+1 for me.
Best,
Regards
Daisy (运国莲)
VSM Team, China Systems & Technology Labs (CSTL)
E-mail: yunguol(a)cn.ibm.com
TEL: (86)-21-60922403
Building 10, 399 Ke Yuan Rd, Pudong Shanghai, 201203
libvirt-cim-bounces(a)redhat.com wrote on 2008-08-07 03:28:36:
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1213136844 25200
# Node ID 63757929dd9a15671ae59fb54b89121bbc93d50d
# Parent 502dddef8c34eeb85b571df0ee97f0ee0676861b
[TEST] Enable test infrastructure to support writing to a temporary
file.
Allow the option to print to a file in addition to stdout. This
will allow a test suite to read back the file after the test
execution is complete.
If a previous log exists at the start of the run, it is removed and
a new one is created.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 502dddef8c34 -r 63757929dd9a lib/Reporter.py
--- a/lib/Reporter.py Tue Jul 01 14:12:48 2008 -0700
+++ b/lib/Reporter.py Tue Jun 10 15:27:24 2008 -0700
@@ -19,10 +19,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
#
+from CimTest.ReturnCodes import PASS, FAIL, SKIP, XFAIL
+
class Reporter:
- def __init__(self, verbosity=1):
+ def __init__(self, verbosity=1, log_fd=None):
self.verbosity = verbosity
+ self.log_fd = log_fd
def __red(self, str):
return "\033[01;31m%s\033[00m" % str
@@ -36,11 +39,38 @@
def __blue(self, str):
return "\033[01;34m%s\033[00m" % str
- def __out(self, str):
- """We might not always be just printing output to stdout,
so this should
- be used for all output."""
- # Right now we just mimic print.
- print(str)
+ def __out(self, str, status, bug):
+ def no_color(string):
+ return string
+
+ colors = { "FAIL" : self.__red,
+ "PASS" : self.__green,
+ "SKIP" : self.__yellow,
+ "XFAIL" : self.__blue,
+ }
+
+ fn = colors.get(status, no_color)
+
+ if status == XFAIL:
+ print "%s: %s\tBug: %s" % (str, fn(status), bug)
+ else:
+ print "%s: %s" % (str, fn(status))
+
+ if self.log_fd is not None:
+ if status == XFAIL:
+ self.log_fd.write("%s: %s\tBug: %s" % (str, status,
bug))
+ else:
+ self.log_fd.write("%s: %s" % (str, status))
+
+ def results(self, str, status, bug):
+
+ rc = { FAIL : "FAIL",
+ PASS : "PASS",
+ SKIP : "SKIP",
+ XFAIL : "XFAIL"
+ }
+
+ self.__out(str, rc[status], bug)
def debug(self, level, str):
"""Produces debug output if appropriate for current verbosity
level.
@@ -49,20 +79,5 @@
priority output will be printed in the most levels, while
low priority
output will only be printed when verbosity is high."""
if level <= self.verbosity:
- self.__out(str)
+ print(str)
- def pass_test(self, test_name):
- str = self.__green("PASS")
- self.__out("%s: %s" % (test_name, str))
-
- def fail_test(self, test_name):
- str = self.__red("FAIL")
- self.__out("%s: %s" % (test_name, str))
-
- def xfail_test(self, test_name, bug):
- str = self.__blue("XFAIL")
- self.__out("%s: %s\tBug: %s" % (test_name, str, bug))
-
- def skip_test(self, test_name):
- str = self.__yellow("SKIP")
- self.__out("%s: %s" % (test_name, str))
diff -r 502dddef8c34 -r 63757929dd9a lib/TestSuite.py
--- a/lib/TestSuite.py Tue Jul 01 14:12:48 2008 -0700
+++ b/lib/TestSuite.py Tue Jun 10 15:27:24 2008 -0700
@@ -24,48 +24,59 @@
DEFAULT_RPC_URL = "http://morbo.linux.ibm.com/xenotest/testrun/api"
+DEFAULT_LOG_FILE = "run_report.txt"
+
import Reporter
import re
+import os
+from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP
class TestSuite:
"""Test Suite class to make the output of driving test suites a
bit more consistant"""
- def __init__(self):
- self.rep = Reporter.Reporter(verbosity=5)
+ def __init__(self, log=False, file_name=None):
+ if log == True:
+ if file_name is None:
+ self.log_file = DEFAULT_LOG_FILE
+ else:
+ self.log_file = file_name
- def ok(self, group, test, output=""):
- self.rep.pass_test("%s - %s" % (group, test))
+ if os.path.exists(self.log_file):
+ os.remove(self.log_file)
+ self.log_fd = open(self.log_file, "w")
+ else:
+ self.log_file = None
+ self.log_fd = None
- def skip(self, group, test, output=""):
- self.rep.skip_test("%s - %s" % (group, test))
+ self.rep = Reporter.Reporter(verbosity=5, log_fd=self.log_fd)
+
+ def print_results(self, group, test, status, output=""):
+ bug = None
+ if status == XFAIL:
+ err = "Test error: returned XFAIL without a valid bug
string."
+ bug = err
+ if len(output) > 0:
+ try:
+ str = re.search('Bug:<[0-9]*>', output).group()
+ bug = re.search("Bug:<([0-9]+)>", str).group(1)
+ if len(str) > 0:
+ if output == str:
+ #No need to pring bug twice
+ output = ""
+ except:
+ #If we hit a problem, make sure bug = error msg
+ bug = err
+
+ self.rep.results("%s - %s" % (group, test), status, bug)
if output:
self.rep.debug(1, output)
- def fail(self, group, test, output=""):
- self.rep.fail_test("%s - %s" % (group, test))
- if output:
- self.rep.debug(1, output)
-
- def xfail(self, group, test, output=""):
- err = "Test error: returned XFAIL without a valid bug string."
- bug = err
- if len(output) > 0:
- try:
- str = re.search('Bug:<[0-9]*>', output).group()
- bug = re.search("Bug:<([0-9]+)>", str).group(1)
- if len(str) > 0:
- if output == str:
- #No need to pring bug twice
- output = ""
- except:
- #If we hit a problem, make sure bug is equal to
theerror msg
- bug = err
- self.rep.xfail_test("%s - %s" % (group, test), bug)
- if output:
- self.rep.debug(1, output)
+ def debug(self, str):
+ self.rep.debug(1, str)
def finish(self):
- pass
+ if self.log_fd is not None:
+ self.log_fd.close()
class RPCTestSuite:
"""Test Suite class to make the output of driving test suites a
bit more consistant
diff -r 502dddef8c34 -r 63757929dd9a suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py Tue Jul 01 14:12:48 2008 -0700
+++ b/suites/libvirt-cim/main.py Tue Jun 10 15:27:24 2008 -0700
@@ -153,14 +153,7 @@
os_status = os.WEXITSTATUS(status)
- if os_status == PASS:
- testsuite.ok(test['group'], test['test'])
- elif os_status == SKIP:
- testsuite.skip(test['group'], test['test'], output)
- elif os_status == XFAIL:
- testsuite.xfail(test['group'], test['test'], output)
- else:
- testsuite.fail(test['group'], test['test'], output)
+ testsuite.print_results(test['group'], test['test'],
os_status)
testsuite.finish()
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim