* Updated Italian translation
[pacman.git] / pactest / pmenv.py
blobbff32e98d000c12682826585d22de4602ab4e5c0
1 #! /usr/bin/python
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.
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.
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.
21 import os
22 import os.path
23 import time
25 import pmtest
28 class pmenv:
29 """Environment object
30 """
32 def __init__(self, root = "root"):
33 self.root = os.path.abspath(root)
34 self.pacman = {
35 "bin": "pacman",
36 "debug": 0,
37 "gdb": 0,
38 "valgrind": 0,
39 "nolog": 0
41 self.testcases = []
43 def __str__(self):
44 return "root = %s\n" \
45 "pacman = %s" \
46 % (self.root, self.pacman)
48 def addtest(self, testcase):
49 """
50 """
51 if not os.path.isfile(testcase):
52 err("file %s not found" % testcase)
53 return
54 test = pmtest.pmtest(testcase, self.root)
55 self.testcases.append(test)
57 def run(self):
58 """
59 """
61 for t in self.testcases:
62 print "=========="*8
63 print "Running '%s'" % t.testname
65 t.load()
66 print t.description
67 print "----------"*8
69 t.generate()
70 # Hack for mtimes consistency
71 modified = 0
72 for i in t.rules:
73 if i.rule.find("MODIFIED") != -1:
74 modified = 1
75 if modified:
76 time.sleep(3)
78 t.run(self.pacman)
80 t.check()
81 print "==> Test result"
82 if t.result["fail"] == 0:
83 print "\tPASS"
84 else:
85 print "\tFAIL"
86 print
88 def results(self):
89 """
90 """
91 passed = 0
92 tpassed = []
93 tfailed = []
94 for test in self.testcases:
95 fail = test.result["fail"]
96 if fail == 0:
97 passed += 1
98 tpassed.append(test)
99 else:
100 tfailed.append(test)
102 def _printtest(t):
103 success = test.result["success"]
104 fail = test.result["fail"]
105 rules = len(test.rules)
106 if fail == 0:
107 result = "[PASS]"
108 else:
109 result = "[FAIL]"
110 print result,
111 print "%s Rules: OK = %2u FAIL = %2u SKIP = %2u" \
112 % (test.testname.ljust(34), success, fail, \
113 rules - (success + fail))
114 if fail != 0:
115 # print test description if test failed
116 print " ", test.description
118 print "=========="*8
119 print "Results"
120 print "----------"*8
121 for test in tpassed: _printtest(test)
122 print "----------"*8
123 for test in tfailed: _printtest(test)
124 print "----------"*8
126 total = len(self.testcases)
127 failed = total - passed
128 print "TOTAL = %3u" % total
129 if total:
130 print "PASS = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total)
131 print "FAIL = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total)
132 print ""
134 if __name__ == "__main__":
135 env = pmenv("/tmp")
136 print env
137 # vim: set ts=4 sw=4 et: