@@ -28,46 +28,62 @@ def white(s): return "\033[37;1m%s\033[0m"%(str(s))
2828}
2929
3030LINE = "%s\n " % (magenta ("=" * 80 ))
31- dmidecode = True in [os .path .exists (os .path .join (_ , "dmidecode" )) for _ in os .getenv ("PATH" ).split (':' )]
32- if dmidecode :
33- print "Please install `dmidecode' (the binary) for complete testing."
34-
35- FH , DUMP = tempfile .mkstemp ()
36- os .unlink (DUMP )
37- os .close (FH )
38-
39- total = 0
40- success = 0
41-
42- def passed ():
43- global total
44- global success
45- total += 1
46- success += 1
31+
32+ score = {
33+ "total" : 0 ,
34+ "skipped" : 0 ,
35+ "passed" : 0 ,
36+ "failed" : 0 ,
37+ }
38+
39+ def passed (msg = None , indent = 1 ):
40+ global score
41+ score ["total" ] += 1
42+ score ["passed" ] += 1
4743 sys .stdout .write ("%s\n " % green ("PASS" ))
48- def failed ():
49- global total
50- total += 1
44+ if msg : sys .stdout .write ("%s %s %s\n " % (" " * indent , green ("P" ), msg ))
45+ def skipped (msg = None , indent = 1 ):
46+ global score
47+ score ["total" ] += 1
48+ score ["skipped" ] += 1
49+ sys .stdout .write ("%s\n " % yellow ("SKIP" ))
50+ if msg : sys .stdout .write ("%s %s %s\n " % (" " * indent , yellow ("S" ), msg ))
51+ def failed (msg = None , indent = 1 ):
52+ global score
53+ score ["total" ] += 1
54+ score ["failed" ] += 1
5155 sys .stdout .write ("%s\n " % red ("FAIL" ))
52- def test (r ):
56+ if msg : sys .stdout .write ("%s %s %s\n " % (" " * indent , red ("F" ), msg ))
57+ def test (r , msg = None , indent = 1 ):
5358 if r :
54- passed ()
59+ passed (msg , indent )
5560 return True
5661 else :
57- failed ()
62+ failed (msg , indent )
5863 return False
5964
60- total += 1
65+ sys .stdout .write (LINE )
66+ sys .stdout .write (" * Testing for access to /dev/mem..." )
67+ d = True in [os .path .exists (os .path .join (_ , "dmidecode" )) for _ in os .getenv ("PATH" ).split (':' )]
68+ test (d , "Please install `dmidecode' (the binary) for complete testing." , 1 )
69+
70+ sys .stdout .write (" * Creation of temporary files..." )
71+ try :
72+ FH , DUMP = tempfile .mkstemp ()
73+ os .unlink (DUMP )
74+ os .close (FH )
75+ passed ()
76+ except :
77+ failed ()
78+
6179sys .stdout .write (LINE )
6280sys .stdout .write (" * Importing module..." )
6381try :
6482 import dmidecode
65- success += 1
6683 passed ()
6784 sys .stdout .write (" * Version: %s\n " % blue (dmidecode .version ))
6885 sys .stdout .write (" * DMI Version String: %s\n " % blue (dmidecode .dmi ))
6986
70- print "-" * 80
7187 sys .stdout .write (" * Testing that default device is /dev/mem..." )
7288 test (dmidecode .get_dev () == "/dev/mem" )
7389
@@ -115,8 +131,9 @@ def test(r):
115131 if output :
116132 sys .stdout .write (" * %s\n " % black (output .keys ()))
117133 except LookupError , e :
118- failed ()
119- sys .stdout .write (" x %s\n " % red (e ))
134+ failed (e , 2 )
135+ except IOError :
136+ skipped ("Permission denied" , 2 )
120137
121138 for i in bad_types :
122139 sys .stdout .write (" * Testing bad type %s..." % red (i )); sys .stdout .flush ()
@@ -143,6 +160,8 @@ def test(r):
143160except ImportError :
144161 failed ()
145162
146- color = red
147- if success == total : color = green
148- sys .stdout .write ("Score: %s/%s\n " % (color (success ), color (total )))
163+ sys .stdout .write (LINE )
164+ sys .stdout .write ("Total : %s\n " % blue (score ["total" ]))
165+ sys .stdout .write ("Skipped : %s\n " % yellow (score ["skipped" ]))
166+ sys .stdout .write ("Passed : %s\n " % green (score ["passed" ]))
167+ sys .stdout .write ("Failed : %s\n " % red (score ["failed" ]))
0 commit comments