Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodb
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joshua
zodb
Commits
660845eb
Commit
660845eb
authored
Sep 18, 2008
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace spurious dependency on ZODB / transaction w/ fake jars.
parent
c58b0c7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
42 deletions
+23
-42
src/persistent/tests/test_overriding_attrs.py
src/persistent/tests/test_overriding_attrs.py
+23
-42
No files found.
src/persistent/tests/test_overriding_attrs.py
View file @
660845eb
...
@@ -19,9 +19,15 @@ access methods.
...
@@ -19,9 +19,15 @@ access methods.
$Id$
$Id$
"""
"""
from
persistent
import
Persistent
from
persistent
import
Persistent
# ouch!
import
transaction
from
ZODB.tests.util
import
DB
def
_resettingJar
():
from
persistent.tests.utils
import
ResettingJar
return
ResettingJar
()
def
_rememberingJar
():
from
persistent.tests.utils
import
RememberingJar
return
RememberingJar
()
class
SampleOverridingGetattr
(
Persistent
):
class
SampleOverridingGetattr
(
Persistent
):
"""Example of overriding __getattr__
"""Example of overriding __getattr__
...
@@ -52,10 +58,8 @@ class SampleOverridingGetattr(Persistent):
...
@@ -52,10 +58,8 @@ class SampleOverridingGetattr(Persistent):
We'll save the object, so it can be deactivated:
We'll save the object, so it can be deactivated:
>>> db = DB()
>>> jar = _resettingJar()
>>> conn = db.open()
>>> jar.add(o)
>>> conn.root()['o'] = o
>>> transaction.commit()
>>> o._p_deactivate()
>>> o._p_deactivate()
>>> o._p_changed
>>> o._p_changed
...
@@ -66,10 +70,6 @@ class SampleOverridingGetattr(Persistent):
...
@@ -66,10 +70,6 @@ class SampleOverridingGetattr(Persistent):
And we see that the object was activated before calling the
And we see that the object was activated before calling the
__getattr__ method.
__getattr__ method.
We always close databases after we use them:
>>> db.close()
"""
"""
# Don't pretend we have any special attributes.
# Don't pretend we have any special attributes.
if
name
.
startswith
(
"__"
)
and
name
.
endswrith
(
"__"
):
if
name
.
startswith
(
"__"
)
and
name
.
endswrith
(
"__"
):
...
@@ -118,10 +118,8 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -118,10 +118,8 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
Next, we'll save the object in a database so that we can
Next, we'll save the object in a database so that we can
deactivate it:
deactivate it:
>>> db = DB()
>>> jar = _rememberingJar()
>>> conn = db.open()
>>> jar.add(o)
>>> conn.root()['o'] = o
>>> transaction.commit()
>>> o._p_deactivate()
>>> o._p_deactivate()
>>> o._p_changed
>>> o._p_changed
...
@@ -149,10 +147,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -149,10 +147,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
0
0
See the very important note in the comment below!
See the very important note in the comment below!
We always close databases after we use them:
>>> db.close()
"""
"""
#################################################################
#################################################################
...
@@ -220,13 +214,11 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -220,13 +214,11 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> 'x' in o.__dict__
>>> 'x' in o.__dict__
False
False
Next, we'll
save the object in a database so that
we can
Next, we'll
give the object a "remembering" jar so
we can
deactivate it:
deactivate it:
>>> db = DB()
>>> jar = _rememberingJar()
>>> conn = db.open()
>>> jar.add(o)
>>> conn.root()['o'] = o
>>> transaction.commit()
>>> o._p_deactivate()
>>> o._p_deactivate()
>>> o._p_changed
>>> o._p_changed
...
@@ -242,9 +234,9 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -242,9 +234,9 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> o._p_changed
>>> o._p_changed
1
1
Now, if commit:
Now, if
fake a
commit:
>>>
transaction.
commit()
>>>
jar.fake_
commit()
>>> o._p_changed
>>> o._p_changed
0
0
...
@@ -263,11 +255,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -263,11 +255,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
0
0
>>> o.tmp_foo
>>> o.tmp_foo
3
3
We always close databases after we use them:
>>> db.close()
"""
"""
#################################################################
#################################################################
...
@@ -320,13 +307,11 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -320,13 +307,11 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
...
AttributeError: x
AttributeError: x
Next, we'll save the object in a
database
so that we can
Next, we'll save the object in a
jar
so that we can
deactivate it:
deactivate it:
>>> db = DB()
>>> jar = _rememberingJar()
>>> conn = db.open()
>>> jar.add(o)
>>> conn.root()['o'] = o
>>> transaction.commit()
>>> o._p_deactivate()
>>> o._p_deactivate()
>>> o._p_changed
>>> o._p_changed
...
@@ -347,9 +332,9 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -347,9 +332,9 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> o.tmp_z
>>> o.tmp_z
3
3
Now, if commit:
Now, if
fake a
commit:
>>>
transaction.
commit()
>>>
jar.fake_
commit()
>>> o._p_changed
>>> o._p_changed
0
0
...
@@ -371,10 +356,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
@@ -371,10 +356,6 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
...
...
AttributeError: tmp_z
AttributeError: tmp_z
We always close databases after we use them:
>>> db.close()
"""
"""
#################################################################
#################################################################
...
...
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