Changes to allow GrampsDb tests to run

svn: r13893
This commit is contained in:
Doug Blank 2009-12-23 15:48:01 +00:00
parent eb23cfd76f
commit 0f20544be3
3 changed files with 30 additions and 51 deletions

View File

@ -94,6 +94,7 @@ class CLIDbManager(object):
self.active = None self.active = None
self.current_names = [] self.current_names = []
if dbstate:
self._populate_cli() self._populate_cli()
def empty(self, val): def empty(self, val):
@ -234,7 +235,7 @@ class CLIDbManager(object):
name_file.close() name_file.close()
# write the version number into metadata # write the version number into metadata
newdb = gen.db.GrampsDBDir() newdb = gen.db.DbBsddb()
newdb.write_version(new_path) newdb.write_version(new_path)
(tval, last) = time_val(new_path) (tval, last) = time_val(new_path)
@ -269,7 +270,7 @@ class CLIDbManager(object):
# Create a new database # Create a new database
self.__start_cursor(_("Importing data...")) self.__start_cursor(_("Importing data..."))
dbclass = gen.db.GrampsDBDir dbclass = gen.db.DbBsddb
dbase = dbclass() dbase = dbclass()
dbase.load(new_path, callback) dbase.load(new_path, callback)

View File

@ -15,34 +15,11 @@ except NameError:
from sets import Set as set from sets import Set as set
import const import const
import RelLib import gen.lib
logger = logging.getLogger('Gramps.GrampsDbBase_Test') logger = logging.getLogger('Gramps.GrampsDbBase_Test')
from GrampsDbTestBase import GrampsDbBaseTest from GrampsDbTestBase import GrampsDbBaseTest
import GrampsDb
class FactoryTest(unittest.TestCase):
"""Test the GrampsDb Factory classes."""
def test_gramps_db_factory(self):
"""test than gramps_db_factory returns the correct classes."""
cls = GrampsDb.gramps_db_factory(db_type = const.app_gramps)
assert cls.__name__ == "GrampsBSDDB", \
"Returned class is %s " % str(cls.__class__.__name__)
cls = GrampsDb.gramps_db_factory(db_type = const.app_gramps_xml)
assert cls.__name__ == "GrampsXMLDB", \
"Returned class is %s " % str(cls.__class__.__name__)
cls = GrampsDb.gramps_db_factory(db_type = const.app_gedcom)
assert cls.__name__ == "GrampsGEDDB", \
"Returned class is %s " % str(cls.__class__.__name__)
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_factory, "gibberish")
class ReferenceMapTest (GrampsDbBaseTest): class ReferenceMapTest (GrampsDbBaseTest):
"""Test methods on the GrampsDbBase class that are related to the reference_map """Test methods on the GrampsDbBase class that are related to the reference_map
@ -59,7 +36,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
assert len(references) == 1 assert len(references) == 1
assert references[0] == (RelLib.Person.__name__,person.get_handle()) assert references[0] == (gen.lib.Person.__name__,person.get_handle())
def test_backlink_for_repository(self): def test_backlink_for_repository(self):
"""check that the source / repos backlink lookup works.""" """check that the source / repos backlink lookup works."""
@ -70,7 +47,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
references = [ ref for ref in self._db.find_backlink_handles(repos.get_handle()) ] references = [ ref for ref in self._db.find_backlink_handles(repos.get_handle()) ]
assert len(references) == 1 assert len(references) == 1
assert references[0] == (RelLib.Source.__name__,source.get_handle()) assert references[0] == (gen.lib.Source.__name__,source.get_handle())
def test_class_limited_lookup(self): def test_class_limited_lookup(self):
"""check that class limited lookups work.""" """check that class limited lookups work."""
@ -89,16 +66,16 @@ class ReferenceMapTest (GrampsDbBaseTest):
assert len(references) == 5, "len(references) == %s " % str(len(references)) assert len(references) == 5, "len(references) == %s " % str(len(references))
# should just return the person reference # should just return the person reference
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(RelLib.Person.__name__,)) ] references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(gen.lib.Person.__name__,)) ]
assert len(references) == 1, "len(references) == %s " % str(len(references)) assert len(references) == 1, "len(references) == %s " % str(len(references))
assert references[0][0] == RelLib.Person.__name__, "references = %s" % repr(references) assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
# should just return the person and event reference # should just return the person and event reference
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(RelLib.Person.__name__, references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(gen.lib.Person.__name__,
RelLib.Event.__name__)) ] gen.lib.Event.__name__)) ]
assert len(references) == 2, "len(references) == %s " % str(len(references)) assert len(references) == 2, "len(references) == %s " % str(len(references))
assert references[0][0] == RelLib.Person.__name__, "references = %s" % repr(references) assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
assert references[1][0] == RelLib.Event.__name__, "references = %s" % repr(references) assert references[1][0] == gen.lib.Event.__name__, "references = %s" % repr(references)
@ -130,7 +107,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
# unhook the reference_map update function so that we # unhook the reference_map update function so that we
# can insert some records without the reference_map being updated. # can insert some records without the reference_map being updated.
update_method = self._db._update_reference_map update_method = self._db.update_reference_map
self._db._update_reference_map = lambda x,y: 1 self._db._update_reference_map = lambda x,y: 1
# Insert a person/source pair. # Insert a person/source pair.
@ -216,7 +193,6 @@ class ReferenceMapTest (GrampsDbBaseTest):
def testSuite(): def testSuite():
suite = unittest.makeSuite(ReferenceMapTest,'test') suite = unittest.makeSuite(ReferenceMapTest,'test')
suite.addTests(unittest.makeSuite(FactoryTest,'test'))
return suite return suite
def perfSuite(): def perfSuite():

View File

@ -14,9 +14,10 @@ try:
except NameError: except NameError:
from sets import Set as set from sets import Set as set
import GrampsDb from gen.db import DbBsddb
from cli.clidbman import CLIDbManager
import const import const
import RelLib import gen.lib
logger = logging.getLogger('Gramps.GrampsDbTestBase') logger = logging.getLogger('Gramps.GrampsDbTestBase')
@ -28,12 +29,13 @@ class GrampsDbBaseTest(unittest.TestCase):
def dummy_callback(dummy): def dummy_callback(dummy):
pass pass
self._tmpdir = tempfile.mkdtemp() self._tmpdir = tempfile.mkdtemp()
self._filename = os.path.join(self._tmpdir,'test.grdb') #self._filename = os.path.join(self._tmpdir,'test.grdb')
self._db = GrampsDb.gramps_db_factory(const.app_gramps)() self._db = DbBsddb()
dbman = CLIDbManager(None)
self._filename, title = dbman.create_new_db_cli(title="Test")
self._db.load(self._filename, dummy_callback, "w") self._db.load(self._filename, dummy_callback, "w")
def tearDown(self): def tearDown(self):
self._db.close() self._db.close()
shutil.rmtree(self._tmpdir) shutil.rmtree(self._tmpdir)
@ -84,9 +86,9 @@ class GrampsDbBaseTest(unittest.TestCase):
# Add a Source # Add a Source
tran = self._db.transaction_begin() tran = self._db.transaction_begin()
source = RelLib.Source() source = gen.lib.Source()
if repos is not None: if repos is not None:
repo_ref = RelLib.RepoRef() repo_ref = gen.lib.RepoRef()
repo_ref.set_reference_handle(repos.get_handle()) repo_ref.set_reference_handle(repos.get_handle())
source.add_repo_reference(repo_ref) source.add_repo_reference(repo_ref)
self._db.add_source(source,tran) self._db.add_source(source,tran)
@ -99,7 +101,7 @@ class GrampsDbBaseTest(unittest.TestCase):
# Add a Repository # Add a Repository
tran = self._db.transaction_begin() tran = self._db.transaction_begin()
repos = RelLib.Repository() repos = gen.lib.Repository()
self._db.add_repository(repos,tran) self._db.add_repository(repos,tran)
self._db.commit_repository(repos,tran) self._db.commit_repository(repos,tran)
self._db.transaction_commit(tran, "Add Repository") self._db.transaction_commit(tran, "Add Repository")
@ -112,7 +114,7 @@ class GrampsDbBaseTest(unittest.TestCase):
object = object_class() object = object_class()
for source in sources: for source in sources:
src_ref = RelLib.SourceRef() src_ref = gen.lib.SourceRef()
src_ref.set_reference_handle(source.get_handle()) src_ref.set_reference_handle(source.get_handle())
object.add_source_reference(src_ref) object.add_source_reference(src_ref)
@ -127,34 +129,34 @@ class GrampsDbBaseTest(unittest.TestCase):
def _add_person_with_sources(self,sources): def _add_person_with_sources(self,sources):
return self._add_object_with_source(sources, return self._add_object_with_source(sources,
RelLib.Person, gen.lib.Person,
self._db.add_person, self._db.add_person,
self._db.commit_person) self._db.commit_person)
def _add_family_with_sources(self,sources): def _add_family_with_sources(self,sources):
return self._add_object_with_source(sources, return self._add_object_with_source(sources,
RelLib.Family, gen.lib.Family,
self._db.add_family, self._db.add_family,
self._db.commit_family) self._db.commit_family)
def _add_event_with_sources(self,sources): def _add_event_with_sources(self,sources):
return self._add_object_with_source(sources, return self._add_object_with_source(sources,
RelLib.Event, gen.lib.Event,
self._db.add_event, self._db.add_event,
self._db.commit_event) self._db.commit_event)
def _add_place_with_sources(self,sources): def _add_place_with_sources(self,sources):
return self._add_object_with_source(sources, return self._add_object_with_source(sources,
RelLib.Place, gen.lib.Place,
self._db.add_place, self._db.add_place,
self._db.commit_place) self._db.commit_place)
def _add_media_object_with_sources(self,sources): def _add_media_object_with_sources(self,sources):
return self._add_object_with_source(sources, return self._add_object_with_source(sources,
RelLib.MediaObject, gen.lib.MediaObject,
self._db.add_object, self._db.add_object,
self._db.commit_media_object) self._db.commit_media_object)