[Zodb-checkins] CVS: ZODB3/Persistence/tests -
testPersistent.py:1.1.2.4
Jeremy Hylton
jeremy at zope.com
Thu Jul 3 18:03:48 EDT 2003
Update of /cvs-repository/ZODB3/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv18624/tests
Modified Files:
Tag: zodb33-devel-branch
testPersistent.py
Log Message:
Flesh out tests that use __getattr__() and __getattribute__().
=== ZODB3/Persistence/tests/testPersistent.py 1.1.2.3 => 1.1.2.4 ===
--- ZODB3/Persistence/tests/testPersistent.py:1.1.2.3 Thu Jul 3 15:17:48 2003
+++ ZODB3/Persistence/tests/testPersistent.py Thu Jul 3 17:03:42 2003
@@ -1,4 +1,4 @@
-##############################################################################
+#############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
@@ -46,9 +46,38 @@
def register(self, obj):
self.registered[obj] = 1
+ def setstate(self, obj):
+ # Trivial setstate() implementation that just re-initializes
+ # the object. This isn't what setstate() is supposed to do,
+ # but it suffices for the tests.
+ obj.__class__.__init__(obj)
+
class P(Persistent):
pass
+class H1(Persistent):
+
+ def __init__(self):
+ self.n = 0
+
+ def __getattr__(self, attr):
+ self.n += 1
+ return self.n
+
+class H2(Persistent):
+
+ def __init__(self):
+ self.n = 0
+
+ def __getattribute__(self, attr):
+ supergetattr = super(H2, self).__getattribute__
+ try:
+ return supergetattr(attr)
+ except AttributeError:
+ n = supergetattr("n")
+ self.n = n + 1
+ return n + 1
+
class PersistenceTest(unittest.TestCase):
def setUp(self):
@@ -135,7 +164,7 @@
del obj._p_serial
self.assertEqual(obj._p_serial, noserial)
- def testTime(self):
+ def testMTime(self):
obj = P()
self.assertEqual(obj._p_mtime, None)
@@ -145,7 +174,42 @@
self.assertEqual(obj._p_mtime, t)
self.assert_(isinstance(obj._p_mtime, float))
- # tests with __getattr__, __getattribute__, and __setattr__
+ def testGetattr(self):
+ obj = H1()
+ self.assertEqual(obj.larry, 1)
+ self.assertEqual(obj.curly, 2)
+ self.assertEqual(obj.moe, 3)
+
+ self.jar.add(obj)
+ obj._p_deactivate()
+
+ # The simple Jar used for testing re-initializes the object.
+ self.assertEqual(obj.larry, 1)
+ # The getattr hook modified the object, so it should now be
+ # in the changed state.
+ self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj.curly, 2)
+ self.assertEqual(obj.moe, 3)
+
+ def testGetattribute(self):
+ obj = H2()
+ self.assertEqual(obj.larry, 1)
+ self.assertEqual(obj.curly, 2)
+ self.assertEqual(obj.moe, 3)
+
+ self.jar.add(obj)
+ obj._p_deactivate()
+
+ # The simple Jar used for testing re-initializes the object.
+ self.assertEqual(obj.larry, 1)
+ # The getattr hook modified the object, so it should now be
+ # in the changed state.
+ self.assertEqual(obj._p_changed, 1)
+ self.assertEqual(obj.curly, 2)
+ self.assertEqual(obj.moe, 3)
+
+ # XXX Need to decide how __setattr__ and __delattr__ should work,
+ # then write tests.
def test_suite():
More information about the Zodb-checkins
mailing list