diff options
author | Nima Talebi <nima@autonomy.net.au> | 2009-05-23 15:21:42 +1000 |
---|---|---|
committer | Nima Talebi <nima@autonomy.net.au> | 2009-05-23 15:21:42 +1000 |
commit | f17fca75b0766caeba992bd62ab9c87cc6a79acc (patch) | |
tree | 8b2b4187a01b9fe26c76f37ca76ca8218ed54873 | |
parent | a18a72fab2a622077d5257003b09be30ab283339 (diff) | |
download | python-dmidecode-f17fca75b0766caeba992bd62ab9c87cc6a79acc.tar.gz python-dmidecode-f17fca75b0766caeba992bd62ab9c87cc6a79acc.tar.xz python-dmidecode-f17fca75b0766caeba992bd62ab9c87cc6a79acc.zip |
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).
-rwxr-xr-x | examples/test.py | 65 | ||||
-rw-r--r-- | src/pythonmap.xml | 2 | ||||
-rw-r--r-- | src/xmlpythonizer.c | 4 |
3 files changed, 41 insertions, 30 deletions
diff --git a/examples/test.py b/examples/test.py index c645d02..053d81d 100755 --- a/examples/test.py +++ b/examples/test.py @@ -5,7 +5,7 @@ from pprint import pprint import os, sys, random, tempfile, time import commands -DUMPS_D = "../../pydmidata/" +DUMPS_D = "private" def ascii(s, i): return "\033[%d;1m%s\033[0m"%(30+i, str(s)) def black(s): return "\033[30;1m%s\033[0m"%(str(s)) @@ -39,17 +39,22 @@ os.close(FH) total = 0 success = 0 -def test(r): +def passed(): global total global success - total += 1 + success += 1 + sys.stdout.write("%s\n"%green("PASS")) +def failed(): + global total + total += 1 + sys.stdout.write("%s\n"%red("FAIL")) +def test(r): if r: - sys.stdout.write("%s\n"%green("PASS")) - success += 1 + passed() return True else: - sys.stdout.write("%s\n"%red("FAIL")) + failed() return False total += 1 @@ -58,7 +63,7 @@ sys.stdout.write(" * Importing module...") try: import dmidecode success += 1 - sys.stdout.write("%s\n"%green("PASS")) + passed() sys.stdout.write(" * Version: %s\n"%blue(dmidecode.version)) sys.stdout.write(" * DMI Version String: %s\n"%blue(dmidecode.dmi)) @@ -80,8 +85,8 @@ try: sys.stdout.write(" * Testing that file was actually written...") time.sleep(0.1) - test(os.path.exists(DUMP)) - os.unlink(DUMP) + if test(os.path.exists(DUMP)): + os.unlink(DUMP) types = range(0, 42)+range(126, 128) bad_types = [-1, -1000, 256] @@ -97,40 +102,46 @@ try: random.shuffle(sections) for dev in devices: + sys.stdout.write(LINE) sys.stdout.write(" * Testing %s..."%yellow(dev)); sys.stdout.flush() if test(dmidecode.set_dev(dev) and dmidecode.get_dev() == dev): - sys.stdout.write(LINE) i = 0 for section in sections: - i += 0 - sys.stdout.write(" * Testing %s (%s/%d)..."%cyan(section), i, len(sections)); sys.stdout.flush() - output = getattr(dmidecode, section)() - test(output is not False) - if output: sys.stdout.write(" * %s\n"%black(output.keys())) + i += 1 + sys.stdout.write(" * Testing %s (%d/%d)..."%(cyan(section), i, len(sections))); sys.stdout.flush() + try: + output = getattr(dmidecode, section)() + test(output is not False) + if output: + sys.stdout.write(" * %s\n"%black(output.keys())) + except LookupError, e: + failed() + sys.stdout.write(" x %s\n"%red(e)) - sys.stdout.write(LINE) for i in bad_types: sys.stdout.write(" * Testing bad type %s..."%red(i)); sys.stdout.flush() try: output = dmidecode.type(i) test(output is False) except SystemError: - sys.stdout.write("%s\n"%red("FAIL")) + failed() - sys.stdout.write(LINE) for i in types: sys.stdout.write(" * Testing type %s..."%red(i)); sys.stdout.flush() - output = dmidecode.type(i) - if dmidecode: - _output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n') - test(len(_output) == 1 and len(output) == 0 or True) - else: - test(output is not False) - if output: - sys.stdout.write(" * %s\n"%output.keys()) + try: + output = dmidecode.type(i) + if dmidecode: + _output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n') + test(len(_output) == 1 and len(output) == 0 or True) + else: + test(output is not False) + if output: + sys.stdout.write(" * %s\n"%output.keys()) + except: + failed() except ImportError: - sys.stdout.write("%s\n"%red("FAIL")) + failed() color = red if success == total: color = green diff --git a/src/pythonmap.xml b/src/pythonmap.xml index b2d2d31..f4f8336 100644 --- a/src/pythonmap.xml +++ b/src/pythonmap.xml @@ -288,7 +288,7 @@ <Map keytype="constant" key="data" valuetype="dict"> <Map keytype="constant" key="Designation" valuetype="string" value="Designation"/> <Map keytype="constant" key="Current Usage" valuetype="string" value="CurrentUsage"/> - <Map keytype="constant" key="Characteristics" + <Map keytype="constant" key="Characteristics" valuetype="list:string" value="SlotCharacteristics/Characteristic" fixedsize="10" index_attr="index"/> <Map keytype="constant" key="SlotLength" valuetype="string" value="SlotLength"/> diff --git a/src/xmlpythonizer.c b/src/xmlpythonizer.c index dceeaa2..f1d755e 100644 --- a/src/xmlpythonizer.c +++ b/src/xmlpythonizer.c @@ -672,7 +672,7 @@ PyObject *_deep_pythonize(PyObject *retdata, ptzMAP *map_p, xmlNode *data_n, int char msg[8094]; snprintf(msg, 8092, "Could not locate XML path node: %s (Defining key: %s)%c", map_p->value, map_p->key, 0); - fprintf(stderr, msg); + //fprintf(stderr, msg); PyErr_SetString(PyExc_LookupError, msg); if( xpo != NULL ) { @@ -765,7 +765,7 @@ PyObject *pythonizeXMLnode(ptzMAP *in_map, xmlNode *data_n) { char msg[8094]; snprintf(msg, 8092, "Could not locate XML path node: %s (Defining key: %s)%c", map_p->rootpath, map_p->key, 0); - fprintf(stderr, msg); + //fprintf(stderr, msg); PyErr_SetString(PyExc_LookupError, msg); if( xpo != NULL ) { |