diff options
author | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-12-20 15:49:18 +0000 |
---|---|---|
committer | nima <nima@abc39116-655e-4be6-ad55-d661dc543056> | 2008-12-20 15:49:18 +0000 |
commit | fe4e406114752c7d61280f32b4af84cdc2504b4d (patch) | |
tree | 06d7fc358e91da769139514c59a04da27f76d8e5 | |
parent | 0e2598266442b8f1015c75833034ac0f26857820 (diff) | |
download | python-dmidecode-fe4e406114752c7d61280f32b4af84cdc2504b4d.tar.gz python-dmidecode-fe4e406114752c7d61280f32b4af84cdc2504b4d.tar.xz python-dmidecode-fe4e406114752c7d61280f32b4af84cdc2504b4d.zip |
Handle cases where user asks for invalid types.
Updated test cases to test for this too.
git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@136 abc39116-655e-4be6-ad55-d661dc543056
-rw-r--r-- | src/dmidecodemodule.c | 9 | ||||
-rwxr-xr-x | test.py | 36 |
2 files changed, 26 insertions, 19 deletions
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c index 03001a8..3030b97 100644 --- a/src/dmidecodemodule.c +++ b/src/dmidecodemodule.c @@ -192,9 +192,12 @@ static PyObject* dmidecode_get_slot(PyObject *self, PyObject *args) { retur static PyObject* dmidecode_get_type(PyObject *self, PyObject *args) { long unsigned int lu; if(PyArg_ParseTuple(args, (char *)"i", &lu)) { - char s[8]; - sprintf(s, "%lu", lu); - return dmidecode_get(self, s); + if(lu < 256) { + char s[8]; + sprintf(s, "%lu", lu); + return dmidecode_get(self, s); + } + return Py_False; } return Py_None; } @@ -19,15 +19,17 @@ def test(r): if r: sys.stdout.write("Good\n") success += 1 + return True else: - sys.stdout.write("Bad\n") + sys.stdout.write("FAILED\n") + return False total += 1 sys.stdout.write("Importing module...") try: import dmidecode - sys.stdout.write("Done\n") success += 1 + sys.stdout.write("Done\n") sys.stdout.write(" * Version: %s\n"%dmidecode.version) sys.stdout.write(" * DMI Version String: %s\n"%dmidecode.dmi) @@ -53,6 +55,7 @@ try: types = range(0, 42)+range(126, 128) types = range(0, 42)+[126, 127] + bad_types = [-1, -1000, 256] sections = ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"] devices = [os.path.join("private", _) for _ in os.listdir("private")] devices.remove('private/.svn') @@ -63,24 +66,25 @@ try: 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") + if test(dmidecode.set_dev(dev) and dmidecode.get_dev() == dev): + for i in bad_types: + sys.stdout.write(" * Testing bad type %i..."%i); sys.stdout.flush() + try: + output = dmidecode.type(i) + test(output is False) + except SystemError: + sys.stdout.write("FAILED\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 + output = dmidecode.type(i) + test(output is not False) + if output: + sys.stdout.write(" * %s\n"%output.keys()) 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") + output = getattr(dmidecode, section)() + test(output is not False) + if output: sys.stdout.write(" * %s\n"%output.keys()) except ImportError: sys.stdout.write("FAILED\n") |