Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Acquisition
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Acquisition
Commits
0d47e4dd
Commit
0d47e4dd
authored
Nov 02, 2014
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flake8
parent
4090a33a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
17 deletions
+56
-17
src/Acquisition/tests.py
src/Acquisition/tests.py
+56
-17
No files found.
src/Acquisition/tests.py
View file @
0d47e4dd
...
...
@@ -327,25 +327,30 @@
"Environmental Acquisition--A New Inheritance-Like Abstraction Mechanism",
http://www.bell-labs.com/people/cope/oopsla/Oopsla96TechnicalProgramAbstracts.html#GilLorenz,
OOPSLA '96 Proceedings, ACM SIG-PLAN, October, 1996
$Id$
"""
import
ExtensionClass
import
Acquisition
class
I
(
Acquisition
.
Implicit
):
def
__init__
(
self
,
id
):
self
.
id
=
id
def
__repr__
(
self
):
return
self
.
id
class
E
(
Acquisition
.
Explicit
):
def
__init__
(
self
,
id
):
self
.
id
=
id
def
__repr__
(
self
):
return
self
.
id
def
test_unwrapped
():
"""
>>> c = I('unwrapped')
...
...
@@ -409,10 +414,9 @@ def test_unwrapped():
>>> Acquisition.aq_self(c) is c
1
"""
def
test_simple
():
"""
>>> a = I('a')
...
...
@@ -554,6 +558,7 @@ def test_simple():
True
"""
def
test__of__exception
():
"""
Wrapper_findattr did't check for an exception in a user defined
...
...
@@ -581,6 +586,7 @@ def test__of__exception():
"""
def
test_muliple
():
r"""
>>> a = I('a')
...
...
@@ -830,6 +836,7 @@ def test_muliple():
"""
def
test_pinball
():
r"""
>>> a = I('a')
...
...
@@ -946,6 +953,7 @@ def test_pinball():
"""
def
test_explicit
():
"""
>>> a = E('a')
...
...
@@ -1079,6 +1087,7 @@ def test_explicit():
"""
def
test_mixed_explicit_and_explicit
():
"""
>>> a = I('a')
...
...
@@ -1325,6 +1334,7 @@ def test_aq_inContextOf():
0
"""
def
test_AqAlg
():
"""
>>> A=I('A')
...
...
@@ -1386,6 +1396,7 @@ def test_AqAlg():
"""
def
test_explicit_acquisition
():
"""
>>> from ExtensionClass import Base
...
...
@@ -1414,6 +1425,7 @@ def test_explicit_acquisition():
"""
def
test_creating_wrappers_directly
():
"""
>>> from ExtensionClass import Base
...
...
@@ -1468,6 +1480,7 @@ def test_creating_wrappers_directly():
TypeError: kwyword arguments not allowed
"""
def
test_cant_pickle_acquisition_wrappers_classic
():
"""
>>> import pickle
...
...
@@ -1515,6 +1528,7 @@ def test_cant_pickle_acquisition_wrappers_classic():
TypeError: Can't pickle objects in acquisition wrappers.
"""
def
test_cant_pickle_acquisition_wrappers_newstyle
():
"""
>>> import pickle
...
...
@@ -1562,6 +1576,7 @@ def test_cant_pickle_acquisition_wrappers_newstyle():
TypeError: Can't pickle objects in acquisition wrappers.
"""
def
test_cant_persist_acquisition_wrappers_classic
():
"""
>>> import cPickle
...
...
@@ -1706,17 +1721,23 @@ def test_interfaces():
True
"""
def
show
(
x
):
print
showaq
(
x
).
strip
()
def
showaq
(
m_self
,
indent
=
''
):
rval
=
''
obj
=
m_self
base
=
getattr
(
obj
,
'aq_base'
,
obj
)
try
:
id
=
base
.
id
except
:
id
=
str
(
base
)
try
:
id
=
id
()
except
:
pass
try
:
id
=
base
.
id
except
Exception
:
id
=
str
(
base
)
try
:
id
=
id
()
except
Exception
:
pass
if
hasattr
(
obj
,
'aq_self'
):
if
hasattr
(
obj
.
aq_self
,
'aq_self'
):
...
...
@@ -1734,7 +1755,6 @@ def showaq(m_self, indent=''):
return
rval
def
test_Basic_gc
():
"""Test to make sure that EC instances participate in GC
...
...
@@ -1768,6 +1788,7 @@ def test_Basic_gc():
"""
def
test_Wrapper_gc
():
"""Test to make sure that EC instances participate in GC
...
...
@@ -2004,12 +2025,15 @@ def test_proxying():
"""
class
Location
(
object
):
__parent__
=
None
class
ECLocation
(
ExtensionClass
.
Base
):
__parent__
=
None
def
test___parent__no_wrappers
():
"""
Acquisition also works with objects that aren't wrappers, as long
...
...
@@ -2061,6 +2085,7 @@ def test___parent__no_wrappers():
True
"""
def
test_implicit_wrapper_as___parent__
():
"""
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__():
AttributeError: __parent__
"""
def
test_explicit_wrapper_as___parent__
():
"""
Let's do this test yet another time, with an explicit wrapper:
...
...
@@ -2221,6 +2247,7 @@ def test_explicit_wrapper_as___parent__():
AttributeError: __parent__
"""
def
test_implicit_wrapper_has_nonwrapper_as_aq_parent
():
"""Let's do this the other way around: The root and the
intermediate parent is an object that doesn't support acquisition,
...
...
@@ -2285,6 +2312,7 @@ def test_implicit_wrapper_has_nonwrapper_as_aq_parent():
3.145
"""
def
test_explicit_wrapper_has_nonwrapper_as_aq_parent
():
"""Let's do this the other way around: The root and the
intermediate parent is an object that doesn't support acquisition,
...
...
@@ -2339,6 +2367,7 @@ def test_explicit_wrapper_has_nonwrapper_as_aq_parent():
True
"""
def
test___parent__aq_parent_circles
():
"""
As a general safety belt, Acquisition won't follow a mixture of
...
...
@@ -2396,24 +2425,26 @@ def test___parent__aq_parent_circles():
RuntimeError: Recursion detected in acquisition wrapper
"""
def
test_unwrapped_implicit_acquirer_unwraps__parent__
():
"""
Set up an implicit acquirer with a parent:
>>> class Impl(Acquisition.Implicit):
... pass
>>> y = Impl()
>>> x = Impl()
>>> x.__parent__ = y
Now if we retrieve the parent from the (unwrapped) instance,
the parent should not be wrapped in the instance's acquisition chain.
>>> x.__parent__ is y
True
"""
def
test__iter__after_AttributeError
():
""" See https://bugs.launchpad.net/zope2/+bug/1155760
...
...
@@ -2439,8 +2470,10 @@ from doctest import DocTestSuite, DocFileSuite
class
TestParent
(
unittest
.
TestCase
):
def
test_parent_parent_circles
(
self
):
class
Impl
(
Acquisition
.
Implicit
):
hello
=
'world'
class
Impl2
(
Acquisition
.
Implicit
):
hello
=
'world2'
only
=
'here'
...
...
@@ -2455,15 +2488,18 @@ class TestParent(unittest.TestCase):
self
.
assertEqual
(
Acquisition
.
aq_acquire
(
x
,
'only'
),
'here'
)
self
.
assertRaises
(
AttributeError
,
Acquisition
.
aq_acquire
,
x
,
'non_existant_attr'
)
x
,
'non_existant_attr'
)
self
.
assertRaises
(
AttributeError
,
Acquisition
.
aq_acquire
,
y
,
'non_existant_attr'
)
y
,
'non_existant_attr'
)
def
test_parent_parent_parent_circles
(
self
):
class
Impl
(
Acquisition
.
Implicit
):
hello
=
'world'
class
Impl2
(
Acquisition
.
Implicit
):
hello
=
'world'
class
Impl3
(
Acquisition
.
Implicit
):
hello
=
'world2'
only
=
'here'
...
...
@@ -2497,10 +2533,13 @@ class TestParent(unittest.TestCase):
class
TestAcquire
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
Impl
(
Acquisition
.
Implicit
):
pass
class
Expl
(
Acquisition
.
Explicit
):
pass
a
=
Impl
(
'a'
)
a
.
y
=
42
a
.
b
=
Expl
(
'b'
)
...
...
@@ -2534,7 +2573,7 @@ class TestAcquire(unittest.TestCase):
class
NotWrapped
(
object
):
pass
child
=
NotWrapped
()
parent
=
child
.
__parent__
=
NotWrapped
()
child
.
__parent__
=
NotWrapped
()
self
.
assertEqual
(
self
.
acquire
(
child
,
'nonesuch'
,
default
=
4
),
4
)
def
test_unwrapped_falls_back_to_default
(
self
):
...
...
@@ -2604,4 +2643,4 @@ def test_suite():
unittest
.
makeSuite
(
TestParent
),
unittest
.
makeSuite
(
TestAcquire
),
unittest
.
makeSuite
(
TestUnicode
),
))
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment