[Zodb-checkins] CVS: Zope3/lib/python/Persistence/tests - testPersistence.py:1.7
Jeremy Hylton
jeremy@zope.com
Thu, 10 Oct 2002 17:36:48 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv22620/lib/python/Persistence/tests
Modified Files:
testPersistence.py
Log Message:
Eliminate BasePersistent! (Take two.)
All Zope3 tests pass with python CVS and python 2.2.2b1.
Python 2.2 has peculiar rules about whether a type's instances should
have an __dict__, which have been fixed in 2.3. The new rules make
the BasePersistent unnecessary, because Persistent does not need to
explicitly create an __dict__.
There is a vast simplification to the code by eliminating
BasePersistent and the corresponding C type. All C code uses a single
type (PyPersist_TYPE) and struct (PyPersistObject *). Yay!
But we've still got to support Python 2.2 (bummer) and it's two big a
change to make some version of 2.2 behave like 2.3. So we still need
some sort of hack to make this all work with 2.2. The answer is a
persistent meta class that sets the dictoffset correctly and adds an
__dict__ descriptor.
The change has fairly broad changes to the Persistence package,
because the Python code already used PersistentMetaClass for
persistent clas support. Rename that meta class to
PersistentClassMetaClass, which is descriptive but too verbose. (Then
again all the names are too verbose.)
=== Zope3/lib/python/Persistence/tests/testPersistence.py 1.6 => 1.7 ===
--- Zope3/lib/python/Persistence/tests/testPersistence.py:1.6 Thu Oct 10 04:20:07 2002
+++ Zope3/lib/python/Persistence/tests/testPersistence.py Thu Oct 10 17:36:17 2002
@@ -124,9 +124,17 @@
p = self.klass()
self.assert_(IPersistent.isImplementedBy(p),
"%s does not implement IPersistent" % p)
-
-from Persistence import Persistent, BasePersistent
+ def testDataManagerAndAttributes(self):
+ # Test to cover an odd bug where the instance __dict__ was
+ # set at the same location as the data manager in the C type.
+ p = P()
+ p.inc()
+ p.inc()
+ self.assert_('x' in p.__dict__)
+ self.assert_(p._p_jar is None)
+
+from Persistence import Persistent
class P(Persistent):
def __init__(self):
@@ -140,7 +148,7 @@
def __setstate__(self, v):
self.v = v
-class B(BasePersistent):
+class B(Persistent):
__slots__ = ["x"]
@@ -176,7 +184,6 @@
p2 = pickle.loads(pickle.dumps(p))
self.assertEqual(p2.__class__, P);
self.assertEqual(p2.__dict__, p.__dict__)
-
def testPicklableWCustomState(self):
import pickle