[Zodb-checkins] CVS: ZODB3/persistent/tests -
testPersistent.py:1.2.10.1
Fred L. Drake, Jr.
fred at zope.com
Fri Jan 16 16:18:24 EST 2004
Update of /cvs-repository/ZODB3/persistent/tests
In directory cvs.zope.org:/tmp/cvs-serv21094
Modified Files:
Tag: zope3-zodb3-devel-branch
testPersistent.py
Log Message:
added tests for:
- add _p_invalidate() method to invalidate an object unconditionally;
this is equivalent to _p_deactivate(force=True) from ZODB 4
- add _p_state as read-only access to the current state; no weird
interpretation based on _p_changed needed
=== ZODB3/persistent/tests/testPersistent.py 1.2 => 1.2.10.1 ===
--- ZODB3/persistent/tests/testPersistent.py:1.2 Fri Nov 28 11:44:56 2003
+++ ZODB3/persistent/tests/testPersistent.py Fri Jan 16 16:18:23 2004
@@ -15,7 +15,7 @@
import time
import unittest
-from persistent import Persistent
+from persistent import Persistent, GHOST, UPTODATE, CHANGED, STICKY
from persistent.cPickleCache import PickleCache
from persistent.TimeStamp import TimeStamp
from ZODB.utils import p64
@@ -111,7 +111,7 @@
obj._p_jar = 12
self.assertRaises(ValueError, setoid)
- def testChanged(self):
+ def testChangedAndState(self):
obj = P()
self.jar.add(obj)
@@ -122,24 +122,29 @@
obj.x = 1
self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj._p_state, CHANGED)
self.assert_(obj in self.jar.registered)
obj._p_changed = 0
self.assertEqual(obj._p_changed, 0)
+ self.assertEqual(obj._p_state, UPTODATE)
self.jar.registered.clear()
obj._p_changed = 1
self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj._p_state, CHANGED)
self.assert_(obj in self.jar.registered)
# setting obj._p_changed to None ghostifies if the
# object is in the up-to-date state, but not otherwise.
obj._p_changed = None
self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj._p_state, CHANGED)
obj._p_changed = 0
# Now it's a ghost.
obj._p_changed = None
self.assertEqual(obj._p_changed, None)
+ self.assertEqual(obj._p_state, GHOST)
obj = P()
self.jar.add(obj)
@@ -148,6 +153,34 @@
# you delete the _p_changed attribute.
del obj._p_changed
self.assertEqual(obj._p_changed, None)
+ self.assertEqual(obj._p_state, GHOST)
+
+ def testStateReadonly(self):
+ # make sure we can't write to _p_state; we don't want yet
+ # another way to change state!
+ obj = P()
+ def setstate(value):
+ obj._p_state = value
+ self.assertRaises(TypeError, setstate, GHOST)
+ self.assertRaises(TypeError, setstate, UPTODATE)
+ self.assertRaises(TypeError, setstate, CHANGED)
+ self.assertRaises(TypeError, setstate, STICKY)
+
+ def testInvalidate(self):
+ obj = P()
+ self.jar.add(obj)
+
+ self.assertEqual(obj._p_changed, 0)
+ self.assertEqual(obj._p_state, UPTODATE)
+ obj._p_invalidate()
+ self.assertEqual(obj._p_changed, None)
+ self.assertEqual(obj._p_state, GHOST)
+
+ obj._p_activate()
+ obj.x = 1
+ obj._p_invalidate()
+ self.assertEqual(obj._p_changed, None)
+ self.assertEqual(obj._p_state, GHOST)
def testSerial(self):
noserial = "\000" * 8
@@ -196,6 +229,7 @@
# The getattr hook modified the object, so it should now be
# in the changed state.
self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj._p_state, CHANGED)
self.assertEqual(obj.curly, 2)
self.assertEqual(obj.moe, 3)
@@ -213,6 +247,7 @@
# The getattr hook modified the object, so it should now be
# in the changed state.
self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj._p_state, CHANGED)
self.assertEqual(obj.curly, 2)
self.assertEqual(obj.moe, 3)
More information about the Zodb-checkins
mailing list