Skip to content

Commit f17fca7

Browse files
author
Nima Talebi
committed
Completed test case
Removed trailing spaces from xml data file. Commented out fprintf()s for now (Perhapse should add them to the debug build at least).
1 parent a18a72f commit f17fca7

3 files changed

Lines changed: 41 additions & 30 deletions

File tree

examples/test.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os, sys, random, tempfile, time
66
import commands
77

8-
DUMPS_D = "../../pydmidata/"
8+
DUMPS_D = "private"
99

1010
def ascii(s, i): return "\033[%d;1m%s\033[0m"%(30+i, str(s))
1111
def black(s): return "\033[30;1m%s\033[0m"%(str(s))
@@ -39,17 +39,22 @@ def white(s): return "\033[37;1m%s\033[0m"%(str(s))
3939
total = 0
4040
success = 0
4141

42-
def test(r):
42+
def passed():
4343
global total
4444
global success
45-
4645
total += 1
46+
success += 1
47+
sys.stdout.write("%s\n"%green("PASS"))
48+
def failed():
49+
global total
50+
total += 1
51+
sys.stdout.write("%s\n"%red("FAIL"))
52+
def test(r):
4753
if r:
48-
sys.stdout.write("%s\n"%green("PASS"))
49-
success += 1
54+
passed()
5055
return True
5156
else:
52-
sys.stdout.write("%s\n"%red("FAIL"))
57+
failed()
5358
return False
5459

5560
total += 1
@@ -58,7 +63,7 @@ def test(r):
5863
try:
5964
import dmidecode
6065
success += 1
61-
sys.stdout.write("%s\n"%green("PASS"))
66+
passed()
6267
sys.stdout.write(" * Version: %s\n"%blue(dmidecode.version))
6368
sys.stdout.write(" * DMI Version String: %s\n"%blue(dmidecode.dmi))
6469

@@ -80,8 +85,8 @@ def test(r):
8085

8186
sys.stdout.write(" * Testing that file was actually written...")
8287
time.sleep(0.1)
83-
test(os.path.exists(DUMP))
84-
os.unlink(DUMP)
88+
if test(os.path.exists(DUMP)):
89+
os.unlink(DUMP)
8590

8691
types = range(0, 42)+range(126, 128)
8792
bad_types = [-1, -1000, 256]
@@ -97,40 +102,46 @@ def test(r):
97102
random.shuffle(sections)
98103

99104
for dev in devices:
105+
sys.stdout.write(LINE)
100106
sys.stdout.write(" * Testing %s..."%yellow(dev)); sys.stdout.flush()
101107
if test(dmidecode.set_dev(dev) and dmidecode.get_dev() == dev):
102-
sys.stdout.write(LINE)
103108
i = 0
104109
for section in sections:
105-
i += 0
106-
sys.stdout.write(" * Testing %s (%s/%d)..."%cyan(section), i, len(sections)); sys.stdout.flush()
107-
output = getattr(dmidecode, section)()
108-
test(output is not False)
109-
if output: sys.stdout.write(" * %s\n"%black(output.keys()))
110+
i += 1
111+
sys.stdout.write(" * Testing %s (%d/%d)..."%(cyan(section), i, len(sections))); sys.stdout.flush()
112+
try:
113+
output = getattr(dmidecode, section)()
114+
test(output is not False)
115+
if output:
116+
sys.stdout.write(" * %s\n"%black(output.keys()))
117+
except LookupError, e:
118+
failed()
119+
sys.stdout.write(" x %s\n"%red(e))
110120

111-
sys.stdout.write(LINE)
112121
for i in bad_types:
113122
sys.stdout.write(" * Testing bad type %s..."%red(i)); sys.stdout.flush()
114123
try:
115124
output = dmidecode.type(i)
116125
test(output is False)
117126
except SystemError:
118-
sys.stdout.write("%s\n"%red("FAIL"))
127+
failed()
119128

120-
sys.stdout.write(LINE)
121129
for i in types:
122130
sys.stdout.write(" * Testing type %s..."%red(i)); sys.stdout.flush()
123-
output = dmidecode.type(i)
124-
if dmidecode:
125-
_output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n')
126-
test(len(_output) == 1 and len(output) == 0 or True)
127-
else:
128-
test(output is not False)
129-
if output:
130-
sys.stdout.write(" * %s\n"%output.keys())
131+
try:
132+
output = dmidecode.type(i)
133+
if dmidecode:
134+
_output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n')
135+
test(len(_output) == 1 and len(output) == 0 or True)
136+
else:
137+
test(output is not False)
138+
if output:
139+
sys.stdout.write(" * %s\n"%output.keys())
140+
except:
141+
failed()
131142

132143
except ImportError:
133-
sys.stdout.write("%s\n"%red("FAIL"))
144+
failed()
134145

135146
color = red
136147
if success == total: color = green

src/pythonmap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
<Map keytype="constant" key="data" valuetype="dict">
289289
<Map keytype="constant" key="Designation" valuetype="string" value="Designation"/>
290290
<Map keytype="constant" key="Current Usage" valuetype="string" value="CurrentUsage"/>
291-
<Map keytype="constant" key="Characteristics"
291+
<Map keytype="constant" key="Characteristics"
292292
valuetype="list:string" value="SlotCharacteristics/Characteristic"
293293
fixedsize="10" index_attr="index"/>
294294
<Map keytype="constant" key="SlotLength" valuetype="string" value="SlotLength"/>

src/xmlpythonizer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ PyObject *_deep_pythonize(PyObject *retdata, ptzMAP *map_p, xmlNode *data_n, int
672672
char msg[8094];
673673
snprintf(msg, 8092, "Could not locate XML path node: %s (Defining key: %s)%c",
674674
map_p->value, map_p->key, 0);
675-
fprintf(stderr, msg);
675+
//fprintf(stderr, msg);
676676
PyErr_SetString(PyExc_LookupError, msg);
677677

678678
if( xpo != NULL ) {
@@ -765,7 +765,7 @@ PyObject *pythonizeXMLnode(ptzMAP *in_map, xmlNode *data_n) {
765765
char msg[8094];
766766
snprintf(msg, 8092, "Could not locate XML path node: %s (Defining key: %s)%c",
767767
map_p->rootpath, map_p->key, 0);
768-
fprintf(stderr, msg);
768+
//fprintf(stderr, msg);
769769
PyErr_SetString(PyExc_LookupError, msg);
770770

771771
if( xpo != NULL ) {

0 commit comments

Comments
 (0)