[Zodb-checkins] CVS: Zope3/src/zodb/storage/tests - test_base.py:1.1.2.1 base.py:1.2.4.1

Jeremy Hylton jeremy@zope.com
Tue, 21 Jan 2003 11:20:44 -0500


Update of /cvs-repository/Zope3/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv25266/src/zodb/storage/tests

Modified Files:
      Tag: new-pickle-branch
	base.py 
Added Files:
      Tag: new-pickle-branch
	test_base.py 
Log Message:
Add database version information to the storage.

Only handled for file storage so far.  A file storage now has two
version identifiers.  The first identifies the storage format and is
independent of the pickle format.  The second identifies the object
format used by the database.  The intent of the database format is to
allow future migration from old versions of the database.  (If we'd
ever change the pickle format again, a script could use the database
version to detect old pickles.)



=== Added File Zope3/src/zodb/storage/tests/test_base.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
import sys
import unittest

from zodb.storage.base import encode_version, decode_version

class BaseTest(unittest.TestCase):

    def test_version_info(self):
        enc = encode_version(sys.version_info)
        dec = decode_version(enc)
        self.assertEqual(dec, sys.version_info)

def test_suite():
    return unittest.makeSuite(BaseTest)



=== Zope3/src/zodb/storage/tests/base.py 1.2 => 1.2.4.1 ===
--- Zope3/src/zodb/storage/tests/base.py:1.2	Wed Dec 25 09:12:20 2002
+++ Zope3/src/zodb/storage/tests/base.py	Tue Jan 21 11:20:40 2003
@@ -29,7 +29,7 @@
 from cPickle import Pickler, Unpickler
 from cStringIO import StringIO
 
-from zodb.serialize import ConnectionObjectReader
+from zodb.serialize import ConnectionObjectReader, ObjectWriter
 from zodb.ztransaction import Transaction
 
 from zodb.storage.tests.minpo import MinPO
@@ -40,15 +40,8 @@
 
 def zodb_pickle(obj):
     """Create a pickle in the format expected by ZODB."""
-    f = StringIO()
-    p = Pickler(f, 1)
-    klass = obj.__class__
-    mod = getattr(klass, "__module__", None)
-    state = obj.__getstate__()
-    # XXX
-    p.dump((mod, klass.__name__, None))
-    p.dump(state)
-    return f.getvalue(1)
+    ow = ObjectWriter()
+    return ow.getState(obj)
 
 def zodb_unpickle(data):
     """Unpickle an object stored using the format expected by ZODB."""