From fff5c3e5951735ff64202e37a92850939c043d08 Mon Sep 17 00:00:00 2001 From: Richard Taylor Date: Sat, 17 Dec 2005 21:13:45 +0000 Subject: [PATCH] * src/GrampsDbBase.py: fixed UNDO buffer issue * test/GrampsDbBase_Test.py: improved performance test * test/RunAllTests.py: added -p cmdline flag svn: r5571 --- ChangeLog | 5 ++++ src/GrampsDbBase.py | 6 ++-- test/GrampsDbBase_Test.py | 59 +++++++++++++++++++++++++++++++-------- test/RunAllTests.py | 22 ++++++++++++--- 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 656e4221b..a98a5f652 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-12-17 Richard Taylor + * src/GrampsDbBase.py: fixed UNDO buffer issue + * test/GrampsDbBase_Test.py: improved performance test + * test/RunAllTests.py: added -p cmdline flag + 2005-12-17 Richard Taylor * src/GrampsBSDDB.py: added work around for cursor set not returing None. diff --git a/src/GrampsDbBase.py b/src/GrampsDbBase.py index a57e3bf55..76ff96b73 100644 --- a/src/GrampsDbBase.py +++ b/src/GrampsDbBase.py @@ -1026,9 +1026,9 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): if not len(transaction) or self.readonly: return transaction.set_description(msg) - self.undoindex += 1 - if self.undoindex == _UNDO_SIZE: - self.translist = transaction[0:-1] + [ transaction ] + self.undoindex += 1 + if self.undoindex >= _UNDO_SIZE: + self.translist = self.translist[0:-1] + [ transaction ] else: self.translist[self.undoindex] = transaction diff --git a/test/GrampsDbBase_Test.py b/test/GrampsDbBase_Test.py index 8b0c78128..4dd50e4f6 100644 --- a/test/GrampsDbBase_Test.py +++ b/test/GrampsDbBase_Test.py @@ -4,10 +4,16 @@ import os import tempfile import shutil import time - +import traceback import sys + sys.path.append('../src') +try: + set() +except NameError: + from set import Set as set + import GrampsBSDDB import RelLib @@ -24,6 +30,7 @@ class ReferenceMapTest (unittest.TestCase): None, # callback "w") + def tearDown(self): shutil.rmtree(self._tmpdir) @@ -60,7 +67,12 @@ class ReferenceMapTest (unittest.TestCase): lnk_sources.add(sources[source_idx-1]) source_idx = (source_idx+1) % len(sources) - add_func(lnk_sources) + try: + add_func(lnk_sources) + except: + print "person_idx = ", person_idx + print "lnk_sources = ", repr(lnk_sources) + raise return @@ -199,15 +211,23 @@ class ReferenceMapTest (unittest.TestCase): return end - start - def test_performance(self): + def perf_simple_search_speed(self): + + num_sources = 100 + num_persons = 1000 + num_families = 10 + num_events = 10 + num_places = 10 + num_media_objects = 10 + num_links = 10 - self._populate_database(num_sources = 100, - num_persons = 80, - num_families = 10, - num_events = 10, - num_places = 10, - num_media_objects = 10, - num_links = 10) + self._populate_database(num_sources, + num_persons, + num_families, + num_events, + num_places, + num_media_objects, + num_links) # time searching for source backrefs with and without reference_map @@ -232,7 +252,21 @@ class ReferenceMapTest (unittest.TestCase): without_reference_map = end - start self._db.__class__.find_backlink_handles = remember - + + logger.info("search test with following data: \n" + "num_sources = %d \n" + "num_persons = %d \n" + "num_families = %d \n" + "num_events = %d \n" + "num_places = %d \n" + "num_media_objects = %d \n" + "num_links = %d" % (num_sources, + num_persons, + num_families, + num_events, + num_places, + num_media_objects, + num_links)) logger.info("with refs %s\n", str(with_reference_map)) logger.info("without refs %s\n", str(without_reference_map)) @@ -241,5 +275,8 @@ class ReferenceMapTest (unittest.TestCase): def testSuite(): return unittest.makeSuite(ReferenceMapTest,'test') +def perfSuite(): + return unittest.makeSuite(ReferenceMapTest,'perf') + if __name__ == '__main__': unittest.TextTestRunner().run(testSuite()) diff --git a/test/RunAllTests.py b/test/RunAllTests.py index 3ae70a94e..a6c061666 100644 --- a/test/RunAllTests.py +++ b/test/RunAllTests.py @@ -13,6 +13,8 @@ def make_parser(): parser = OptionParser(usage) parser.add_option("-v", "--verbosity", type="int", dest="verbose_level", default=0, help="Level of verboseness") + parser.add_option("-p", "--performance", action="store_true", dest="performance", default=False, + help="Run the performance tests.") return parser @@ -21,15 +23,23 @@ def getTestSuites(): test_modules = [ i for i in os.listdir('.') 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 - return test_suites + return (test_suites,perf_suites) def allTheTests(): - return unittest.TestSuite(getTestSuites()) + return unittest.TestSuite(getTestSuites()[0]) +def perfTests(): + return unittest.TestSuite(getTestSuites()[1]) + if __name__ == '__main__': console = logging.StreamHandler() @@ -57,5 +67,9 @@ if __name__ == '__main__': else: logger.setLevel(logging.ERROR) console.setLevel(logging.ERROR) - - unittest.TextTestRunner(verbosity=options.verbose_level).run(allTheTests()) + + + if options.performance: + unittest.TextTestRunner(verbosity=options.verbose_level).run(perfTests()) + else: + unittest.TextTestRunner(verbosity=options.verbose_level).run(allTheTests())