diff options
author | David Sommerseth <davids@redhat.com> | 2010-05-14 19:03:50 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2010-05-14 19:03:50 +0200 |
commit | 09c18db0baebb77c02de066638ad2ed27edb15cc (patch) | |
tree | 7aeb83d54da507f267694fa0162256a576515b14 /rteval/dmi.py | |
parent | 1a9c5a4c7372c5dead09254b11c844debcc2a26c (diff) | |
download | rteval-09c18db0baebb77c02de066638ad2ed27edb15cc.tar.gz rteval-09c18db0baebb77c02de066638ad2ed27edb15cc.tar.xz rteval-09c18db0baebb77c02de066638ad2ed27edb15cc.zip |
Added unit-tests
Added a generic unit-test framework and rewritten the self-test parts in
some rteval modules where this was appropriate.
The unit-test contains a list of modules to load and test. It will run a
function named unit_test() in the imported modules. It is expected that
the unit_test() function will return 0 on success, otherwise it is logged
as an error.
Diffstat (limited to 'rteval/dmi.py')
-rw-r--r-- | rteval/dmi.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/rteval/dmi.py b/rteval/dmi.py index 3b08a2c..4f4835c 100644 --- a/rteval/dmi.py +++ b/rteval/dmi.py @@ -83,12 +83,35 @@ class DMIinfo(object): xml.AppendXMLnodes(node) -if __name__ == '__main__': +def unit_test(rootdir): from pprint import pprint - - d = DMIinfo('.') - x = xmlout.XMLOut('dmi_test', "0.0") - x.NewReport() - d.genxml(x) - x.close() - x.Write('-') + + class unittest_ConfigDummy(object): + def __init__(self, rootdir): + self.config = {'installdir': '%s/rteval'} + self.__update_vars() + + def __update_vars(self): + for k in self.config.keys(): + self.__dict__[k] = self.config[k] + + try: + ProcessWarnings() + if os.getuid() != 0: + print "** ERROR ** Must be root to run this unit_test()" + return 1 + + cfg = unittest_ConfigDummy(rootdir) + d = DMIinfo(cfg) + x = xmlout.XMLOut('dmi_test', "0.0") + x.NewReport() + d.genxml(x) + x.close() + x.Write('-') + return 0 + except Exception, e: + print "** EXCEPTION: %s" % str(e) + return 1 + +if __name__ == '__main__': + sys.exit(unit_test('.')) |