[Zope-CVS] CVS: Products/AdaptableStorage/tests - SerialTestBase.py:1.6 testSerialization.py:1.5 testZope2FS.py:1.7
Shane Hathaway
shane@zope.com
Mon, 9 Dec 2002 17:11:08 -0500
Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv31255/tests
Modified Files:
SerialTestBase.py testSerialization.py testZope2FS.py
Log Message:
Successfully created a CMF site on the filesystem (yehaw!)
This involved some minor fixes:
- cPickle doesn't like anything but strings as persistent IDs. Fixed by
encoding (aspect_name, name) as a string.
- The "isPrincipiaFolderish" test isn't thorough enough; we really need to
know whether the objectItems() method exists. Switched to testing for
the ObjectManager base class. (In Zope 3 this will be an interface check.)
- Added a workaround for the tricky skins tool.
- New unit test for remainder pickling.
- Better integration with DBTab.
=== Products/AdaptableStorage/tests/SerialTestBase.py 1.5 => 1.6 ===
--- Products/AdaptableStorage/tests/SerialTestBase.py:1.5 Mon Dec 9 13:25:29 2002
+++ Products/AdaptableStorage/tests/SerialTestBase.py Mon Dec 9 17:11:07 2002
@@ -19,11 +19,12 @@
import ZODB
from Persistence import PersistentMapping
+from cPickle import dumps, loads
from Products.AdaptableStorage.serial import public as sfw
from Products.AdaptableStorage.serial_std.public import \
StringDataAttribute, MappingGateway, FixedPersistentMapping, RollCall, \
- FixedClassifier
+ FixedClassifier, RemainingState
class SimpleItemsAspect:
@@ -32,16 +33,17 @@
schema = sfw.RowSequenceSchema()
schema.addField('name')
- schema.addField('value')
+ schema.addField('pickle')
def getSchema(self):
return self.schema
def serialize(self, object, event):
- res = object.items()
- res.sort()
- for k, v in res:
+ res = []
+ for k, v in object.items():
+ res.append((k, dumps(v)))
event.notifySerialized(k, v, 0)
+ res.sort()
event.ignoreAttribute('data')
event.ignoreAttribute('_container')
return res
@@ -49,7 +51,9 @@
def deserialize(self, object, event, state):
d = {}
for k, v in state:
- d[k] = v
+ o = loads(v)
+ d[k] = o
+ event.notifyDeserialized(k, o)
object.__init__(d)
@@ -58,6 +62,7 @@
def setUp(self):
classifier = FixedClassifier()
classifier.register('test', 'test_mapper')
+ classifier.register('test2', 'test_mapper_2')
ser2 = sfw.ObjectSerializer('Persistence', 'PersistentMapping')
fixed_items_aspect = FixedPersistentMapping()
@@ -69,6 +74,8 @@
classifier)
self.root_mapper = root_mapper
+ # Create "test_mapper"
+
ser1 = sfw.ObjectSerializer('Persistence', 'PersistentMapping')
items_aspect = SimpleItemsAspect()
ser1.addAspect('items', items_aspect)
@@ -87,6 +94,24 @@
om1 = sfw.ObjectMapper(root_mapper, ser1, gw1)
self.om1 = om1
root_mapper.addSubMapper('test_mapper', om1)
+
+ # Create "test_mapper_2"
+
+ ser = sfw.ObjectSerializer('Persistence', 'PersistentMapping')
+ items_aspect = SimpleItemsAspect()
+ ser.addAspect('items', items_aspect)
+ remain_aspect = RemainingState()
+ ser.addAspect('remainder', remain_aspect)
+
+ gw = sfw.ObjectGateway()
+ items_gw = MappingGateway(items_aspect.getSchema())
+ gw.addGateway('items', items_gw)
+ remain_gw = MappingGateway(remain_aspect.getSchema())
+ gw.addGateway('remainder', remain_gw)
+
+ om = sfw.ObjectMapper(root_mapper, ser, gw)
+ root_mapper.addSubMapper('test_mapper_2', om)
+
def tearDown(self):
pass
=== Products/AdaptableStorage/tests/testSerialization.py 1.4 => 1.5 ===
--- Products/AdaptableStorage/tests/testSerialization.py:1.4 Mon Dec 9 13:25:29 2002
+++ Products/AdaptableStorage/tests/testSerialization.py Mon Dec 9 17:11:07 2002
@@ -25,6 +25,12 @@
from SerialTestBase import SerialTestBase
+class SimpleInstance:
+
+ def __init__(self, data):
+ self.data = data
+
+
class SerializationTests(SerialTestBase, unittest.TestCase):
def getKeyedObjectSystem(self):
@@ -73,6 +79,29 @@
self.assertRaises(sfw.SerializationError,
mapper.getSerializer().serialize, kos, mapper,
'', ob)
+
+ def testSharedAttribute(self):
+ # Test of an attribute shared between an aspect and
+ # a remainder serializer.
+ ob = PersistentMapping()
+ data = SimpleInstance('This is a shared piece of data')
+ ob.extra = data
+ ob['a'] = data
+ kos = self.getKeyedObjectSystem()
+ mapper = self.root_mapper.getSubMapper('test_mapper_2')
+ full_state, refs = mapper.getSerializer().serialize(
+ kos, mapper, '', ob)
+ event = sfw.MapperEvent(mapper, '')
+ mapper.getGateway().store(event, full_state)
+ # Now load the state into a different object
+ full_state, serial = mapper.getGateway().load(event)
+ ob2 = PersistentMapping()
+ mapper.getSerializer().deserialize(kos, mapper, '', ob2, full_state)
+ self.assertEqual(ob.extra.data, ob2.extra.data)
+ self.assertEqual(ob.keys(), ob2.keys())
+ # Check that both see the *same* object
+ self.assert_(ob2['a'] is ob2.extra, (ob2['a'], ob2.extra))
+ self.assert_(ob2['a'] is not data) # Verify it didn't cheat somehow
if __name__ == '__main__':
=== Products/AdaptableStorage/tests/testZope2FS.py 1.6 => 1.7 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.6 Mon Dec 9 15:27:09 2002
+++ Products/AdaptableStorage/tests/testZope2FS.py Mon Dec 9 17:11:07 2002
@@ -197,7 +197,6 @@
conn2.close()
finally:
conn.close()
-
if __name__ == '__main__':