move database code into new package
svn: r5598
This commit is contained in:
@ -13,14 +13,64 @@ try:
|
||||
set()
|
||||
except NameError:
|
||||
from sets import Set as set
|
||||
|
||||
import GrampsBSDDB
|
||||
|
||||
import const
|
||||
import RelLib
|
||||
|
||||
logger = logging.getLogger('Gramps.GrampsDbBase_Test')
|
||||
|
||||
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")
|
||||
|
||||
def test_gramps_db_writer_factory(self):
|
||||
"""Test that gramps_db_writer_factory returns the correct method."""
|
||||
|
||||
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gramps)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gramps_xml)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
md = GrampsDb.gramps_db_writer_factory(db_type = const.app_gedcom)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_writer_factory, "gibberish")
|
||||
|
||||
def test_gramps_db_reader_factory(self):
|
||||
"""Test that gramps_db_reader_factory returns the correct method."""
|
||||
|
||||
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gramps_xml)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
md = GrampsDb.gramps_db_reader_factory(db_type = const.app_gedcom)
|
||||
assert callable(md), "Returned method is %s " % str(md)
|
||||
|
||||
self.assertRaises(GrampsDb.GrampsDbException, GrampsDb.gramps_db_reader_factory, "gibberish")
|
||||
|
||||
|
||||
|
||||
class ReferenceMapTest (GrampsDbBaseTest):
|
||||
"""Test methods on the GrampsDbBase class that are related to the reference_map
|
||||
@ -180,6 +230,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
|
||||
|
||||
def testSuite():
|
||||
suite = unittest.makeSuite(ReferenceMapTest,'test')
|
||||
suite.addTests(unittest.makeSuite(FactoryTest,'test'))
|
||||
return suite
|
||||
|
||||
def perfSuite():
|
@ -14,7 +14,8 @@ try:
|
||||
except NameError:
|
||||
from sets import Set as set
|
||||
|
||||
import GrampsBSDDB
|
||||
import GrampsDb
|
||||
import const
|
||||
import RelLib
|
||||
|
||||
logger = logging.getLogger('Gramps.GrampsDbTestBase')
|
||||
@ -27,7 +28,7 @@ class GrampsDbBaseTest(unittest.TestCase):
|
||||
self._tmpdir = tempfile.mkdtemp()
|
||||
self._filename = os.path.join(self._tmpdir,'test.grdb')
|
||||
|
||||
self._db = GrampsBSDDB.GrampsBSDDB()
|
||||
self._db = GrampsDb.gramps_db_factory(const.app_gramps)()
|
||||
self._db.load(self._filename,
|
||||
None, # callback
|
||||
"w")
|
@ -7,7 +7,6 @@ import time
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
sys.path.append('../src')
|
||||
|
||||
try:
|
||||
set()
|
||||
@ -19,9 +18,8 @@ import RelLib
|
||||
|
||||
logger = logging.getLogger('Gramps.RelLib_Test')
|
||||
|
||||
from GrampsDbTestBase import GrampsDbBaseTest
|
||||
|
||||
class PrimaryObjectTest (GrampsDbBaseTest):
|
||||
class PrimaryObjectTest (unittest.TestCase):
|
||||
"""Test methods on the PrimaryObject class"""
|
||||
|
||||
|
@ -5,9 +5,12 @@
|
||||
import logging
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from optparse import OptionParser
|
||||
|
||||
sys.path.append('../src')
|
||||
|
||||
def make_parser():
|
||||
usage = "usage: %prog [options]"
|
||||
parser = OptionParser(usage)
|
||||
@ -19,18 +22,29 @@ def make_parser():
|
||||
|
||||
|
||||
def getTestSuites():
|
||||
# Sorry about this line, but it is the easiest way of doing it.
|
||||
# It just walks the filetree from '.' downwards and returns
|
||||
# a tuple per directory of (dirpatch,filelist) if the directory
|
||||
# contains any test files.
|
||||
|
||||
test_modules = [ i for i in os.listdir('.') if i[-8:] == "_Test.py" ]
|
||||
paths = [(f[0],f[2]) for f in os.walk('.') \
|
||||
if len ([i for i in f[2] \
|
||||
if i[-8:] == "_Test.py"]) ]
|
||||
|
||||
test_suites = []
|
||||
perf_suites = []
|
||||
for module in test_modules:
|
||||
mod = __import__(module[:-3])
|
||||
test_suites.append(mod.testSuite())
|
||||
try:
|
||||
perf_suites.append(mod.perfSuite())
|
||||
except:
|
||||
pass
|
||||
for (dir,test_modules) in paths:
|
||||
sys.path.append(dir)
|
||||
|
||||
test_suites = []
|
||||
perf_suites = []
|
||||
for module in test_modules:
|
||||
if module[-8:] != "_Test.py":
|
||||
break
|
||||
mod = __import__(module[:-3])
|
||||
test_suites.append(mod.testSuite())
|
||||
try:
|
||||
perf_suites.append(mod.perfSuite())
|
||||
except:
|
||||
pass
|
||||
|
||||
return (test_suites,perf_suites)
|
||||
|
||||
|
Reference in New Issue
Block a user