Commit 5890fb04 authored by Jim Fulton's avatar Jim Fulton

Changed the way test records are generated to be consistent with

database format. In particular, data records should always have two
pickles.
parent 3320c159
...@@ -86,8 +86,15 @@ def dumps(obj): ...@@ -86,8 +86,15 @@ def dumps(obj):
p = pickle.Pickler(s) p = pickle.Pickler(s)
p.persistent_id = getpersid p.persistent_id = getpersid
p.dump(obj) p.dump(obj)
p.dump(None)
return s.getvalue() return s.getvalue()
def pdumps(obj):
s = StringIO()
p = pickle.Pickler(s)
p.dump(obj)
p.dump(None)
return s.getvalue()
class PackableStorageBase: class PackableStorageBase:
...@@ -315,11 +322,11 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -315,11 +322,11 @@ class PackableUndoStorage(PackableStorageBase):
oid = obj.getoid() oid = obj.getoid()
obj.value = 1 obj.value = 1
# Commit three different revisions # Commit three different revisions
revid1 = self._dostoreNP(oid, data=pickle.dumps(obj)) revid1 = self._dostoreNP(oid, data=pdumps(obj))
obj.value = 2 obj.value = 2
revid2 = self._dostoreNP(oid, revid=revid1, data=pickle.dumps(obj)) revid2 = self._dostoreNP(oid, revid=revid1, data=pdumps(obj))
obj.value = 3 obj.value = 3
revid3 = self._dostoreNP(oid, revid=revid2, data=pickle.dumps(obj)) revid3 = self._dostoreNP(oid, revid=revid2, data=pdumps(obj))
# Now make sure all three revisions can be extracted # Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid, revid1) data = self._storage.loadSerial(oid, revid1)
pobj = pickle.loads(data) pobj = pickle.loads(data)
...@@ -368,11 +375,11 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -368,11 +375,11 @@ class PackableUndoStorage(PackableStorageBase):
eq(loads(data).value, 0) eq(loads(data).value, 0)
# Commit three different revisions of the other object # Commit three different revisions of the other object
obj.value = 1 obj.value = 1
revid1 = self._dostoreNP(oid, data=pickle.dumps(obj)) revid1 = self._dostoreNP(oid, data=pdumps(obj))
obj.value = 2 obj.value = 2
revid2 = self._dostoreNP(oid, revid=revid1, data=pickle.dumps(obj)) revid2 = self._dostoreNP(oid, revid=revid1, data=pdumps(obj))
obj.value = 3 obj.value = 3
revid3 = self._dostoreNP(oid, revid=revid2, data=pickle.dumps(obj)) revid3 = self._dostoreNP(oid, revid=revid2, data=pdumps(obj))
# Now make sure all three revisions can be extracted # Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid, revid1) data = self._storage.loadSerial(oid, revid1)
pobj = pickle.loads(data) pobj = pickle.loads(data)
...@@ -438,11 +445,11 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -438,11 +445,11 @@ class PackableUndoStorage(PackableStorageBase):
eq(loads(data).value, 0) eq(loads(data).value, 0)
# Commit three different revisions of the first object # Commit three different revisions of the first object
obj1.value = 1 obj1.value = 1
revid1 = self._dostoreNP(oid1, data=pickle.dumps(obj1)) revid1 = self._dostoreNP(oid1, data=pdumps(obj1))
obj1.value = 2 obj1.value = 2
revid2 = self._dostoreNP(oid1, revid=revid1, data=pickle.dumps(obj1)) revid2 = self._dostoreNP(oid1, revid=revid1, data=pdumps(obj1))
obj1.value = 3 obj1.value = 3
revid3 = self._dostoreNP(oid1, revid=revid2, data=pickle.dumps(obj1)) revid3 = self._dostoreNP(oid1, revid=revid2, data=pdumps(obj1))
# Now make sure all three revisions can be extracted # Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid1, revid1) data = self._storage.loadSerial(oid1, revid1)
pobj = pickle.loads(data) pobj = pickle.loads(data)
...@@ -458,7 +465,7 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -458,7 +465,7 @@ class PackableUndoStorage(PackableStorageBase):
eq(pobj.value, 3) eq(pobj.value, 3)
# Now commit a revision of the second object # Now commit a revision of the second object
obj2.value = 11 obj2.value = 11
revid4 = self._dostoreNP(oid2, data=pickle.dumps(obj2)) revid4 = self._dostoreNP(oid2, data=pdumps(obj2))
# And make sure the revision can be extracted # And make sure the revision can be extracted
data = self._storage.loadSerial(oid2, revid4) data = self._storage.loadSerial(oid2, revid4)
pobj = pickle.loads(data) pobj = pickle.loads(data)
...@@ -586,12 +593,12 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -586,12 +593,12 @@ class PackableUndoStorage(PackableStorageBase):
oid = obj.getoid() oid = obj.getoid()
obj.value = 1 obj.value = 1
# Commit two different revisions # Commit two different revisions
revid1 = self._dostoreNP(oid, data=pickle.dumps(obj)) revid1 = self._dostoreNP(oid, data=pdumps(obj))
obj.value = 2 obj.value = 2
snooze() snooze()
packtime = time.time() packtime = time.time()
snooze() snooze()
self._dostoreNP(oid, revid=revid1, data=pickle.dumps(obj)) self._dostoreNP(oid, revid=revid1, data=pdumps(obj))
# Now pack the first transaction # Now pack the first transaction
self.assertEqual(3, len(self._storage.undoLog())) self.assertEqual(3, len(self._storage.undoLog()))
self._storage.pack(packtime, referencesf) self._storage.pack(packtime, referencesf)
...@@ -616,9 +623,9 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -616,9 +623,9 @@ class PackableUndoStorage(PackableStorageBase):
obj2.value = 2 obj2.value = 2
# Commit the first revision of each of them # Commit the first revision of each of them
revid11 = self._dostoreNP(oid1, data=pickle.dumps(obj1), revid11 = self._dostoreNP(oid1, data=pdumps(obj1),
description="1-1") description="1-1")
revid22 = self._dostoreNP(oid2, data=pickle.dumps(obj2), revid22 = self._dostoreNP(oid2, data=pdumps(obj2),
description="2-2") description="2-2")
# remember the time. everything above here will be packed away # remember the time. everything above here will be packed away
...@@ -628,14 +635,14 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -628,14 +635,14 @@ class PackableUndoStorage(PackableStorageBase):
# Commit two revisions of the first object # Commit two revisions of the first object
obj1.value = 3 obj1.value = 3
revid13 = self._dostoreNP(oid1, revid=revid11, revid13 = self._dostoreNP(oid1, revid=revid11,
data=pickle.dumps(obj1), description="1-3") data=pdumps(obj1), description="1-3")
obj1.value = 4 obj1.value = 4
self._dostoreNP(oid1, revid=revid13, self._dostoreNP(oid1, revid=revid13,
data=pickle.dumps(obj1), description="1-4") data=pdumps(obj1), description="1-4")
# Commit one revision of the second object # Commit one revision of the second object
obj2.value = 5 obj2.value = 5
self._dostoreNP(oid2, revid=revid22, self._dostoreNP(oid2, revid=revid22,
data=pickle.dumps(obj2), description="2-5") data=pdumps(obj2), description="2-5")
# Now pack # Now pack
self.assertEqual(6,len(self._storage.undoLog())) self.assertEqual(6,len(self._storage.undoLog()))
print '\ninitial undoLog was' print '\ninitial undoLog was'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment