[Zope-CVS] CVS: Products/AdaptableStorage/tests - testASStorage.py:1.10

Shane Hathaway shane@zope.com
Fri, 21 Feb 2003 12:18:25 -0500


Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv16106/tests

Modified Files:
	testASStorage.py 
Log Message:
copyOf() can now copy ZClass instances

=== Products/AdaptableStorage/tests/testASStorage.py 1.9 => 1.10 ===
--- Products/AdaptableStorage/tests/testASStorage.py:1.9	Fri Jan 17 22:33:49 2003
+++ Products/AdaptableStorage/tests/testASStorage.py	Fri Feb 21 12:17:54 2003
@@ -25,6 +25,7 @@
 from Products.AdaptableStorage.zodb.ASDB import ASDB
 from Products.AdaptableStorage.zodb.ASStorage import ASStorage
 from Products.AdaptableStorage.zodb.StaticResource import StaticResource
+from Products.AdaptableStorage.zodb.utils import copyOf
 from SerialTestBase import SerialTestBase
 
 
@@ -283,6 +284,40 @@
                 conn2.close()
         finally:
             conn1.close()
+
+
+    def testCopyOf(self):
+        # Verifies the functionality of copyOf().
+        ob1 = PersistentMapping()
+        ob1._p_oid = 'xxx'
+        self.assertEqual(ob1._p_oid, 'xxx')  # Precondition
+        ob1['fish'] = PersistentMapping()
+        ob1['fish']['trout'] = 1
+        ob1['fish']['herring'] = 2
+
+        ob2 = copyOf(ob1)
+        self.assert_(ob2 is not ob1)
+        self.assert_(ob2['fish'] is not ob1['fish'])
+        self.assert_(ob2._p_oid is None)
+        self.assertEqual(list(ob2.keys()), ['fish'])
+        self.assertEqual(len(ob2['fish'].keys()), 2)
+
+
+    def testCopyOfZClassInstance(self):
+        # Verifies that copyOf() can copy instances that look like ZClass
+        # instances.
+        class weird_class (ZODB.Persistent):
+            pass
+        weird_class.__module__ = '*IAmAZClassModule'
+        self.assertEqual(weird_class.__module__, '*IAmAZClassModule')
+
+        ob1 = PersistentMapping()
+        ob1['fishy'] = weird_class()
+
+        ob2 = copyOf(ob1)
+        self.assert_(ob2 is not ob1)
+        self.assert_(ob2['fishy'] is not ob1['fishy'])
+        self.assert_(ob2['fishy'].__class__ is weird_class)
 
 
 if __name__ == '__main__':