[Zope-CVS] CVS: Products/Ape/lib/apelib/tests - testio.py:1.1 testall.py:1.3 testserialization.py:1.3 teststorage.py:1.4
Shane Hathaway
shane@zope.com
Mon, 26 May 2003 15:33:46 -0400
Update of /cvs-repository/Products/Ape/lib/apelib/tests
In directory cvs.zope.org:/tmp/cvs-serv13513/tests
Modified Files:
testall.py testserialization.py teststorage.py
Added Files:
testio.py
Log Message:
Added some facades in a new module called apelib.core.io. These are
designed to make it easier to:
- reuse Ape in different frameworks
- do simple operations like import / export objects
- ignore classification and mapper_names details
In support of this:
- Added tests for ape.core.io.
- Renamed loadStub() to getObject(). The old name was silly. ;-)
Left a deprecated alias.
- Moved getExternalRefs() to ISDEvent so that IDeserializationEvent
now implements it as well. This mades it easier to implement object
import.
- Created IClassFactory. IKeyedObjectSystem extends it.
- Changed the signature of createEmptyInstance so that an
IClassFactory is always expected.
=== Added File Products/Ape/lib/apelib/tests/testio.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of apelib.core.io
$Id: testio.py,v 1.1 2003/05/26 19:33:16 shane Exp $
"""
import unittest
import ZODB
from Persistence import PersistentMapping
from apelib.core import io
from apelib.core.interfaces import IKeyedObjectSystem
from serialtestbase import SerialTestBase
class TestKeyedObjectSystem:
__implements__ = IKeyedObjectSystem
def getObject(self, keychain, hints=None):
raise NotImplementedError
loadStub = getObject
def identifyObject(self, obj):
raise NotImplementedError
def newKey(self):
raise NotImplementedError
def getClass(self, module, name):
m = __import__(module)
return getattr(m, name)
class ApeIOTests(SerialTestBase, unittest.TestCase):
def getKeyedObjectSystem(self):
return TestKeyedObjectSystem()
def getMapper(self):
return self.root_mapper
def testImpl(self):
# Test of test :-)
from Interface.Verify import verifyClass
verifyClass(IKeyedObjectSystem, TestKeyedObjectSystem)
def testSerializeAndDeserialize(self):
ob = PersistentMapping()
ob.strdata = '345'
ob['a'] = 'b'
ob['c'] = 'd'
keychain = ('test',)
kos = self.getKeyedObjectSystem()
obsys = io.ObjectSystemIO(self.getMapper(), kos)
event, classified_state = obsys.serialize(keychain, ob)
ob2 = obsys.newObject(classified_state)
obsys.deserialize(keychain, ob2, classified_state)
self.assertEqual(ob.strdata, ob2.strdata)
self.assertEqual(ob, ob2)
def testStoreAndLoad(self):
# Tests both serialization and storage
ob = PersistentMapping()
ob.strdata = '345'
ob['a'] = 'b'
ob['c'] = 'd'
keychain = ('test',)
kos = self.getKeyedObjectSystem()
obsys = io.ObjectSystemIO(self.getMapper(), kos)
gwsys = io.GatewayIO(self.getMapper(), self.conns)
event, classified_state = obsys.serialize(keychain, ob)
gwsys.store(keychain, classified_state)
cs, hash_value = gwsys.load(keychain)
ob2 = obsys.newObject(cs)
obsys.deserialize(keychain, ob2, cs)
self.assertEqual(ob.strdata, ob2.strdata)
self.assertEqual(ob, ob2)
def testExportImport(self):
ob = PersistentMapping()
ob.strdata = '345'
ob['a'] = 'b'
ob['c'] = 'd'
keychain = ('test',)
exporter = io.ExportImport(self.getMapper(), self.conns)
exporter.exportObject(ob, keychain)
importer = io.ExportImport(self.getMapper(), self.conns)
ob2 = importer.importObject(keychain)
self.assert_(ob is not ob2)
self.assertEqual(ob, ob2)
self.assertEqual(ob.strdata, ob2.strdata)
if __name__ == '__main__':
unittest.main()
=== Products/Ape/lib/apelib/tests/testall.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/tests/testall.py:1.2 Sat Apr 12 16:56:26 2003
+++ Products/Ape/lib/apelib/tests/testall.py Mon May 26 15:33:16 2003
@@ -33,6 +33,7 @@
from testserialization import SerializationTests
from testimpl import ApelibImplTests
from teststorage import ApeStorageTests
+from testio import ApeIOTests
from testzope2fs import Zope2FSTests, Zope2FSUnderscoreTests
from testparams import ParamsTests
from testsqlimpl import ApelibSQLImplTests
@@ -46,6 +47,7 @@
SerializationTests,
ApelibImplTests,
ApeStorageTests,
+ ApeIOTests,
Zope2FSTests,
Zope2FSUnderscoreTests,
ParamsTests,
=== Products/Ape/lib/apelib/tests/testserialization.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/tests/testserialization.py:1.2 Tue Apr 29 18:11:51 2003
+++ Products/Ape/lib/apelib/tests/testserialization.py Mon May 26 15:33:16 2003
@@ -52,7 +52,7 @@
event = DeserializationEvent(kos, mapper, ('',), ob2)
mapper.getSerializer().deserialize(ob2, event, full_state)
self.assertEqual(ob.strdata, ob2.strdata)
- self.assertEqual(ob.items(), ob2.items())
+ self.assertEqual(ob, ob2)
def testStoreAndLoad(self):
ob = PersistentMapping()
@@ -72,7 +72,7 @@
event = DeserializationEvent(kos, mapper, ('',), ob2)
mapper.getSerializer().deserialize(ob2, event, full_state)
self.assertEqual(ob.strdata, ob2.strdata)
- self.assertEqual(ob.items(), ob2.items())
+ self.assertEqual(ob, ob2)
def testCatchExtraAttribute(self):
ob = PersistentMapping()
=== Products/Ape/lib/apelib/tests/teststorage.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/tests/teststorage.py:1.3 Wed May 14 10:32:25 2003
+++ Products/Ape/lib/apelib/tests/teststorage.py Mon May 26 15:33:16 2003
@@ -78,14 +78,14 @@
root['TestRoot'] = ob
root['TestRoot2'] = dummy
get_transaction().commit()
- ob1 = conn1.loadStub(('test',))
+ ob1 = conn1.getObject(('test',))
self.assertEqual(ob1.strdata, ob.strdata)
self.assertEqual(ob1.items(), ob.items())
# Verify a new object was stored and make a change
get_transaction().begin()
conn2 = self.db.open()
- ob2 = conn2.loadStub(('test',))
+ ob2 = conn2.getObject(('test',))
self.assertEqual(ob2.strdata, ob.strdata)
self.assertEqual(ob2.items(), ob.items())
ob2.strdata = '678'
@@ -93,7 +93,7 @@
# Verify the change was stored and make another change
conn3 = self.db.open()
- ob3 = conn3.loadStub(('test',))
+ ob3 = conn3.getObject(('test',))
self.assertEqual(ob3.strdata, '678')
self.assertEqual(ob3.items(), ob.items())
ob3.strdata = '901'
@@ -101,7 +101,7 @@
conn3.close()
conn3 = None
conn3 = self.db.open()
- ob3 = conn3.loadStub(('test',))
+ ob3 = conn3.getObject(('test',))
self.assertEqual(ob3.strdata, '901')
# Verify we didn't accidentally change the original object
@@ -135,7 +135,7 @@
root['TestRoot'] = dummy
root['TestRoot2'] = ob
get_transaction().commit()
- ob1 = conn1.loadStub(('test2',))
+ ob1 = conn1.getObject(('test2',))
self.assert_(ob1 is ob)
self.assertEqual(ob1.items(), [('a', 'b')])
self.assertEqual(ob1.stowaway.items(), [('c', 'd')])
@@ -143,7 +143,7 @@
# Verify a new object was stored
get_transaction().begin()
conn2 = self.db.open()
- ob2 = conn2.loadStub(('test2',))
+ ob2 = conn2.getObject(('test2',))
self.assertEqual(ob2.items(), [('a', 'b')])
self.assertEqual(ob2.stowaway.items(), [('c', 'd')])
@@ -155,7 +155,7 @@
# Verify the change was stored and make a change to the
# managed persistent object.
conn3 = self.db.open()
- ob3 = conn3.loadStub(('test2',))
+ ob3 = conn3.getObject(('test2',))
self.assertEqual(ob3.items(), [('a', 'b')])
self.assertEqual(ob3.stowaway.items(), [('c', 'e')])
ob3['a'] = 'z'
@@ -163,7 +163,7 @@
conn3.close()
conn3 = None
conn3 = self.db.open()
- ob3 = conn3.loadStub(('test2',))
+ ob3 = conn3.getObject(('test2',))
self.assertEqual(ob3['a'], 'z')
self.assertEqual(ob3.stowaway.items(), [('c', 'e')])
@@ -197,7 +197,7 @@
root['TestRoot'] = ob
root['TestRoot2'] = dummy
get_transaction().commit()
- ob1 = conn1.loadStub(('test',))
+ ob1 = conn1.getObject(('test',))
self.assertEqual(ob1.strdata, ob.strdata)
self.assertEqual(ob1.items(), ob.items())
finally: