[Zodb-checkins] CVS: Zope3/lib/python/Persistence/tests - testPersistence.py:1.1.2.4
Jeremy Hylton
jeremy@zope.com
Mon, 4 Mar 2002 16:45:36 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv23904
Modified Files:
Tag: Zope-3x-branch
testPersistence.py
Log Message:
Add __implements__ attribute to Persistent type implemented in C.
Extend test suite to verify that Persistent implements IPersistent and
other tests implied by the first one.
Remove persist_safe() method from cPersistence.c; was obsolete as of
previous checkin.
Add persist_set_interface() that adds __implements__ to type's tp_dict
after the type is initialized.
=== Zope3/lib/python/Persistence/tests/testPersistence.py 1.1.2.3 => 1.1.2.4 ===
##############################################################################
-import unittest, sys
-
+import unittest
+
+from Persistence.IPersistent import IPersistent
class Test(unittest.TestCase):
@@ -74,7 +75,6 @@
p.inc()
self.assertEqual(p._p_changed, 1)
self.assertEqual(dm.called, 3)
-
def testState(self):
p=P()
@@ -96,24 +96,41 @@
p._p_changed=1
self.assertEqual(dm.called, 1)
+ def testInterface(self):
+ self.assert_(IPersistent.isImplementedByInstancesOf(Persistent),
+ "%s does not implement IPersistent" % Persistent)
+ p = Persistent()
+ self.assert_(IPersistent.isImplementedBy(p),
+ "%s does not implement IPersistent" % p)
+
+ self.assert_(IPersistent.isImplementedByInstancesOf(P),
+ "%s does not implement IPersistent" % P)
+ p = P()
+ self.assert_(IPersistent.isImplementedBy(p),
+ "%s does not implement IPersistent" % p)
+
+
from Persistence import Persistent
class P(Persistent):
- def __init__(self): self.x=0
- def inc(self): self.x += 1
-
+ def __init__(self):
+ self.x = 0
+ def inc(self):
+ self.x += 1
class DM:
- def __init__(self): self.called=0
- def register(self, ob): self.called += 1
+ def __init__(self):
+ self.called = 0
+ def register(self, ob):
+ self.called += 1
def setstate(self, ob):
ob.__setstate__({'x': 42})
##############################################################################
def test_suite():
- loader=unittest.TestLoader()
+ loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
-if __name__=='__main__':
+if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())