Commit aa3de9c1 authored by Barry Warsaw's avatar Barry Warsaw

Fix some tests for commit log turd detection. Specifically,

checkCreateWithFilename(), checkCloseDoesUnlink(), checkDel(): Don't
unlink explicitly, but assert that the file is unlinked after close.

BaseSetupTearDown.tearDown(): It's okay if the tear down unlink fails
because the file already doesn't exist.

suite(): Use makeSuite.
parent 34b88faf
# Test the operation of the CommitLog classes # Test the operation of the CommitLog classes
import os import os
import errno
import unittest import unittest
import CommitLog import CommitLog
...@@ -40,27 +41,19 @@ class CreateCommitLogTest(unittest.TestCase): ...@@ -40,27 +41,19 @@ class CreateCommitLogTest(unittest.TestCase):
CommitLog.CommitLog, fp) CommitLog.CommitLog, fp)
finally: finally:
fp.close() fp.close()
os.unlink(filename) assert not os.path.exists(filename)
def checkCloseNoUnlink(self): def checkCloseDoesUnlink(self):
log = CommitLog.CommitLog() log = CommitLog.CommitLog()
filename = log.get_filename() filename = log.get_filename()
log.close() log.close()
try: assert not os.path.exists(filename)
assert os.path.exists(filename)
finally:
os.unlink(filename)
assert not os.path.exists(filename)
def checkDel(self): def checkDel(self):
log = CommitLog.CommitLog() log = CommitLog.CommitLog()
filename = log.get_filename() filename = log.get_filename()
del log del log
try: assert not os.path.exists(filename)
assert os.path.exists(filename)
finally:
os.unlink(filename)
assert not os.path.exists(filename)
...@@ -69,7 +62,10 @@ class BaseSetupTearDown(unittest.TestCase): ...@@ -69,7 +62,10 @@ class BaseSetupTearDown(unittest.TestCase):
self._log = CommitLog.CommitLog() self._log = CommitLog.CommitLog()
def tearDown(self): def tearDown(self):
self._log.close(unlink=1) try:
self._log.close(unlink=1)
except OSError, e:
if e.errno <> errno.ENOENT: raise
...@@ -232,27 +228,11 @@ class FullLogTest(BaseSetupTearDown): ...@@ -232,27 +228,11 @@ class FullLogTest(BaseSetupTearDown):
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
# Creation and closing suite.addTest(unittest.makeSuite(CreateCommitLogTest, 'check'))
suite.addTest(CreateCommitLogTest('checkCreateNoFile')) suite.addTest(unittest.makeSuite(CommitLogStateTransitionTest, 'check'))
suite.addTest(CreateCommitLogTest('checkCreateWithFilename')) suite.addTest(unittest.makeSuite(LowLevelStoreAndLoadTest, 'check'))
suite.addTest(CreateCommitLogTest('checkCreateWithFileobj')) suite.addTest(unittest.makeSuite(PacklessLogTest, 'check'))
suite.addTest(CreateCommitLogTest('checkCloseNoUnlink')) suite.addTest(unittest.makeSuite(FullLogTest, 'check'))
suite.addTest(CreateCommitLogTest('checkDel'))
# State transitions
suite.addTest(CommitLogStateTransitionTest('checkProperStart'))
suite.addTest(CommitLogStateTransitionTest('checkAppendSetsOpen'))
suite.addTest(CommitLogStateTransitionTest('checkPromiseSetsPromise'))
suite.addTest(CommitLogStateTransitionTest('checkBadDoublePromise'))
suite.addTest(CommitLogStateTransitionTest('checkFinishSetsStart'))
# Base class for storing and loading
suite.addTest(LowLevelStoreAndLoadTest('checkOneStoreAndLoad'))
suite.addTest(LowLevelStoreAndLoadTest('checkTenStoresAndLoads'))
# PacklessLog API
suite.addTest(PacklessLogTest('checkOneStoreAndLoad'))
suite.addTest(PacklessLogTest('checkTenStoresAndLoads'))
# FullLog API
suite.addTest(FullLogTest('checkOneStoreAndLoad'))
suite.addTest(FullLogTest('checkOtherWriteMethods'))
return suite return suite
......
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