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
This commit is contained in:
Worros 2010-08-19 18:25:26 +08:00
parent 924e155b45
commit 0fab203a53

View File

@ -102,6 +102,7 @@ class Importer:
self.settings.setdefault("dropIndexes", "don't drop") self.settings.setdefault("dropIndexes", "don't drop")
self.settings.setdefault("dropHudCache", "don't drop") self.settings.setdefault("dropHudCache", "don't drop")
self.settings.setdefault("starsArchive", False) self.settings.setdefault("starsArchive", False)
self.settings.setdefault("testData", False)
self.writeq = None self.writeq = None
self.database = Database.Database(self.config, sql = self.sql) self.database = Database.Database(self.config, sql = self.sql)
@ -146,6 +147,15 @@ class Importer:
def setStarsArchive(self, value): def setStarsArchive(self, value):
self.settings['starsArchive'] = 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): # def setWatchTime(self):
# self.updated = time() # self.updated = time()
@ -456,7 +466,7 @@ class Importer:
if hand is not None: if hand is not None:
hand.prepInsert(self.database) hand.prepInsert(self.database)
try: try:
hand.insert(self.database) hand.insert(self.database, printtest = self.settings['testData'])
except Exceptions.FpdbHandDuplicate: except Exceptions.FpdbHandDuplicate:
duplicates += 1 duplicates += 1
else: else:
@ -485,6 +495,10 @@ class Importer:
stored = getattr(hhc, 'numHands') stored = getattr(hhc, 'numHands')
stored -= duplicates stored -= duplicates
stored -= errors 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: else:
# conversion didn't work # conversion didn't work
# TODO: appropriate response? # TODO: appropriate response?