summaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-20 15:32:30 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-20 15:32:30 +0000
commit0e2598266442b8f1015c75833034ac0f26857820 (patch)
treef4fb3cb9a3ad6e0fb9f61cd437a0933623ac820b /test.py
parent6d5ebf5d39e419e2f83960223bf840275426dc87 (diff)
downloadpython-dmidecode-0e2598266442b8f1015c75833034ac0f26857820.tar.gz
python-dmidecode-0e2598266442b8f1015c75833034ac0f26857820.tar.xz
python-dmidecode-0e2598266442b8f1015c75833034ac0f26857820.zip
Version information now set once during init().
Bettered test cases. Case 127 magically fixed. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@135 abc39116-655e-4be6-ad55-d661dc543056
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py126
1 files changed, 74 insertions, 52 deletions
diff --git a/test.py b/test.py
index 59608a8..23b83f2 100755
--- a/test.py
+++ b/test.py
@@ -1,66 +1,88 @@
#!/usr/bin/env python
-#.awk '$0 ~ /case [0-9]+: .. 3/ { print $2 }' src/dmidecode.c|tr ':\n' ', '
+#.awk '$0 ~ /case [0-9]+: .. 3/ { sys.stdout.write($2 }' src/dmidecode.c|tr ':\n' ', '
from pprint import pprint
-import os, sys, random
+import os, sys, random, tempfile, time
-print "Importing module...",
-import dmidecode
-print "Done"
+FH, DUMP = tempfile.mkstemp()
+os.unlink(DUMP)
+os.close(FH)
-print "Testing check for write permission on dump...",
-print not dmidecode.dump() and "Good" or "Bad"
+total = 0
+success = 0
-print "Testing that default device is /dev/mem",
-print dmidecode.get_dev() == "/dev/mem" and "Good" or "Bad"
+def test(r):
+ global total
+ global success
-print "Testing ability to change device to /tmp/foo...",
-print dmidecode.set_dev("/tmp/foo") and "Good" or "Bad"
+ total += 1
+ if r:
+ sys.stdout.write("Good\n")
+ success += 1
+ else:
+ sys.stdout.write("Bad\n")
-print "Testing that device has changed to /tmp/foo...",
-print dmidecode.get_dev() == "/tmp/foo" and "Good" or "Bad"
+total += 1
+sys.stdout.write("Importing module...")
+try:
+ import dmidecode
+ sys.stdout.write("Done\n")
+ success += 1
+ sys.stdout.write(" * Version: %s\n"%dmidecode.version)
+ sys.stdout.write(" * DMI Version String: %s\n"%dmidecode.dmi)
-print "Testing that write on new file is ok...",
-print dmidecode.dump() and "Good" or "Bad"
+ sys.stdout.write("Testing that default device is /dev/mem...")
+ test(dmidecode.get_dev() == "/dev/mem")
-print "Testing that file was actually written...",
-if os.path.exists("/tmp/foo"):
- sys.stdout.write("Good\n")
- os.unlink("/tmp/foo")
-else:
- sys.stdout.write("FAILED\n")
+ sys.stdout.write("Testing that write-lock will not break on dump()...")
+ test(not dmidecode.dump())
-types = range(0, 42)+range(126, 128)
-types = range(0, 42)+[126, 127]
-sections = ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"]
-devices = [os.path.join("private", _) for _ in os.listdir("private")]
-devices.remove('private/.svn')
-devices.append("/dev/mem")
-random.shuffle(types)
-random.shuffle(devices)
-random.shuffle(sections)
+ sys.stdout.write("Testing ability to change device to %s..."%DUMP)
+ test(dmidecode.set_dev(DUMP))
-total = 0
-success = 0
-for dev in devices:
- sys.stdout.write(" * Testing %s..."%dev); sys.stdout.flush()
- total += 1
- if dmidecode.set_dev(dev) and dmidecode.get_dev() == dev:
- success += 1
- sys.stdout.write("...\n")
- for i in types:
- sys.stdout.write(" * Testing type %i..."%i); sys.stdout.flush()
- output = dmidecode.type(i).keys()
- total += 1
- sys.stdout.write("Done (%s)\n"%output)
- success += 1
- for section in sections:
- total += 1
- sys.stdout.write(" * Testing %s..."%section); sys.stdout.flush()
- output = getattr(dmidecode, section)().keys()
- sys.stdout.write("Done (%s)\n"%output)
+ sys.stdout.write("Testing that device has changed to %s..."%DUMP)
+ test(dmidecode.get_dev() == DUMP)
+
+ sys.stdout.write("Testing that write on new file is ok...")
+ test(dmidecode.dump())
+
+ sys.stdout.write("Testing that file was actually written...")
+ time.sleep(0.1)
+ test(os.path.exists(DUMP))
+ os.unlink(DUMP)
+
+ types = range(0, 42)+range(126, 128)
+ types = range(0, 42)+[126, 127]
+ sections = ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"]
+ devices = [os.path.join("private", _) for _ in os.listdir("private")]
+ devices.remove('private/.svn')
+ devices.append("/dev/mem")
+ random.shuffle(types)
+ random.shuffle(devices)
+ random.shuffle(sections)
+
+ for dev in devices:
+ sys.stdout.write(" * Testing %s..."%dev); sys.stdout.flush()
+ total += 1
+ if dmidecode.set_dev(dev) and dmidecode.get_dev() == dev:
success += 1
- else:
- sys.stdout.write("FAILED\n")
+ sys.stdout.write("...\n")
+ for i in types:
+ total += 1
+ sys.stdout.write(" * Testing type %i..."%i); sys.stdout.flush()
+ output = dmidecode.type(i).keys()
+ sys.stdout.write("Done (%s)\n"%output)
+ success += 1
+ for section in sections:
+ total += 1
+ sys.stdout.write(" * Testing %s..."%section); sys.stdout.flush()
+ output = getattr(dmidecode, section)().keys()
+ sys.stdout.write("Done (%s)\n"%output)
+ success += 1
+ else:
+ sys.stdout.write("FAILED\n")
+
+except ImportError:
+ sys.stdout.write("FAILED\n")
-print "Score: %d/%d"%(success, total)
+sys.stdout.write("Score: %d/%d\n"%(success, total))