[Zodb-checkins] CVS: Zope2/lib/python/ZODB - VersionStorage.py:1.3
Jim Fulton
jim@digicool.com
Thu, 12 Apr 2001 19:32:39 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/ZODB/tests
In directory korak:/tmp/cvs-serv9759
Modified Files:
VersionStorage.py
Log Message:
Fixed a number of tests. The tests didn't recognize that when an
object hasn't been modified in a version, we fall back to non-version
data.
There are a couple of places where the spec was unclear and I punted
for now.
--- Updated File VersionStorage.py in package Zope2/lib/python/ZODB --
--- VersionStorage.py 2001/04/11 22:07:52 1.2
+++ VersionStorage.py 2001/04/12 23:32:38 1.3
@@ -34,9 +34,12 @@
self._storage.load,
self._storage.new_oid(), '')
# Try to load a bogus version string
- self.assertRaises(POSException.VersionError,
- self._storage.load,
- oid, 'bogus')
+ #JF# Nope, fall back to non-version
+ #JF# self.assertRaises(KeyError,
+ #JF# self._storage.load,
+ #JF# oid, 'bogus')
+ data, revid = self._storage.load(oid, 'bogus')
+ assert pickle.loads(data) == 11
def checkVersionLock(self):
@@ -52,7 +55,9 @@
def checkVersionEmpty(self):
# Before we store anything, these versions ought to be empty
version = 'test-version'
- assert self._storage.versionEmpty('')
+ #JF# The empty string is not a valid version. I think that this should
+ #JF# be an error. Let's punt for now.
+ #JF# assert self._storage.versionEmpty('')
assert self._storage.versionEmpty(version)
# Now store some objects
oid = self._storage.new_oid()
@@ -61,7 +66,10 @@
revid = self._dostore(oid, revid=revid, data=13, version=version)
revid = self._dostore(oid, revid=revid, data=14, version=version)
# The blank version should not be empty
- assert not self._storage.versionEmpty('')
+ #JF# The empty string is not a valid version. I think that this should
+ #JF# be an error. Let's punt for now.
+ #JF# assert not self._storage.versionEmpty('')
+
# Neither should 'test-version'
assert not self._storage.versionEmpty(version)
# But this non-existant version should be empty
@@ -117,11 +125,16 @@
oid, version = self._setup_version()
# Now abort a bogus version
self._storage.tpc_begin(self._transaction)
- self.assertRaises(KeyError,
- self._storage.abortVersion,
- 'bogus', self._transaction)
+
+ #JF# The spec is silent on what happens if you abort or commit
+ #JF# a non-existent version. FileStorage consideres this a noop.
+ #JF# We can change the spec, but until we do ....
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.abortVersion,
+ #JF# 'bogus', self._transaction)
+
# And try to abort the empty version
- self.assertRaises(KeyError,
+ self.assertRaises(POSException.VersionError,
self._storage.abortVersion,
'', self._transaction)
# But now we really try to abort the version
@@ -172,8 +185,13 @@
data, revid2 = self._storage.load(oid2, version2)
assert pickle.loads(data) == 54
# Let's make sure we can't get object1 in version2
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version2)
+ #JF# This won't fail because we fall back to non-version data.
+ #JF# In fact, it must succed and give us 51
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version2)
+ data, revid2 = self._storage.load(oid1, version2)
+ assert pickle.loads(data) == 51
+
# Okay, now let's commit object1 to version2
self._storage.tpc_begin(self._transaction)
oids = self._storage.commitVersion(version1, version2,
@@ -186,8 +204,11 @@
assert pickle.loads(data) == 54
data, revid = self._storage.load(oid2, version2)
assert pickle.loads(data) == 54
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version1)
+ #JF# Ditto, sort of
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version1)
+ data, revid2 = self._storage.load(oid1, version1)
+ assert pickle.loads(data) == 51
def checkAbortOneVersionCommitTheOther(self):
oid1, version1 = self._setup_version('one')
@@ -197,8 +218,15 @@
data, revid2 = self._storage.load(oid2, version2)
assert pickle.loads(data) == 54
# Let's make sure we can't get object1 in version2
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version2)
+
+ #JF# It's not an error to load data in a different version when data
+ #JF# are stored in non-version. See above
+ #JF#
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version2)
+ data, revid2 = self._storage.load(oid1, version2)
+ assert pickle.loads(data) == 51
+
# First, let's abort version1
self._storage.tpc_begin(self._transaction)
oids = self._storage.abortVersion(version1, self._transaction)
@@ -208,10 +236,17 @@
assert oids[0] == oid1
data, revid = self._storage.load(oid1, '')
assert pickle.loads(data) == 51
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version1)
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version2)
+
+ #JF# Ditto
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version1)
+ data, revid = self._storage.load(oid1, '')
+ assert pickle.loads(data) == 51
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version2)
+ data, revid = self._storage.load(oid1, '')
+ assert pickle.loads(data) == 51
+
data, revid = self._storage.load(oid2, '')
assert pickle.loads(data) == 51
data, revid = self._storage.load(oid2, version2)
@@ -224,10 +259,24 @@
assert len(oids) == 1
assert oids[0] == oid2
# These objects should not be found in version 2
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid1, version2)
- self.assertRaises(POSException.VersionError,
- self._storage.load, oid2, version2)
+ #JF# Ditto
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid1, version2)
+ data, revid = self._storage.load(oid1, '')
+ assert pickle.loads(data) == 51
+ #JF# self.assertRaises(POSException.VersionError,
+ #JF# self._storage.load, oid2, version2)
# But the trunk should be up to date now
+ data, revid = self._storage.load(oid2, version2)
+ assert pickle.loads(data) == 54
data, revid = self._storage.load(oid2, '')
assert pickle.loads(data) == 54
+
+
+ #JF# To do a test like you want, you have to add the data in a version
+ oid = self._storage.new_oid()
+ revid = self._dostore(oid, revid=revid, data=54, version='one')
+ self.assertRaises(KeyError,
+ self._storage.load, oid, '')
+ self.assertRaises(KeyError,
+ self._storage.load, oid, 'two')