Commit d3b36376 authored by Barry Warsaw's avatar Barry Warsaw

Don't use assert keyword to ensure that a test passes; use

self.assertEqual() and friends since this gives much better output.
parent f2a208c2
......@@ -68,25 +68,26 @@ class BasicStorage:
revid = ZERO
newrevid = self._dostore(revid=revid)
# Finish the transaction.
assert newrevid <> revid
self.assertNotEqual(newrevid, revid)
def checkNonVersionStoreAndLoad(self):
eq = self.assertEqual
oid = self._storage.new_oid()
self._dostore(oid=oid, data=MinPO(7))
data, revid = self._storage.load(oid, '')
value = zodb_unpickle(data)
assert value == MinPO(7)
eq(value, MinPO(7))
# Now do a bunch of updates to an object
for i in range(13, 22):
revid = self._dostore(oid, revid=revid, data=MinPO(i))
# Now get the latest revision of the object
data, revid = self._storage.load(oid, '')
assert zodb_unpickle(data) == MinPO(21)
eq(zodb_unpickle(data), MinPO(21))
def checkNonVersionModifiedInVersion(self):
oid = self._storage.new_oid()
self._dostore(oid=oid)
assert self._storage.modifiedInVersion(oid) == ''
self.assertEqual(self._storage.modifiedInVersion(oid), '')
def checkLoadSerial(self):
oid = self._storage.new_oid()
......@@ -98,7 +99,7 @@ class BasicStorage:
# Now make sure all the revisions have the correct value
for revid, value in revisions.items():
data = self._storage.loadSerial(oid, revid)
assert zodb_unpickle(data) == value
self.assertEqual(zodb_unpickle(data), value)
def checkConflicts(self):
oid = self._storage.new_oid()
......
......@@ -65,7 +65,7 @@ class ConflictResolvingStorage:
data, serialno = self._storage.load(oid, '')
inst = zodb_unpickle(data)
self.assert_(inst._value == 5)
self.assertEqual(inst._value, 5)
def checkUnresolvable(self):
obj = PCounter2()
......
......@@ -44,7 +44,7 @@ class FileStorageCorruptTests(StorageTestBase):
# truncation the index file
path = self.path + '.index'
self.assert_(os.path.exists(path))
self.failUnless(os.path.exists(path))
f = open(path, 'r+')
f.seek(0, 2)
size = f.tell()
......@@ -61,7 +61,7 @@ class FileStorageCorruptTests(StorageTestBase):
# truncation the index file
path = self.path + '.index'
self.assert_(os.path.exists(path))
self.failUnless(os.path.exists(path))
size = os.stat(path)[stat.ST_SIZE]
f = open(path, 'r+')
while f.tell() < size:
......
......@@ -8,6 +8,7 @@ from ZODB.tests.StorageTestBase import zodb_unpickle
class HistoryStorage:
def checkSimpleHistory(self):
eq = self.assertEqual
# Store a couple of non-version revisions of the object
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
......@@ -15,36 +16,46 @@ class HistoryStorage:
revid3 = self._dostore(oid, revid=revid2, data=MinPO(13))
# Now get various snapshots of the object's history
h = self._storage.history(oid, size=1)
assert len(h) == 1
eq(len(h), 1)
d = h[0]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
# Try to get 2 historical revisions
h = self._storage.history(oid, size=2)
assert len(h) == 2
eq(len(h), 2)
d = h[0]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[1]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
# Try to get all 3 historical revisions
h = self._storage.history(oid, size=3)
assert len(h) == 3
eq(len(h), 3)
d = h[0]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[1]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
d = h[2]
assert d['serial'] == revid1 and d['version'] == ''
eq(d['serial'], revid1)
eq(d['version'], '')
# There should be no more than 3 revisions
h = self._storage.history(oid, size=4)
assert len(h) == 3
eq(len(h), 3)
d = h[0]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[1]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
d = h[2]
assert d['serial'] == revid1 and d['version'] == ''
eq(d['serial'], revid1)
eq(d['version'], '')
def checkVersionHistory(self):
eq = self.assertEqual
# Store a couple of non-version revisions
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
......@@ -61,21 +72,28 @@ class HistoryStorage:
# Now, try to get the six historical revisions (first three are in
# 'test-version', followed by the non-version revisions).
h = self._storage.history(oid, version, 100)
assert len(h) == 6
eq(len(h), 6)
d = h[0]
assert d['serial'] == revid6 and d['version'] == version
eq(d['serial'], revid6)
eq(d['version'], version)
d = h[1]
assert d['serial'] == revid5 and d['version'] == version
eq(d['serial'], revid5)
eq(d['version'], version)
d = h[2]
assert d['serial'] == revid4 and d['version'] == version
eq(d['serial'], revid4)
eq(d['version'], version)
d = h[3]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[4]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
d = h[5]
assert d['serial'] == revid1 and d['version'] == ''
eq(d['serial'], revid1)
eq(d['version'], '')
def checkHistoryAfterVersionCommit(self):
eq = self.assertEqual
# Store a couple of non-version revisions
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
......@@ -108,23 +126,31 @@ class HistoryStorage:
# Now, try to get the six historical revisions (first three are in
# 'test-version', followed by the non-version revisions).
h = self._storage.history(oid, version, 100)
assert len(h) == 7
eq(len(h), 7)
d = h[0]
assert d['serial'] == revid7 and d['version'] == ''
eq(d['serial'], revid7)
eq(d['version'], '')
d = h[1]
assert d['serial'] == revid6 and d['version'] == version
eq(d['serial'], revid6)
eq(d['version'], version)
d = h[2]
assert d['serial'] == revid5 and d['version'] == version
eq(d['serial'], revid5)
eq(d['version'], version)
d = h[3]
assert d['serial'] == revid4 and d['version'] == version
eq(d['serial'], revid4)
eq(d['version'], version)
d = h[4]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[5]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
d = h[6]
assert d['serial'] == revid1 and d['version'] == ''
eq(d['serial'], revid1)
eq(d['version'], '')
def checkHistoryAfterVersionAbort(self):
eq = self.assertEqual
# Store a couple of non-version revisions
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
......@@ -157,18 +183,25 @@ class HistoryStorage:
# Now, try to get the six historical revisions (first three are in
# 'test-version', followed by the non-version revisions).
h = self._storage.history(oid, version, 100)
assert len(h) == 7
eq(len(h), 7)
d = h[0]
assert d['serial'] == revid7 and d['version'] == ''
eq(d['serial'], revid7)
eq(d['version'], '')
d = h[1]
assert d['serial'] == revid6 and d['version'] == version
eq(d['serial'], revid6)
eq(d['version'], version)
d = h[2]
assert d['serial'] == revid5 and d['version'] == version
eq(d['serial'], revid5)
eq(d['version'], version)
d = h[3]
assert d['serial'] == revid4 and d['version'] == version
eq(d['serial'], revid4)
eq(d['version'], version)
d = h[4]
assert d['serial'] == revid3 and d['version'] == ''
eq(d['serial'], revid3)
eq(d['version'], '')
d = h[5]
assert d['serial'] == revid2 and d['version'] == ''
eq(d['serial'], revid2)
eq(d['version'], '')
d = h[6]
assert d['serial'] == revid1 and d['version'] == ''
eq(d['serial'], revid1)
eq(d['version'], '')
......@@ -8,6 +8,7 @@ from ZODB.tests.StorageTestBase import zodb_unpickle
class IteratorStorage:
def checkSimpleIteration(self):
eq = self.assertEqual
# Store a bunch of revisions of a single object
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
......@@ -17,10 +18,10 @@ class IteratorStorage:
val = 11
txniter = self._storage.iterator()
for reciter, revid in zip(txniter, (revid1, revid2, revid3)):
assert reciter.tid == revid
eq(reciter.tid, revid)
for rec in reciter:
assert rec.oid == oid
assert rec.serial == revid
assert rec.version == ''
assert zodb_unpickle(rec.data) == MinPO(val)
eq(rec.oid, oid)
eq(rec.serial, revid)
eq(rec.version, '')
eq(zodb_unpickle(rec.data), MinPO(val))
val = val + 1
......@@ -5,10 +5,10 @@ class LocalStorage:
implementation for ZEO is inexact.
"""
def checkLen(self):
eq = self.assertEqual
# The length of the database ought to grow by one each time
assert len(self._storage) == 0
eq(len(self._storage), 0)
self._dostore()
assert len(self._storage) == 1
eq(len(self._storage), 1)
self._dostore()
assert len(self._storage) == 2
eq(len(self._storage), 2)
......@@ -104,6 +104,8 @@ class PackableStorageBase:
class PackableStorage(PackableStorageBase):
def checkPackAllRevisions(self):
eq = self.assertEqual
raises = self.assertRaises
# Create a `persistent' object
obj = self._newobj()
oid = obj.getoid()
......@@ -117,25 +119,27 @@ class PackableStorage(PackableStorageBase):
# Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid, revid1)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 1
eq(pobj.getoid(), oid)
eq(pobj.value, 1)
data = self._storage.loadSerial(oid, revid2)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 2
eq(pobj.getoid(), oid)
eq(pobj.value, 2)
data = self._storage.loadSerial(oid, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 3
eq(pobj.getoid(), oid)
eq(pobj.value, 3)
# Now pack all transactions
self._storage.pack(time.time(), referencesf)
# All revisions of the object should be gone, since there is no
# reference from the root object to this object.
self.assertRaises(KeyError,
self._storage.loadSerial, oid, revid1)
self.assertRaises(KeyError,
self._storage.loadSerial, oid, revid2)
self.assertRaises(KeyError,
self._storage.loadSerial, oid, revid3)
raises(KeyError, self._storage.loadSerial, oid, revid1)
raises(KeyError, self._storage.loadSerial, oid, revid2)
raises(KeyError, self._storage.loadSerial, oid, revid3)
def checkPackJustOldRevisions(self):
eq = self.assertEqual
raises = self.assertRaises
loads = self._makeloader()
# Create a root object. This can't be an instance of Object,
# otherwise the pickling machinery will serialize it as a persistent
......@@ -152,7 +156,8 @@ class PackableStorage(PackableStorageBase):
revid0 = self._dostoreNP(ZERO, data=dumps(root))
# Make sure the root can be retrieved
data, revid = self._storage.load(ZERO, '')
assert revid == revid0 and loads(data).value == 0
eq(revid, revid0)
eq(loads(data).value, 0)
# Commit three different revisions of the other object
obj.value = 1
revid1 = self._dostoreNP(oid, data=pickle.dumps(obj))
......@@ -163,33 +168,39 @@ class PackableStorage(PackableStorageBase):
# Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid, revid1)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 1
eq(pobj.getoid(), oid)
eq(pobj.value, 1)
data = self._storage.loadSerial(oid, revid2)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 2
eq(pobj.getoid(), oid)
eq(pobj.value, 2)
data = self._storage.loadSerial(oid, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 3
eq(pobj.getoid(), oid)
eq(pobj.value, 3)
# Now pack just revisions 1 and 2. The object's current revision
# should stay alive because it's pointed to by the root.
self._storage.pack(time.time(), referencesf)
# Make sure the revisions are gone, but that object zero and revision
# 3 are still there and correct
data, revid = self._storage.load(ZERO, '')
assert revid == revid0 and loads(data).value == 0
self.assertRaises(KeyError,
self._storage.loadSerial, oid, revid1)
self.assertRaises(KeyError,
self._storage.loadSerial, oid, revid2)
eq(revid, revid0)
eq(loads(data).value, 0)
raises(KeyError, self._storage.loadSerial, oid, revid1)
raises(KeyError, self._storage.loadSerial, oid, revid2)
data = self._storage.loadSerial(oid, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 3
eq(pobj.getoid(), oid)
eq(pobj.value, 3)
data, revid = self._storage.load(oid, '')
assert revid == revid3
eq(revid, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid and pobj.value == 3
eq(pobj.getoid(), oid)
eq(pobj.value, 3)
def checkPackOnlyOneObject(self):
eq = self.assertEqual
raises = self.assertRaises
loads = self._makeloader()
# Create a root object. This can't be an instance of Object,
# otherwise the pickling machinery will serialize it as a persistent
......@@ -203,7 +214,7 @@ class PackableStorage(PackableStorageBase):
# sure it's oid is greater than the first object's oid.
obj2 = self._newobj()
oid2 = obj2.getoid()
assert oid2 > oid1
self.failUnless(oid2 > oid1)
# Link the root object to the persistent objects, in order to keep
# them alive. Store the root object.
root.obj1 = obj1
......@@ -212,7 +223,8 @@ class PackableStorage(PackableStorageBase):
revid0 = self._dostoreNP(ZERO, data=dumps(root))
# Make sure the root can be retrieved
data, revid = self._storage.load(ZERO, '')
assert revid == revid0 and loads(data).value == 0
eq(revid, revid0)
eq(loads(data).value, 0)
# Commit three different revisions of the first object
obj1.value = 1
revid1 = self._dostoreNP(oid1, data=pickle.dumps(obj1))
......@@ -223,20 +235,24 @@ class PackableStorage(PackableStorageBase):
# Now make sure all three revisions can be extracted
data = self._storage.loadSerial(oid1, revid1)
pobj = pickle.loads(data)
assert pobj.getoid() == oid1 and pobj.value == 1
eq(pobj.getoid(), oid1)
eq(pobj.value, 1)
data = self._storage.loadSerial(oid1, revid2)
pobj = pickle.loads(data)
assert pobj.getoid() == oid1 and pobj.value == 2
eq(pobj.getoid(), oid1)
eq(pobj.value, 2)
data = self._storage.loadSerial(oid1, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid1 and pobj.value == 3
eq(pobj.getoid(), oid1)
eq(pobj.value, 3)
# Now commit a revision of the second object
obj2.value = 11
revid4 = self._dostoreNP(oid2, data=pickle.dumps(obj2))
# And make sure the revision can be extracted
data = self._storage.loadSerial(oid2, revid4)
pobj = pickle.loads(data)
assert pobj.getoid() == oid2 and pobj.value == 11
eq(pobj.getoid(), oid2)
eq(pobj.value, 11)
# Now pack just revisions 1 and 2 of object1. Object1's current
# revision should stay alive because it's pointed to by the root, as
# should Object2's current revision.
......@@ -244,20 +260,23 @@ class PackableStorage(PackableStorageBase):
# Make sure the revisions are gone, but that object zero, object2, and
# revision 3 of object1 are still there and correct.
data, revid = self._storage.load(ZERO, '')
assert revid == revid0 and loads(data).value == 0
self.assertRaises(KeyError,
self._storage.loadSerial, oid1, revid1)
self.assertRaises(KeyError,
self._storage.loadSerial, oid1, revid2)
eq(revid, revid0)
eq(loads(data).value, 0)
raises(KeyError, self._storage.loadSerial, oid1, revid1)
raises(KeyError, self._storage.loadSerial, oid1, revid2)
data = self._storage.loadSerial(oid1, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid1 and pobj.value == 3
eq(pobj.getoid(), oid1)
eq(pobj.value, 3)
data, revid = self._storage.load(oid1, '')
assert revid == revid3
eq(revid, revid3)
pobj = pickle.loads(data)
assert pobj.getoid() == oid1 and pobj.value == 3
eq(pobj.getoid(), oid1)
eq(pobj.value, 3)
data, revid = self._storage.load(oid2, '')
assert revid == revid4 and loads(data).value == 11
eq(revid, revid4)
eq(loads(data).value, 11)
data = self._storage.loadSerial(oid2, revid4)
pobj = pickle.loads(data)
assert pobj.getoid() == oid2 and pobj.value == 11
eq(pobj.getoid(), oid2)
eq(pobj.value, 11)
This diff is collapsed.
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