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
f9f846a2
Commit
f9f846a2
authored
Apr 03, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace
parent
a934a6a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
51 deletions
+51
-51
src/Acquisition/tests.py
src/Acquisition/tests.py
+51
-51
No files found.
src/Acquisition/tests.py
View file @
f9f846a2
...
@@ -70,9 +70,9 @@
...
@@ -70,9 +70,9 @@
cannot be found in 'a'.
cannot be found in 'a'.
Aquisition wrappers provide access to the wrapped objects
Aquisition wrappers provide access to the wrapped objects
through the attributes 'aq_parent', 'aq_self', 'aq_base'.
through the attributes 'aq_parent', 'aq_self', 'aq_base'.
In the example above, the expressions::
In the example above, the expressions::
>>> c.a.aq_parent is c
>>> c.a.aq_parent is c
1
1
...
@@ -97,28 +97,28 @@
...
@@ -97,28 +97,28 @@
Two styles of acquisition are supported in the current
Two styles of acquisition are supported in the current
ExtensionClass release, implicit and explicit aquisition.
ExtensionClass release, implicit and explicit aquisition.
Implicit acquisition
Implicit acquisition
Implicit acquisition is so named because it searches for
Implicit acquisition is so named because it searches for
attributes from the environment automatically whenever an
attributes from the environment automatically whenever an
attribute cannot be obtained directly from an object or
attribute cannot be obtained directly from an object or
through inheritence.
through inheritence.
An attribute may be implicitly acquired if it's name does
An attribute may be implicitly acquired if it's name does
not begin with an underscore, '_'.
not begin with an underscore, '_'.
To support implicit acquisition, an object should inherit
To support implicit acquisition, an object should inherit
from the mix-in class 'Acquisition.Implicit'.
from the mix-in class 'Acquisition.Implicit'.
Explicit Acquisition
Explicit Acquisition
When explicit acquisition is used, attributes are not
When explicit acquisition is used, attributes are not
automatically obtained from the environment. Instead, the
automatically obtained from the environment. Instead, the
method 'aq_aquire' must be used, as in::
method 'aq_aquire' must be used, as in::
print c.a.aq_acquire('color')
print c.a.aq_acquire('color')
To support explicit acquisition, an object should inherit
To support explicit acquisition, an object should inherit
from the mix-in class 'Acquisition.Explicit'.
from the mix-in class 'Acquisition.Explicit'.
...
@@ -206,31 +206,31 @@
...
@@ -206,31 +206,31 @@
For example, in::
For example, in::
>>> from Acquisition import Explicit
>>> from Acquisition import Explicit
>>> class HandyForTesting:
>>> class HandyForTesting:
... def __init__(self, name): self.name=name
... def __init__(self, name): self.name=name
... def __str__(self):
... def __str__(self):
... return "%s(%s)" % (self.name, self.__class__.__name__)
... return "%s(%s)" % (self.name, self.__class__.__name__)
... __repr__=__str__
... __repr__=__str__
>>> class E(Explicit, HandyForTesting):
>>> class E(Explicit, HandyForTesting):
... pass
... pass
>>> class Nice(HandyForTesting):
>>> class Nice(HandyForTesting):
... isNice=1
... isNice=1
... def __str__(self):
... def __str__(self):
... return HandyForTesting.__str__(self)+' and I am nice!'
... return HandyForTesting.__str__(self)+' and I am nice!'
... __repr__=__str__
... __repr__=__str__
>>> a = E('a')
>>> a = E('a')
>>> a.b = E('b')
>>> a.b = E('b')
>>> a.b.c = E('c')
>>> a.b.c = E('c')
>>> a.p = Nice('spam')
>>> a.p = Nice('spam')
>>> a.b.p = E('p')
>>> a.b.p = E('p')
>>> def find_nice(self, ancestor, name, object, extra):
>>> def find_nice(self, ancestor, name, object, extra):
... return hasattr(object,'isNice') and object.isNice
... return hasattr(object,'isNice') and object.isNice
>>> print a.b.c.aq_acquire('p', find_nice)
>>> print a.b.c.aq_acquire('p', find_nice)
spam(Nice) and I am nice!
spam(Nice) and I am nice!
...
@@ -258,13 +258,13 @@
...
@@ -258,13 +258,13 @@
Consider the following example::
Consider the following example::
>>> from Acquisition import Implicit
>>> from Acquisition import Implicit
>>> class C(Implicit):
>>> class C(Implicit):
... def __init__(self, name): self.name=name
... def __init__(self, name): self.name=name
... def __str__(self):
... def __str__(self):
... return "%s(%s)" % (self.name, self.__class__.__name__)
... return "%s(%s)" % (self.name, self.__class__.__name__)
... __repr__=__str__
... __repr__=__str__
>>> a = C("a")
>>> a = C("a")
>>> a.b = C("b")
>>> a.b = C("b")
>>> a.b.pref = "spam"
>>> a.b.pref = "spam"
...
@@ -323,9 +323,9 @@
...
@@ -323,9 +323,9 @@
'a' is searched no more than once, even though it is wrapped three
'a' is searched no more than once, even though it is wrapped three
times.
times.
.. [1] Gil, J., Lorenz, D.,
.. [1] Gil, J., Lorenz, D.,
"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$
$Id$
...
@@ -368,7 +368,7 @@ def test_unwrapped():
...
@@ -368,7 +368,7 @@ def test_unwrapped():
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AttributeError: x
AttributeError: x
>>> Acquisition.aq_acquire(c, 'id',
>>> Acquisition.aq_acquire(c, 'id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -409,8 +409,8 @@ def test_unwrapped():
...
@@ -409,8 +409,8 @@ def test_unwrapped():
>>> Acquisition.aq_self(c) is c
>>> Acquisition.aq_self(c) is c
1
1
"""
"""
def
test_simple
():
def
test_simple
():
...
@@ -475,7 +475,7 @@ def test_simple():
...
@@ -475,7 +475,7 @@ def test_simple():
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AttributeError: x
AttributeError: x
>>> a.b.c.aq_acquire('id',
>>> a.b.c.aq_acquire('id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -497,7 +497,7 @@ def test_simple():
...
@@ -497,7 +497,7 @@ def test_simple():
>>> Acquisition.aq_acquire(a.b.c, 'y')
>>> Acquisition.aq_acquire(a.b.c, 'y')
42
42
>>> Acquisition.aq_acquire(a.b.c, 'id',
>>> Acquisition.aq_acquire(a.b.c, 'id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -685,19 +685,19 @@ def test_muliple():
...
@@ -685,19 +685,19 @@ def test_muliple():
>>> show(a.a1.a11.a2.a21.aq_inner.aq_parent.aq_inner.aq_parent)
>>> show(a.a1.a11.a2.a21.aq_inner.aq_parent.aq_inner.aq_parent)
a
a
>>> a.a1.a11.a2.a21.aq_chain
>>> a.a1.a11.a2.a21.aq_chain
[a21, a2, a11, a1, a]
[a21, a2, a11, a1, a]
>>> a.a1.a11.a2.a21.aq_inContextOf(a)
>>> a.a1.a11.a2.a21.aq_inContextOf(a)
1
1
>>> a.a1.a11.a2.a21.aq_inContextOf(a.a2)
>>> a.a1.a11.a2.a21.aq_inContextOf(a.a2)
1
1
>>> a.a1.a11.a2.a21.aq_inContextOf(a.a1)
>>> a.a1.a11.a2.a21.aq_inContextOf(a.a1)
0
0
>>> a.a1.a11.a2.a21.aq_acquire('color')
>>> a.a1.a11.a2.a21.aq_acquire('color')
'red'
'red'
>>> a.a1.a11.a2.a21.aq_acquire('id')
>>> a.a1.a11.a2.a21.aq_acquire('id')
...
@@ -712,7 +712,7 @@ def test_muliple():
...
@@ -712,7 +712,7 @@ def test_muliple():
>>> a.a1.a11.a2.a21.aq_acquire('color',
>>> a.a1.a11.a2.a21.aq_acquire('color',
... lambda ob, parent, name, v, extra: extra, 1)
... lambda ob, parent, name, v, extra: extra, 1)
'red'
'red'
>>> a.a1.y = 42
>>> a.a1.y = 42
>>> a.a1.a11.a2.a21.aq_acquire('y')
>>> a.a1.a11.a2.a21.aq_acquire('y')
42
42
...
@@ -796,13 +796,13 @@ def test_muliple():
...
@@ -796,13 +796,13 @@ def test_muliple():
>>> show(Acquisition.aq_parent(
>>> show(Acquisition.aq_parent(
... a.a1.a11.a2.a21.aq_inner.aq_parent.aq_inner))
... a.a1.a11.a2.a21.aq_inner.aq_parent.aq_inner))
a
a
>>> Acquisition.aq_chain(a.a1.a11.a2.a21)
>>> Acquisition.aq_chain(a.a1.a11.a2.a21)
[a21, a2, a11, a1, a]
[a21, a2, a11, a1, a]
>>> Acquisition.aq_chain(a.a1.a11.a2.a21, 1)
>>> Acquisition.aq_chain(a.a1.a11.a2.a21, 1)
[a21, a2, a]
[a21, a2, a]
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'color')
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'color')
'red'
'red'
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'id')
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'id')
...
@@ -817,7 +817,7 @@ def test_muliple():
...
@@ -817,7 +817,7 @@ def test_muliple():
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'color',
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'color',
... lambda ob, parent, name, v, extra: extra, 1)
... lambda ob, parent, name, v, extra: extra, 1)
'red'
'red'
>>> a.a1.y = 42
>>> a.a1.y = 42
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'y')
>>> Acquisition.aq_acquire(a.a1.a11.a2.a21, 'y')
42
42
...
@@ -829,7 +829,7 @@ def test_muliple():
...
@@ -829,7 +829,7 @@ def test_muliple():
"""
"""
def
test_pinball
():
def
test_pinball
():
r"""
r"""
>>> a = I('a')
>>> a = I('a')
...
@@ -943,7 +943,7 @@ def test_pinball():
...
@@ -943,7 +943,7 @@ def test_pinball():
a1
a1
|
|
a
a
"""
"""
def
test_explicit
():
def
test_explicit
():
...
@@ -1003,7 +1003,7 @@ def test_explicit():
...
@@ -1003,7 +1003,7 @@ def test_explicit():
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AttributeError: x
AttributeError: x
>>> a.b.c.aq_acquire('id',
>>> a.b.c.aq_acquire('id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -1025,7 +1025,7 @@ def test_explicit():
...
@@ -1025,7 +1025,7 @@ def test_explicit():
>>> Acquisition.aq_acquire(a.b.c, 'y')
>>> Acquisition.aq_acquire(a.b.c, 'y')
42
42
>>> Acquisition.aq_acquire(a.b.c, 'id',
>>> Acquisition.aq_acquire(a.b.c, 'id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -1143,7 +1143,7 @@ def test_mixed_explicit_and_explicit():
...
@@ -1143,7 +1143,7 @@ def test_mixed_explicit_and_explicit():
Traceback (most recent call last):
Traceback (most recent call last):
...
...
AttributeError: x
AttributeError: x
>>> a.b.c.aq_acquire('id',
>>> a.b.c.aq_acquire('id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -1165,7 +1165,7 @@ def test_mixed_explicit_and_explicit():
...
@@ -1165,7 +1165,7 @@ def test_mixed_explicit_and_explicit():
>>> Acquisition.aq_acquire(a.b.c, 'y')
>>> Acquisition.aq_acquire(a.b.c, 'y')
42
42
>>> Acquisition.aq_acquire(a.b.c, 'id',
>>> Acquisition.aq_acquire(a.b.c, 'id',
... lambda searched, parent, name, ob, extra: extra)
... lambda searched, parent, name, ob, extra: extra)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -1221,7 +1221,7 @@ def test_mixed_explicit_and_explicit():
...
@@ -1221,7 +1221,7 @@ def test_mixed_explicit_and_explicit():
def
test_aq_inContextOf
():
def
test_aq_inContextOf
():
"""
"""
>>> from ExtensionClass import Base
>>> from ExtensionClass import Base
>>> import Acquisition
>>> import Acquisition
...
@@ -1247,9 +1247,9 @@ def test_aq_inContextOf():
...
@@ -1247,9 +1247,9 @@ def test_aq_inContextOf():
... raise 'Program error', 'spam'
... raise 'Program error', 'spam'
... except AttributeError: pass
... except AttributeError: pass
A()
A()
New test for wrapper comparisons.
New test for wrapper comparisons.
>>> foo = b.a
>>> foo = b.a
>>> bar = b.a
>>> bar = b.a
>>> foo == bar
>>> foo == bar
...
@@ -1379,14 +1379,14 @@ def test_AqAlg():
...
@@ -1379,14 +1379,14 @@ def test_AqAlg():
[D, C, A]
[D, C, A]
>>> map(Acquisition.aq_base, Acquisition.aq_chain(A.B.C.D, 1))
>>> map(Acquisition.aq_base, Acquisition.aq_chain(A.B.C.D, 1))
[D, C, A]
[D, C, A]
>>> A.B.C.D.color
>>> A.B.C.D.color
'red'
'red'
>>> Acquisition.aq_get(A.B.C.D, "color", None)
>>> Acquisition.aq_get(A.B.C.D, "color", None)
'red'
'red'
>>> Acquisition.aq_get(A.B.C.D, "color", None, 1)
>>> Acquisition.aq_get(A.B.C.D, "color", None, 1)
"""
"""
def
test_explicit_acquisition
():
def
test_explicit_acquisition
():
...
@@ -1414,7 +1414,7 @@ def test_explicit_acquisition():
...
@@ -1414,7 +1414,7 @@ def test_explicit_acquisition():
... raise 'Program error', 'spam'
... raise 'Program error', 'spam'
... except AttributeError: pass
... except AttributeError: pass
A
A
"""
"""
def
test_creating_wrappers_directly
():
def
test_creating_wrappers_directly
():
...
@@ -1593,7 +1593,7 @@ def test_interfaces():
...
@@ -1593,7 +1593,7 @@ def test_interfaces():
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
...
@@ -1631,11 +1631,11 @@ def test_Basic_gc():
...
@@ -1631,11 +1631,11 @@ def test_Basic_gc():
>>> for B in I, E:
>>> for B in I, E:
... class C1(B):
... class C1(B):
... pass
... pass
...
...
... class C2(Base):
... class C2(Base):
... def __del__(self):
... def __del__(self):
... print 'removed'
... print 'removed'
...
...
... a=C1('a')
... a=C1('a')
... a.b = C1('a.b')
... a.b = C1('a.b')
... a.b.a = a
... a.b.a = a
...
@@ -1664,7 +1664,7 @@ def test_Wrapper_gc():
...
@@ -1664,7 +1664,7 @@ def test_Wrapper_gc():
... class C:
... class C:
... def __del__(self):
... def __del__(self):
... print 'removed'
... print 'removed'
...
...
... a=B('a')
... a=B('a')
... a.b = B('b')
... a.b = B('b')
... a.a_b = a.b # circ ref through wrapper
... a.a_b = a.b # circ ref through wrapper
...
@@ -1891,7 +1891,7 @@ def test_proxying():
...
@@ -1891,7 +1891,7 @@ 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
...
...
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