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/xmlout.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/xmlout.py')
-rw-r--r-- | rteval/xmlout.py | 126 |
1 files changed, 72 insertions, 54 deletions
diff --git a/rteval/xmlout.py b/rteval/xmlout.py index b4fe371..648131b 100644 --- a/rteval/xmlout.py +++ b/rteval/xmlout.py @@ -257,58 +257,76 @@ class XMLOut(object): return self.currtag.addChild(nodes) +def unit_test(rootdir): + try: + x = XMLOut('rteval', 'UNIT-TEST', None, 'UTF-8') + x.NewReport() + x.openblock('run_info', {'days': 0, 'hours': 0, 'minutes': 32, 'seconds': 18}) + x.taggedvalue('time', '11:22:33') + x.taggedvalue('date', '2000-11-22') + x.closeblock() + x.openblock('uname') + x.taggedvalue('node', u'testing - \xe6\xf8') + x.taggedvalue('kernel', 'my_test_kernel', {'is_RT': 0}) + x.taggedvalue('arch', 'mips') + x.closeblock() + x.openblock('hardware') + x.taggedvalue('cpu_cores', 2) + x.taggedvalue('memory_size', 1024*1024*2) + x.closeblock() + x.openblock('loads', {'load_average': 3.29}) + x.taggedvalue('command_line','./load/loader --extreme --ultimate --threads 4096', + {'name': 'heavyloader'}) + x.taggedvalue('command_line','dd if=/dev/zero of=/dev/null', {'name': 'lightloader'}) + x.closeblock() + x.close() + print "------------- XML OUTPUT ----------------------------" + x.Write("-") + print "------------- XSLT PARSED OUTPUT --------------------" + x.Write("-", "rteval_text.xsl") + print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + x.Write("/tmp/xmlout-test.xml") + del x + + print "------------- LOAD XML FROM FILE -----------------------------" + x = XMLOut('rteval','UNIT-TEST', None, 'UTF-8') + x.LoadReport("/tmp/xmlout-test.xml", True) + print "------------- LOADED XML DATA --------------------------------" + x.Write("-") + print "------------- XSLT PARSED OUTPUT FROM LOADED XML--------------" + x.Write("-", "rteval_text.xsl") + x.close() + + ## Test new data parser ... it eats most data types + print "------------- TESTING XMLOut::ParseData() --------------" + x.NewReport() + x.ParseData("ParseTest", "test string", {"type": "simple_string"}) + x.ParseData("ParseTest", 1234, {"type": "integer"}) + x.ParseData("ParseTest", 39.3904, {"type": "float"}) + x.ParseData("ParseTest", (11,22,33,44,55), {"type": "tuples"}) + x.ParseData("ParseTest", (99,88,77), {"type": "tuples", "comment": "Changed default tuple tag name"}, + "int_values") + test = {"var1": "value 1", + "var2": { "varA1": 1, + "pi": 3.1415926, + "varA3": (1, + 2, + {"test1": "val1"}, + (4.1,4.2,4.3), + 5), + "varA4": {'another_level': True, + 'another_value': "blabla"} + }, + "utf8 data": u'æøå', + u"løpe": True} + x.ParseData("ParseTest", test, {"type": "dict"}, prefix="test ") + x.close() + x.Write("-") + return 0 + except Exception, e: + print "** EXCEPTION %s", str(e) + return 1 + if __name__ == '__main__': - x = XMLOut('rteval', '0.6', None, 'UTF-8') - x.NewReport() - x.openblock('run_info', {'days': 0, 'hours': 0, 'minutes': 32, 'seconds': 18}) - x.taggedvalue('time', '11:22:33') - x.taggedvalue('date', '2000-11-22') - x.closeblock() - x.openblock('uname') - x.taggedvalue('node', u'testing - \xe6\xf8') - x.taggedvalue('kernel', 'my_test_kernel', {'is_RT': 0}) - x.taggedvalue('arch', 'mips') - x.closeblock() - x.openblock('hardware') - x.taggedvalue('cpu_cores', 2) - x.taggedvalue('memory_size', 1024*1024*2) - x.closeblock() - x.openblock('loads', {'load_average': 3.29}) - x.taggedvalue('command_line','./load/loader --extreme --ultimate --threads 4096', {'name': 'heavyloader'}) - x.taggedvalue('command_line','dd if=/dev/zero of=/dev/null', {'name': 'lightloader'}) - x.closeblock() - x.close() - print "------------- XML OUTPUT ----------------------------" - x.Write("-") - print "------------- XSLT PARSED OUTPUT --------------------" - x.Write("-", "rteval_text.xsl") - print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" - x.LoadReport("latency.xml", True) - x.Write("-") - x.Write("-", "rteval_text.xsl") - x.close() - - ## Test new data parser ... it eats most data types - x.NewReport() - x.ParseData("ParseTest", "test string", {"type": "simple_string"}) - x.ParseData("ParseTest", 1234, {"type": "integer"}) - x.ParseData("ParseTest", 39.3904, {"type": "float"}) - x.ParseData("ParseTest", (11,22,33,44,55), {"type": "tuples"}) - x.ParseData("ParseTest", (99,88,77), {"type": "tuples", "comment": "Changed default tuple tag name"}, - "int_values") - test = {"var1": "value 1", - "var2": { "varA1": 1, - "pi": 3.1415926, - "varA3": (1, - 2, - {"test1": "val1"}, - (4.1,4.2,4.3), - 5), - "varA4": {'another_level': True, - 'another_value': "blabla"} - }, - "utf8 data": u'æøå', - u"løpe": True} - x.ParseData("ParseTest", test, {"type": "dict"}, prefix="test ") - x.close() - x.Write("-") + sys.exit(unit_test('..')) + |