|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 """Store the results. |
|
6 |
|
7 Use a db, but we could do better""" |
|
8 |
|
9 import shelve |
|
10 import string |
|
11 |
|
12 class results: |
|
13 def __init__(self, id): |
|
14 self.id = id |
|
15 self.d = shelve.open("data/"+id+".db") |
|
16 |
|
17 def get_tester(self, path): |
|
18 import BaseTest |
|
19 |
|
20 try: |
|
21 fname = path+"tester.py" |
|
22 text = open(fname).read() |
|
23 # Thanks to markh, for showing me how to do this |
|
24 # Python Is Cool. |
|
25 codeob = compile(text, fname, "exec") |
|
26 namespace = { 'BaseTester': BaseTest.tester } |
|
27 exec codeob in namespace, namespace |
|
28 tester = namespace['tester']() |
|
29 except IOError: |
|
30 tester = BaseTest.tester() |
|
31 |
|
32 if self.d.has_key(path): |
|
33 tester.__dict__ = self.d[path] |
|
34 else: |
|
35 tester.parse_config(open(path+"config")) |
|
36 |
|
37 return tester |
|
38 |
|
39 def set_tester(self, path, test): |
|
40 self.d[path] = test.__dict__ |
|
41 |
|
42 def write_report(self, file): |
|
43 for i in self.d.keys(): |
|
44 file.write("%s: " % (i)) |
|
45 tester = self.get_tester(i) |
|
46 res, detail = tester.result() |
|
47 if res: |
|
48 file.write("Pass!\n") |
|
49 else: |
|
50 file.write("Fail: %s\n" % (detail)) |
|
51 |
|
52 def __del__(self): |
|
53 self.d.close() |