michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: """Store the results. michael@0: michael@0: Use a db, but we could do better""" michael@0: michael@0: import shelve michael@0: import string michael@0: michael@0: class results: michael@0: def __init__(self, id): michael@0: self.id = id michael@0: self.d = shelve.open("data/"+id+".db") michael@0: michael@0: def get_tester(self, path): michael@0: import BaseTest michael@0: michael@0: try: michael@0: fname = path+"tester.py" michael@0: text = open(fname).read() michael@0: # Thanks to markh, for showing me how to do this michael@0: # Python Is Cool. michael@0: codeob = compile(text, fname, "exec") michael@0: namespace = { 'BaseTester': BaseTest.tester } michael@0: exec codeob in namespace, namespace michael@0: tester = namespace['tester']() michael@0: except IOError: michael@0: tester = BaseTest.tester() michael@0: michael@0: if self.d.has_key(path): michael@0: tester.__dict__ = self.d[path] michael@0: else: michael@0: tester.parse_config(open(path+"config")) michael@0: michael@0: return tester michael@0: michael@0: def set_tester(self, path, test): michael@0: self.d[path] = test.__dict__ michael@0: michael@0: def write_report(self, file): michael@0: for i in self.d.keys(): michael@0: file.write("%s: " % (i)) michael@0: tester = self.get_tester(i) michael@0: res, detail = tester.result() michael@0: if res: michael@0: file.write("Pass!\n") michael@0: else: michael@0: file.write("Fail: %s\n" % (detail)) michael@0: michael@0: def __del__(self): michael@0: self.d.close()