From a9cad8c0d2e14fb3f436dd7c7522e8ee7f9f9af6 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sun, 28 Jul 2013 18:54:14 +0000 Subject: [PATCH] Convert db unit test to use unittest module svn: r22760 --- gramps/gen/db/test/__init__.py | 0 gramps/gen/db/test/db_test.py | 78 ++++++++++++++++------------------ 2 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 gramps/gen/db/test/__init__.py diff --git a/gramps/gen/db/test/__init__.py b/gramps/gen/db/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/gen/db/test/db_test.py b/gramps/gen/db/test/db_test.py index d72224539..fac9fc727 100644 --- a/gramps/gen/db/test/db_test.py +++ b/gramps/gen/db/test/db_test.py @@ -18,17 +18,15 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# gen/db/test/db_test.py # $Id$ -from __future__ import print_function +import unittest -from ..db import (DbReadBase, DbWriteBase, - DbBsddbRead, DbBsddb) +from .. import DbReadBase, DbWriteBase, DbBsddbRead, DbBsddb from ...proxy.proxybase import ProxyDbBase from ...proxy import LivingProxyDb -class DbTest(object): +class DbTest(unittest.TestCase): READ_METHODS = [ "all_handles", "close", @@ -182,7 +180,6 @@ class DbTest(object): "set_researcher", "set_save_path", "set_undo_callback", - "version_supported", ] @@ -236,49 +233,48 @@ class DbTest(object): "write_version", ] - def __init__(self, db): - self.db = db - - def _verify_readonly(self): - print("Verifying readonly", self.db.__class__.__name__) + def _verify_readonly(self, db): for method in self.READ_METHODS: - assert hasattr(self.db, method), \ - ("readonly should have a '%s' method" % method) + self.assertTrue(hasattr(db, method), + ("readonly should have a '%s' method" % method)) for method in self.WRITE_METHODS: - assert not hasattr(self.db, method), \ - ("readonly should NOT have a '%s' method" % method) - print("passed!") + self.assertFalse(hasattr(db, method), + ("readonly should NOT have a '%s' method" % method)) - def _verify_readwrite(self): - print("Verifying readwrite", self.db.__class__.__name__) + def _verify_readwrite(self, db): for method in self.READ_METHODS: - assert hasattr(self.db, method), \ - ("readwrite should have a '%s' method" % method) + self.assertTrue(hasattr(db, method), + ("readwrite should have a '%s' method" % method)) for method in self.WRITE_METHODS: - assert hasattr(self.db, method), \ - ("readwrite should have a '%s' method" % method) - print("passed!") + self.assertTrue(hasattr(db, method), + ("readwrite should have a '%s' method" % method)) -db1 = DbTest(DbReadBase()) -db1._verify_readonly() + def test_verify_readbase(self): + db = DbReadBase() + self._verify_readonly(db) -db2 = DbTest(DbWriteBase()) -db2._verify_readwrite() + def test_verify_writebase(self): + db = DbWriteBase() + self._verify_readwrite(db) -from .. import DbBsddbRead -db3 = DbTest(DbBsddbRead()) -db3._verify_readonly() + def test_verify_read(self): + db = DbBsddbRead() + self._verify_readonly(db) -from .. import DbBsddb -db4 = DbTest(DbBsddb()) -db4._verify_readwrite() + def test_verify_write(self): + db = DbBsddb() + self._verify_readwrite(db) -from ...proxy.proxybase import ProxyDbBase -gdb = DbBsddb() -db5 = DbTest(ProxyDbBase(gdb)) -db5._verify_readonly() + def test_verify_proxy(self): + gdb = DbBsddb() + db = ProxyDbBase(gdb) + self._verify_readonly(db) -from ...proxy import LivingProxyDb -gdb = DbBsddb() -db6 = DbTest(LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL)) -db6._verify_readonly() + def test_verify_living(self): + gdb = DbBsddb() + db = LivingProxyDb(gdb, LivingProxyDb.MODE_EXCLUDE_ALL) + self._verify_readonly(db) + + +if __name__ == "__main__": + unittest.main()