[Zodb-checkins] CVS: ZODB4/src/persistence/tests - test_persistence.py:1.6
Phillip J. Eby
pje@telecommunity.com
Fri, 11 Apr 2003 17:59:55 -0400
Update of /cvs-repository/ZODB4/src/persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv7086/src/persistence/tests
Modified Files:
test_persistence.py
Log Message:
Fixed the last two bugs from Zope3-Dev Collector #86: you couldn't mix
Persistent and a base class that used a Python metaclass under Python 2.2,
and Persistent subclasses wouldn't have instance dictionaries if a parent
class defined '__slots__', even though for normal Python classes,
subclassing a class with '__slots__' produces a class with instance
dictionaries unless the subclass also defines '__slots__'. Added test
cases for both scenarios. Note that these bugs only existed under Python
2.2, where the custom C metaclass 'PersistentMetaClass' is used.
=== ZODB4/src/persistence/tests/test_persistence.py 1.5 => 1.6 ===
--- ZODB4/src/persistence/tests/test_persistence.py:1.5 Tue Feb 25 17:06:08 2003
+++ ZODB4/src/persistence/tests/test_persistence.py Fri Apr 11 17:59:54 2003
@@ -13,7 +13,7 @@
##############################################################################
import unittest
-from persistence import Persistent
+from persistence import Persistent, PersistentMetaClass
from persistence.interfaces import IPersistent
class Test(unittest.TestCase):
@@ -164,6 +164,41 @@
class E(D, B):
pass
+ def testMultipleMeta(self):
+ # make sure it's possible to define persistent classes
+ # with a base whose metaclass is different
+ class alternateMeta(type):
+ pass
+ class alternate(object):
+ __metaclass__ = alternateMeta
+ class mixedMeta(alternateMeta, PersistentMetaClass):
+ pass
+ class mixed(alternate,Persistent):
+ __metaclass__ = mixedMeta
+
+ def testSlots(self):
+ # Verify that Persistent classes behave the same way
+ # as pure Python objects where '__slots__' and '__dict__'
+ # are concerned.
+
+ class noDict(object):
+ __slots__ = ['foo']
+
+ class shouldHaveDict(noDict):
+ pass
+
+ class p_noDict(Persistent):
+ __slots__ = ['foo']
+
+ class p_shouldHaveDict(p_noDict):
+ pass
+
+ self.assertEqual(noDict.__dictoffset__, 0)
+ self.assertEqual(p_noDict.__dictoffset__, 0)
+
+ self.assert_(shouldHaveDict.__dictoffset__ <> 0)
+ self.assert_(p_shouldHaveDict.__dictoffset__ <> 0)
+
def testBasicTypeStructure(self):
# test that a persistent class has a sane C type structure
# use P (defined below) as simplest example