[Zodb-checkins] CVS: Zope3/src/zodb/code/tests - test_class.py:1.6
Jeremy Hylton
jeremy@zope.com
Thu, 30 Jan 2003 13:50:46 -0500
Update of /cvs-repository/Zope3/src/zodb/code/tests
In directory cvs.zope.org:/tmp/cvs-serv11359/tests
Modified Files:
test_class.py
Log Message:
A collection of small improvements.
Set _pc_init to False inside constructor, although I'm not entirely
certain why it is necessary. Sometimes a class would get loaded
through a new connection or invalidated and its _pc_init would be
True.
Remove unneeded __call__(). A class is never a ghost.
Add comment and commented-out test of the need for _p_changed.
First steps towards a more useful __getstate__().
Remove stale comment in patch.TypeWrapper.
Re-enable testing of _p_oid attribute.
=== Zope3/src/zodb/code/tests/test_class.py 1.5 => 1.6 ===
--- Zope3/src/zodb/code/tests/test_class.py:1.5 Wed Jan 29 12:01:58 2003
+++ Zope3/src/zodb/code/tests/test_class.py Thu Jan 30 13:50:14 2003
@@ -21,6 +21,7 @@
from zodb.code.module import newModule
from transaction import get_transaction
+from persistence._persistence import CHANGED, UPTODATE
class TestClass(TestBase):
@@ -87,9 +88,7 @@
x = self._load_name("testclass.x")
self.assertEqual(x.var, 12)
- #XXX I'm commenting the following because Jeremy doesn't
- # have time to fix it now and we can't have tests failing.
- #XXX self.assert_(not hasattr(x, "_p_oid"))
+ self.assert_(not hasattr(x, "_p_oid"))
class_interface = """class Foo:
__implements__ = 1""" + "\n"
@@ -142,11 +141,11 @@
self.assertEqual(inst2.meth(4), 7)
self.assertEqual(Foo2().meth(4), 7)
- parent1 = """class Foo:
+ parent1 = """class Foo(object):
def meth(self, arg):
return arg * 2""" "\n"
- parent2 = """class Foo:
+ parent2 = """class Foo(object):
def meth(self, arg):
return arg // 2""" "\n"
@@ -165,12 +164,38 @@
self.registry.updateModule("parent", self.parent2)
get_transaction().commit()
self.assertEqual(child.Bar().meth(3), 3//2+5)
-
- # XXX somehow we get the meth() defined on parent
- # instead of the one on child. it looks like super
- # isn't doing what I expect.
+
Bar = self._load_name("child.Bar")
-## self.assertEqual(Bar().meth(3), 3//2+5)
+ self.assertEqual(Bar().meth(3), 3//2+5)
+
+ persist = """from persistence import Persistent
+class Foo(Persistent):
+ pass""" "\n"
+
+ def testPersistentSubclass(self):
+ self.registry.newModule("persist", self.persist)
+ get_transaction().commit()
+ import persist
+ # Verify that the instances are persistent and that the
+ # _p_ namespace is separate.
+ obj = persist.Foo()
+ foo_oid = persist.Foo._p_oid
+ self.assertEqual(obj._p_oid, None)
+ obj._p_oid = 1
+ self.assertEqual(obj._p_oid, 1)
+ self.assertEqual(persist.Foo._p_oid, foo_oid)
+
+ def XXXtestUpdateClassAttribute(self):
+ self.registry.newModule("parent", self.parent1)
+ get_transaction().commit()
+ import parent
+ parent.Foo.attr = 2
+ self.assertEqual(parent.Foo._p_state, CHANGED)
+ get_transaction().commit()
+ self.assertEqual(parent.Foo._p_state, UPTODATE)
+
+ Foo = self._load_name("parent.Foo")
+ self.assertEqual(Foo.attr, 2)
def test_suite():
return unittest.makeSuite(TestClass)