]>
Commit | Line | Data |
---|---|---|
1dc81514 AG |
1 | #! /usr/bin/python |
2 | # | |
3 | # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 2 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
18 | # USA. | |
19 | ||
20 | ||
21 | import os | |
22 | import time | |
23 | ||
24 | import pmtest | |
25 | ||
26 | ||
27 | class pmenv: | |
28 | """Environment object | |
29 | """ | |
30 | ||
31 | def __init__(self, root = "root"): | |
32 | self.root = os.path.abspath(root) | |
33 | self.pacman = { | |
34 | "bin": "pacman", | |
35 | "debug": 0, | |
36 | "gdb": 0, | |
37 | "valgrind": 0, | |
38 | "nolog": 0 | |
39 | } | |
40 | self.testcases = [] | |
41 | ||
42 | def __str__(self): | |
43 | return "root = %s\n" \ | |
44 | "pacman = %s" \ | |
45 | % (self.root, self.pacman) | |
46 | ||
47 | def addtest(self, testcase): | |
48 | """ | |
49 | """ | |
50 | if not os.path.isfile(testcase): | |
51 | err("file %s not found" % testcase) | |
52 | return | |
53 | test = pmtest.pmtest(testcase, self.root) | |
54 | self.testcases.append(test) | |
55 | ||
56 | def run(self): | |
57 | """ | |
58 | """ | |
59 | ||
60 | for t in self.testcases: | |
61 | print "=========="*8 | |
62 | print "Running '%s'" % t.name.strip(".py") | |
63 | ||
64 | t.load() | |
65 | print t.description | |
66 | print "----------"*8 | |
67 | ||
68 | t.generate() | |
69 | # Hack for mtimes consistency | |
70 | modified = 0 | |
71 | for i in t.rules: | |
72 | if i.rule.find("MODIFIED") != -1: | |
73 | modified = 1 | |
74 | if modified: | |
75 | time.sleep(3) | |
76 | ||
77 | t.run(self.pacman) | |
78 | ||
79 | t.check() | |
80 | print "==> Test result" | |
81 | if t.result["ko"] == 0: | |
82 | print "\tPASSED" | |
83 | else: | |
84 | print "\tFAILED" | |
85 | ||
86 | ||
87 | def results(self): | |
88 | """ | |
89 | """ | |
90 | passed = 0 | |
91 | print "=========="*8 | |
92 | print "Results" | |
93 | print "----------"*8 | |
94 | for test in self.testcases: | |
95 | ok = test.result["ok"] | |
96 | ko = test.result["ko"] | |
97 | rules = len(test.rules) | |
98 | if ko == 0: | |
99 | print "[PASSED]", | |
100 | passed += 1 | |
101 | else: | |
102 | print "[FAILED]", | |
103 | print test.name.strip(".py").ljust(38), | |
104 | print "Rules:", | |
105 | print "OK = %2u KO = %2u SKIP = %2u" % (ok, ko, rules-(ok+ko)) | |
106 | print "----------"*8 | |
107 | total = len(self.testcases) | |
108 | failed = total - passed | |
109 | print "TOTAL = %3u" % total | |
110 | if total: | |
111 | print "PASSED = %3u (%6.2f%%)" % (passed, float(passed)*100/total) | |
112 | print "FAILED = %3u (%6.2f%%)" % (failed, float(failed)*100/total) | |
113 | ||
114 | ||
115 | ||
116 | if __name__ == "__main__": | |
117 | env = pmenv("/tmp") | |
118 | print env |