Commit 0d47e4dd authored by Hanno Schlichting's avatar Hanno Schlichting

flake8

parent 4090a33a
...@@ -327,25 +327,30 @@ ...@@ -327,25 +327,30 @@
"Environmental Acquisition--A New Inheritance-Like Abstraction Mechanism", "Environmental Acquisition--A New Inheritance-Like Abstraction Mechanism",
http://www.bell-labs.com/people/cope/oopsla/Oopsla96TechnicalProgramAbstracts.html#GilLorenz, http://www.bell-labs.com/people/cope/oopsla/Oopsla96TechnicalProgramAbstracts.html#GilLorenz,
OOPSLA '96 Proceedings, ACM SIG-PLAN, October, 1996 OOPSLA '96 Proceedings, ACM SIG-PLAN, October, 1996
$Id$
""" """
import ExtensionClass import ExtensionClass
import Acquisition import Acquisition
class I(Acquisition.Implicit): class I(Acquisition.Implicit):
def __init__(self, id): def __init__(self, id):
self.id = id self.id = id
def __repr__(self): def __repr__(self):
return self.id return self.id
class E(Acquisition.Explicit): class E(Acquisition.Explicit):
def __init__(self, id): def __init__(self, id):
self.id = id self.id = id
def __repr__(self): def __repr__(self):
return self.id return self.id
def test_unwrapped(): def test_unwrapped():
""" """
>>> c = I('unwrapped') >>> c = I('unwrapped')
...@@ -409,10 +414,9 @@ def test_unwrapped(): ...@@ -409,10 +414,9 @@ def test_unwrapped():
>>> Acquisition.aq_self(c) is c >>> Acquisition.aq_self(c) is c
1 1
""" """
def test_simple(): def test_simple():
""" """
>>> a = I('a') >>> a = I('a')
...@@ -554,6 +558,7 @@ def test_simple(): ...@@ -554,6 +558,7 @@ def test_simple():
True True
""" """
def test__of__exception(): def test__of__exception():
""" """
Wrapper_findattr did't check for an exception in a user defined Wrapper_findattr did't check for an exception in a user defined
...@@ -581,6 +586,7 @@ def test__of__exception(): ...@@ -581,6 +586,7 @@ def test__of__exception():
""" """
def test_muliple(): def test_muliple():
r""" r"""
>>> a = I('a') >>> a = I('a')
...@@ -830,6 +836,7 @@ def test_muliple(): ...@@ -830,6 +836,7 @@ def test_muliple():
""" """
def test_pinball(): def test_pinball():
r""" r"""
>>> a = I('a') >>> a = I('a')
...@@ -946,6 +953,7 @@ def test_pinball(): ...@@ -946,6 +953,7 @@ def test_pinball():
""" """
def test_explicit(): def test_explicit():
""" """
>>> a = E('a') >>> a = E('a')
...@@ -1079,6 +1087,7 @@ def test_explicit(): ...@@ -1079,6 +1087,7 @@ def test_explicit():
""" """
def test_mixed_explicit_and_explicit(): def test_mixed_explicit_and_explicit():
""" """
>>> a = I('a') >>> a = I('a')
...@@ -1325,6 +1334,7 @@ def test_aq_inContextOf(): ...@@ -1325,6 +1334,7 @@ def test_aq_inContextOf():
0 0
""" """
def test_AqAlg(): def test_AqAlg():
""" """
>>> A=I('A') >>> A=I('A')
...@@ -1386,6 +1396,7 @@ def test_AqAlg(): ...@@ -1386,6 +1396,7 @@ def test_AqAlg():
""" """
def test_explicit_acquisition(): def test_explicit_acquisition():
""" """
>>> from ExtensionClass import Base >>> from ExtensionClass import Base
...@@ -1414,6 +1425,7 @@ def test_explicit_acquisition(): ...@@ -1414,6 +1425,7 @@ def test_explicit_acquisition():
""" """
def test_creating_wrappers_directly(): def test_creating_wrappers_directly():
""" """
>>> from ExtensionClass import Base >>> from ExtensionClass import Base
...@@ -1468,6 +1480,7 @@ def test_creating_wrappers_directly(): ...@@ -1468,6 +1480,7 @@ def test_creating_wrappers_directly():
TypeError: kwyword arguments not allowed TypeError: kwyword arguments not allowed
""" """
def test_cant_pickle_acquisition_wrappers_classic(): def test_cant_pickle_acquisition_wrappers_classic():
""" """
>>> import pickle >>> import pickle
...@@ -1515,6 +1528,7 @@ def test_cant_pickle_acquisition_wrappers_classic(): ...@@ -1515,6 +1528,7 @@ def test_cant_pickle_acquisition_wrappers_classic():
TypeError: Can't pickle objects in acquisition wrappers. TypeError: Can't pickle objects in acquisition wrappers.
""" """
def test_cant_pickle_acquisition_wrappers_newstyle(): def test_cant_pickle_acquisition_wrappers_newstyle():
""" """
>>> import pickle >>> import pickle
...@@ -1562,6 +1576,7 @@ def test_cant_pickle_acquisition_wrappers_newstyle(): ...@@ -1562,6 +1576,7 @@ def test_cant_pickle_acquisition_wrappers_newstyle():
TypeError: Can't pickle objects in acquisition wrappers. TypeError: Can't pickle objects in acquisition wrappers.
""" """
def test_cant_persist_acquisition_wrappers_classic(): def test_cant_persist_acquisition_wrappers_classic():
""" """
>>> import cPickle >>> import cPickle
...@@ -1706,17 +1721,23 @@ def test_interfaces(): ...@@ -1706,17 +1721,23 @@ def test_interfaces():
True True
""" """
def show(x): def show(x):
print showaq(x).strip() print showaq(x).strip()
def showaq(m_self, indent=''): def showaq(m_self, indent=''):
rval = '' rval = ''
obj = m_self obj = m_self
base = getattr(obj, 'aq_base', obj) base = getattr(obj, 'aq_base', obj)
try: id = base.id try:
except: id = str(base) id = base.id
try: id = id() except Exception:
except: pass id = str(base)
try:
id = id()
except Exception:
pass
if hasattr(obj, 'aq_self'): if hasattr(obj, 'aq_self'):
if hasattr(obj.aq_self, 'aq_self'): if hasattr(obj.aq_self, 'aq_self'):
...@@ -1734,7 +1755,6 @@ def showaq(m_self, indent=''): ...@@ -1734,7 +1755,6 @@ def showaq(m_self, indent=''):
return rval return rval
def test_Basic_gc(): def test_Basic_gc():
"""Test to make sure that EC instances participate in GC """Test to make sure that EC instances participate in GC
...@@ -1768,6 +1788,7 @@ def test_Basic_gc(): ...@@ -1768,6 +1788,7 @@ def test_Basic_gc():
""" """
def test_Wrapper_gc(): def test_Wrapper_gc():
"""Test to make sure that EC instances participate in GC """Test to make sure that EC instances participate in GC
...@@ -2004,12 +2025,15 @@ def test_proxying(): ...@@ -2004,12 +2025,15 @@ def test_proxying():
""" """
class Location(object): class Location(object):
__parent__ = None __parent__ = None
class ECLocation(ExtensionClass.Base): class ECLocation(ExtensionClass.Base):
__parent__ = None __parent__ = None
def test___parent__no_wrappers(): def test___parent__no_wrappers():
""" """
Acquisition also works with objects that aren't wrappers, as long Acquisition also works with objects that aren't wrappers, as long
...@@ -2061,6 +2085,7 @@ def test___parent__no_wrappers(): ...@@ -2061,6 +2085,7 @@ def test___parent__no_wrappers():
True True
""" """
def test_implicit_wrapper_as___parent__(): def test_implicit_wrapper_as___parent__():
""" """
Let's do the same test again, only now not all objects are of the Let's do the same test again, only now not all objects are of the
...@@ -2142,6 +2167,7 @@ def test_implicit_wrapper_as___parent__(): ...@@ -2142,6 +2167,7 @@ def test_implicit_wrapper_as___parent__():
AttributeError: __parent__ AttributeError: __parent__
""" """
def test_explicit_wrapper_as___parent__(): def test_explicit_wrapper_as___parent__():
""" """
Let's do this test yet another time, with an explicit wrapper: Let's do this test yet another time, with an explicit wrapper:
...@@ -2221,6 +2247,7 @@ def test_explicit_wrapper_as___parent__(): ...@@ -2221,6 +2247,7 @@ def test_explicit_wrapper_as___parent__():
AttributeError: __parent__ AttributeError: __parent__
""" """
def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
"""Let's do this the other way around: The root and the """Let's do this the other way around: The root and the
intermediate parent is an object that doesn't support acquisition, intermediate parent is an object that doesn't support acquisition,
...@@ -2285,6 +2312,7 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -2285,6 +2312,7 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
3.145 3.145
""" """
def test_explicit_wrapper_has_nonwrapper_as_aq_parent(): def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
"""Let's do this the other way around: The root and the """Let's do this the other way around: The root and the
intermediate parent is an object that doesn't support acquisition, intermediate parent is an object that doesn't support acquisition,
...@@ -2339,6 +2367,7 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent(): ...@@ -2339,6 +2367,7 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
True True
""" """
def test___parent__aq_parent_circles(): def test___parent__aq_parent_circles():
""" """
As a general safety belt, Acquisition won't follow a mixture of As a general safety belt, Acquisition won't follow a mixture of
...@@ -2396,6 +2425,7 @@ def test___parent__aq_parent_circles(): ...@@ -2396,6 +2425,7 @@ def test___parent__aq_parent_circles():
RuntimeError: Recursion detected in acquisition wrapper RuntimeError: Recursion detected in acquisition wrapper
""" """
def test_unwrapped_implicit_acquirer_unwraps__parent__(): def test_unwrapped_implicit_acquirer_unwraps__parent__():
""" """
Set up an implicit acquirer with a parent: Set up an implicit acquirer with a parent:
...@@ -2414,6 +2444,7 @@ def test_unwrapped_implicit_acquirer_unwraps__parent__(): ...@@ -2414,6 +2444,7 @@ def test_unwrapped_implicit_acquirer_unwraps__parent__():
True True
""" """
def test__iter__after_AttributeError(): def test__iter__after_AttributeError():
""" See https://bugs.launchpad.net/zope2/+bug/1155760 """ See https://bugs.launchpad.net/zope2/+bug/1155760
...@@ -2439,8 +2470,10 @@ from doctest import DocTestSuite, DocFileSuite ...@@ -2439,8 +2470,10 @@ from doctest import DocTestSuite, DocFileSuite
class TestParent(unittest.TestCase): class TestParent(unittest.TestCase):
def test_parent_parent_circles(self): def test_parent_parent_circles(self):
class Impl(Acquisition.Implicit): class Impl(Acquisition.Implicit):
hello = 'world' hello = 'world'
class Impl2(Acquisition.Implicit): class Impl2(Acquisition.Implicit):
hello = 'world2' hello = 'world2'
only = 'here' only = 'here'
...@@ -2460,10 +2493,13 @@ class TestParent(unittest.TestCase): ...@@ -2460,10 +2493,13 @@ class TestParent(unittest.TestCase):
y, 'non_existant_attr') y, 'non_existant_attr')
def test_parent_parent_parent_circles(self): def test_parent_parent_parent_circles(self):
class Impl(Acquisition.Implicit): class Impl(Acquisition.Implicit):
hello = 'world' hello = 'world'
class Impl2(Acquisition.Implicit): class Impl2(Acquisition.Implicit):
hello = 'world' hello = 'world'
class Impl3(Acquisition.Implicit): class Impl3(Acquisition.Implicit):
hello = 'world2' hello = 'world2'
only = 'here' only = 'here'
...@@ -2497,10 +2533,13 @@ class TestParent(unittest.TestCase): ...@@ -2497,10 +2533,13 @@ class TestParent(unittest.TestCase):
class TestAcquire(unittest.TestCase): class TestAcquire(unittest.TestCase):
def setUp(self): def setUp(self):
class Impl(Acquisition.Implicit): class Impl(Acquisition.Implicit):
pass pass
class Expl(Acquisition.Explicit): class Expl(Acquisition.Explicit):
pass pass
a = Impl('a') a = Impl('a')
a.y = 42 a.y = 42
a.b = Expl('b') a.b = Expl('b')
...@@ -2534,7 +2573,7 @@ class TestAcquire(unittest.TestCase): ...@@ -2534,7 +2573,7 @@ class TestAcquire(unittest.TestCase):
class NotWrapped(object): class NotWrapped(object):
pass pass
child = NotWrapped() child = NotWrapped()
parent = child.__parent__ = NotWrapped() child.__parent__ = NotWrapped()
self.assertEqual(self.acquire(child, 'nonesuch', default=4), 4) self.assertEqual(self.acquire(child, 'nonesuch', default=4), 4)
def test_unwrapped_falls_back_to_default(self): def test_unwrapped_falls_back_to_default(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment