Commit 430e86d8 authored by Tres Seaver's avatar Tres Seaver

Replace spurious dependency on ZODB / transaction w/ fake jars.

parent adef045b
...@@ -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()
""" """
################################################################# #################################################################
......
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