]>
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 | |
9781d0d6 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1dc81514 AG |
17 | |
18 | ||
19 | import os | |
25223d67 | 20 | import os.path |
1dc81514 AG |
21 | |
22 | import pmtest | |
23 | ||
24 | ||
25 | class pmenv: | |
786cd38c AG |
26 | """Environment object |
27 | """ | |
28 | ||
cf25884e DM |
29 | testcases = [] |
30 | passed = 0 | |
31 | failed = 0 | |
32 | expectedfail = 0 | |
33 | unexpectedpass = 0 | |
34 | ||
786cd38c AG |
35 | def __init__(self, root = "root"): |
36 | self.root = os.path.abspath(root) | |
37 | self.pacman = { | |
38 | "bin": "pacman", | |
39 | "debug": 0, | |
40 | "gdb": 0, | |
41 | "valgrind": 0, | |
42 | "nolog": 0 | |
43 | } | |
786cd38c AG |
44 | |
45 | def __str__(self): | |
46 | return "root = %s\n" \ | |
47 | "pacman = %s" \ | |
48 | % (self.root, self.pacman) | |
49 | ||
50 | def addtest(self, testcase): | |
51 | """ | |
52 | """ | |
53 | if not os.path.isfile(testcase): | |
cf25884e | 54 | raise IOError("test file %s not found" % testcase) |
786cd38c AG |
55 | test = pmtest.pmtest(testcase, self.root) |
56 | self.testcases.append(test) | |
57 | ||
58 | def run(self): | |
59 | """ | |
60 | """ | |
61 | ||
62 | for t in self.testcases: | |
63 | print "=========="*8 | |
25223d67 | 64 | print "Running '%s'" % t.testname |
786cd38c AG |
65 | |
66 | t.load() | |
67 | print t.description | |
68 | print "----------"*8 | |
69 | ||
70 | t.generate() | |
786cd38c AG |
71 | |
72 | t.run(self.pacman) | |
73 | ||
74 | t.check() | |
75 | print "==> Test result" | |
76 | if t.result["fail"] == 0: | |
efca1cc0 | 77 | print "\tPASS" |
786cd38c | 78 | else: |
efca1cc0 | 79 | print "\tFAIL" |
786cd38c AG |
80 | |
81 | ||
82 | def results(self): | |
83 | """ | |
84 | """ | |
25223d67 AG |
85 | tpassed = [] |
86 | tfailed = [] | |
9f579214 | 87 | texpectedfail = [] |
9f579214 | 88 | tunexpectedpass = [] |
786cd38c | 89 | for test in self.testcases: |
25223d67 | 90 | fail = test.result["fail"] |
9f579214 | 91 | if fail == 0 and not test.expectfailure: |
cf25884e | 92 | self.passed += 1 |
25223d67 | 93 | tpassed.append(test) |
9f579214 | 94 | elif fail != 0 and test.expectfailure: |
cf25884e | 95 | self.expectedfail += 1 |
9f579214 DM |
96 | texpectedfail.append(test) |
97 | elif fail == 0: # and not test.expectfail | |
cf25884e | 98 | self.unexpectedpass += 1 |
9f579214 | 99 | tunexpectedpass.append(test) |
25223d67 | 100 | else: |
cf25884e | 101 | self.failed += 1 |
25223d67 AG |
102 | tfailed.append(test) |
103 | ||
104 | def _printtest(t): | |
786cd38c AG |
105 | success = test.result["success"] |
106 | fail = test.result["fail"] | |
107 | rules = len(test.rules) | |
108 | if fail == 0: | |
efca1cc0 | 109 | result = "[PASS]" |
786cd38c | 110 | else: |
efca1cc0 | 111 | result = "[FAIL]" |
13e21110 | 112 | print result, |
7ee5a4e7 | 113 | print "%s Rules: OK = %2u FAIL = %2u SKIP = %2u" \ |
efca1cc0 | 114 | % (test.testname.ljust(34), success, fail, \ |
13e21110 DM |
115 | rules - (success + fail)) |
116 | if fail != 0: | |
117 | # print test description if test failed | |
efca1cc0 | 118 | print " ", test.description |
25223d67 AG |
119 | |
120 | print "=========="*8 | |
121 | print "Results" | |
786cd38c | 122 | print "----------"*8 |
9f579214 | 123 | print " Passed:" |
25223d67 AG |
124 | for test in tpassed: _printtest(test) |
125 | print "----------"*8 | |
9f579214 DM |
126 | print " Expected Failures:" |
127 | for test in texpectedfail: _printtest(test) | |
128 | print "----------"*8 | |
129 | print " Unexpected Passes:" | |
130 | for test in tunexpectedpass: _printtest(test) | |
131 | print "----------"*8 | |
132 | print " Failed:" | |
25223d67 AG |
133 | for test in tfailed: _printtest(test) |
134 | print "----------"*8 | |
135 | ||
786cd38c | 136 | total = len(self.testcases) |
9f579214 | 137 | print "Total = %3u" % total |
786cd38c | 138 | if total: |
cf25884e DM |
139 | print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total) |
140 | print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total) | |
141 | print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total) | |
142 | print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total) | |
25223d67 | 143 | print "" |
1dc81514 AG |
144 | |
145 | if __name__ == "__main__": | |
cf25884e DM |
146 | pass |
147 | ||
786cd38c | 148 | # vim: set ts=4 sw=4 et: |