From 0fab203a535b497c709f15b748bad9ccc5ab9965 Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 19 Aug 2010 18:25:26 +0800 Subject: [PATCH] Importer: Add utility functions for regression testing setPrintTestData: Indicate you would like to print test data when importing setFakeCacheHHC: Indicate you want to access the HHC after an import run getCachedHHC: Retrieve HHC Also modified the main import loop to pass self.settings['testData'] to the database insert and records the HHC if requested --- pyfpdb/fpdb_import.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 03fbbe48..a1835830 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -102,6 +102,7 @@ class Importer: self.settings.setdefault("dropIndexes", "don't drop") self.settings.setdefault("dropHudCache", "don't drop") self.settings.setdefault("starsArchive", False) + self.settings.setdefault("testData", False) self.writeq = None self.database = Database.Database(self.config, sql = self.sql) @@ -146,6 +147,15 @@ class Importer: def setStarsArchive(self, value): self.settings['starsArchive'] = value + def setPrintTestData(self, value): + self.settings['testData'] = value + + def setFakeCacheHHC(self, value): + self.settings['cacheHHC'] = value + + def getCachedHHC(self): + return self.handhistoryconverter + # def setWatchTime(self): # self.updated = time() @@ -456,7 +466,7 @@ class Importer: if hand is not None: hand.prepInsert(self.database) try: - hand.insert(self.database) + hand.insert(self.database, printtest = self.settings['testData']) except Exceptions.FpdbHandDuplicate: duplicates += 1 else: @@ -485,6 +495,10 @@ class Importer: stored = getattr(hhc, 'numHands') stored -= duplicates stored -= errors + # Really ugly hack to allow testing Hands within the HHC from someone + # with only an Importer objec + if self.settings['cacheHHC']: + self.handhistoryconverter = hhc else: # conversion didn't work # TODO: appropriate response?