Convert db unit test to use unittest module

svn: r22760
This commit is contained in:
Nick Hall 2013-07-28 18:54:14 +00:00
parent d5eb5ec8f1
commit a9cad8c0d2
2 changed files with 37 additions and 41 deletions

View File

View File

@ -18,17 +18,15 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# gen/db/test/db_test.py
# $Id$ # $Id$
from __future__ import print_function import unittest
from ..db import (DbReadBase, DbWriteBase, from .. import DbReadBase, DbWriteBase, DbBsddbRead, DbBsddb
DbBsddbRead, DbBsddb)
from ...proxy.proxybase import ProxyDbBase from ...proxy.proxybase import ProxyDbBase
from ...proxy import LivingProxyDb from ...proxy import LivingProxyDb
class DbTest(object): class DbTest(unittest.TestCase):
READ_METHODS = [ READ_METHODS = [
"all_handles", "all_handles",
"close", "close",
@ -182,7 +180,6 @@ class DbTest(object):
"set_researcher", "set_researcher",
"set_save_path", "set_save_path",
"set_undo_callback", "set_undo_callback",
"version_supported", "version_supported",
] ]
@ -236,49 +233,48 @@ class DbTest(object):
"write_version", "write_version",
] ]
def __init__(self, db): def _verify_readonly(self, db):
self.db = db
def _verify_readonly(self):
print("Verifying readonly", self.db.__class__.__name__)
for method in self.READ_METHODS: for method in self.READ_METHODS:
assert hasattr(self.db, method), \ self.assertTrue(hasattr(db, method),
("readonly should have a '%s' method" % method) ("readonly should have a '%s' method" % method))
for method in self.WRITE_METHODS: for method in self.WRITE_METHODS:
assert not hasattr(self.db, method), \ self.assertFalse(hasattr(db, method),
("readonly should NOT have a '%s' method" % method) ("readonly should NOT have a '%s' method" % method))
print("passed!")
def _verify_readwrite(self): def _verify_readwrite(self, db):
print("Verifying readwrite", self.db.__class__.__name__)
for method in self.READ_METHODS: for method in self.READ_METHODS:
assert hasattr(self.db, method), \ self.assertTrue(hasattr(db, method),
("readwrite should have a '%s' method" % method) ("readwrite should have a '%s' method" % method))
for method in self.WRITE_METHODS: for method in self.WRITE_METHODS:
assert hasattr(self.db, method), \ self.assertTrue(hasattr(db, method),
("readwrite should have a '%s' method" % method) ("readwrite should have a '%s' method" % method))
print("passed!")
db1 = DbTest(DbReadBase()) def test_verify_readbase(self):
db1._verify_readonly() db = DbReadBase()
self._verify_readonly(db)
db2 = DbTest(DbWriteBase()) def test_verify_writebase(self):
db2._verify_readwrite() db = DbWriteBase()
self._verify_readwrite(db)
from .. import DbBsddbRead def test_verify_read(self):
db3 = DbTest(DbBsddbRead()) db = DbBsddbRead()
db3._verify_readonly() self._verify_readonly(db)
from .. import DbBsddb def test_verify_write(self):
db4 = DbTest(DbBsddb()) db = DbBsddb()
db4._verify_readwrite() self._verify_readwrite(db)
from ...proxy.proxybase import ProxyDbBase def test_verify_proxy(self):
gdb = DbBsddb() gdb = DbBsddb()
db5 = DbTest(ProxyDbBase(gdb)) db = ProxyDbBase(gdb)
db5._verify_readonly() self._verify_readonly(db)
from ...proxy import LivingProxyDb def test_verify_living(self):
gdb = DbBsddb() gdb = DbBsddb()
db6 = DbTest(LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL)) db = LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL)
db6._verify_readonly() self._verify_readonly(db)
if __name__ == "__main__":
unittest.main()