mirror of
https://github.com/samba-team/samba.git
synced 2025-03-29 02:50:28 +03:00
format-subunit: Improve formatting, simplify code.
This commit is contained in:
parent
ef3fb75261
commit
c108a2e74e
@ -12,7 +12,8 @@ import subunithelper
|
||||
|
||||
class PlainFormatter(object):
|
||||
|
||||
def __init__(self, summaryfile, verbose, immediate, statistics, totaltests=None):
|
||||
def __init__(self, summaryfile, verbose, immediate, statistics,
|
||||
totaltests=None):
|
||||
self.verbose = verbose
|
||||
self.immediate = immediate
|
||||
self.statistics = statistics
|
||||
@ -23,7 +24,7 @@ class PlainFormatter(object):
|
||||
self.skips = {}
|
||||
self.summaryfile = summaryfile
|
||||
self.index = 0
|
||||
self.NAME = None
|
||||
self.name = None
|
||||
self.totalsuites = totaltests
|
||||
|
||||
def testsuite_count(self, count):
|
||||
@ -36,16 +37,15 @@ class PlainFormatter(object):
|
||||
|
||||
def start_testsuite(self, name):
|
||||
self.index += 1
|
||||
self.NAME = name
|
||||
self.START_TIME = self.last_time
|
||||
self.name = name
|
||||
testsuite_start_time = self.last_time
|
||||
|
||||
duration = self.START_TIME - self.start_time
|
||||
duration = testsuite_start_time - self.start_time
|
||||
|
||||
if not self.verbose:
|
||||
self.test_output[name] = ""
|
||||
|
||||
out = ""
|
||||
out += "[%d" % self.index
|
||||
out = "[%d" % self.index
|
||||
if self.totalsuites is not None:
|
||||
out += "/%d" % self.totalsuites
|
||||
out += " in %ds" % duration
|
||||
@ -60,8 +60,8 @@ class PlainFormatter(object):
|
||||
def output_msg(self, output):
|
||||
if self.verbose:
|
||||
sys.stdout.write(output)
|
||||
elif self.NAME is not None:
|
||||
self.test_output[self.NAME] += output
|
||||
elif self.name is not None:
|
||||
self.test_output[self.name] += output
|
||||
else:
|
||||
sys.stdout.write(output)
|
||||
|
||||
@ -97,10 +97,8 @@ class PlainFormatter(object):
|
||||
pass
|
||||
|
||||
def end_test(self, testname, result, unexpected, reason):
|
||||
append = ""
|
||||
|
||||
if not unexpected:
|
||||
self.test_output[self.NAME] = ""
|
||||
self.test_output[self.name] = ""
|
||||
if not self.immediate:
|
||||
sys.stdout.write({
|
||||
'failure': 'f',
|
||||
@ -111,13 +109,11 @@ class PlainFormatter(object):
|
||||
|
||||
reason = reason.strip()
|
||||
|
||||
append = "UNEXPECTED(%s): %s\nREASON: %s\n" % (result, testname, reason)
|
||||
|
||||
self.test_output[self.NAME] += append
|
||||
self.test_output[self.name] += "UNEXPECTED(%s): %s\nREASON: %s\n" % (result, testname, reason)
|
||||
|
||||
if self.immediate and not self.verbose:
|
||||
print self.test_output[self.NAME]
|
||||
self.test_output[self.NAME] = ""
|
||||
print self.test_output[self.name]
|
||||
self.test_output[self.name] = ""
|
||||
|
||||
if not self.immediate:
|
||||
sys.stdout.write({
|
||||
@ -139,7 +135,7 @@ class PlainFormatter(object):
|
||||
|
||||
if not self.immediate and not self.verbose:
|
||||
for suite in self.suitesfailed:
|
||||
print "==============================================================================="
|
||||
print "=" * 78
|
||||
print "FAIL: %s" % suite
|
||||
print self.test_output[suite]
|
||||
print ""
|
||||
@ -152,13 +148,18 @@ class PlainFormatter(object):
|
||||
f.write("\n")
|
||||
f.close()
|
||||
|
||||
print "\nA summary with detailed information can be found in:\n %s\n" % self.summaryfile
|
||||
print "\nA summary with detailed information can be found in:"
|
||||
print " %s" % self.summaryfile
|
||||
|
||||
if not self.suitesfailed:
|
||||
ok = self.statistics['TESTS_EXPECTED_OK'] + self.statistics['TESTS_EXPECTED_FAIL']
|
||||
ok = (self.statistics['TESTS_EXPECTED_OK'] +
|
||||
self.statistics['TESTS_EXPECTED_FAIL'])
|
||||
print "\nALL OK (%d tests in %d testsuites)" % (ok, self.suites_ok)
|
||||
else:
|
||||
print "\nFAILED (%d failures and %d errors in %d testsuites)" % (self.statistics['TESTS_UNEXPECTED_FAIL'], self.statistics['TESTS_ERROR'], len(self.suitesfailed))
|
||||
print "\nFAILED (%d failures and %d errors in %d testsuites)" % (
|
||||
self.statistics['TESTS_UNEXPECTED_FAIL'],
|
||||
self.statistics['TESTS_ERROR'],
|
||||
len(self.suitesfailed))
|
||||
|
||||
def skip_testsuite(self, name, reason="UNKNOWN"):
|
||||
self.skips.setdefault(reason, []).append(name)
|
||||
@ -185,7 +186,8 @@ statistics = {
|
||||
'TESTS_SKIP': 0,
|
||||
}
|
||||
|
||||
msg_ops = PlainFormatter(os.path.join(opts.prefix, "summary"), opts.verbose, opts.immediate, statistics)
|
||||
msg_ops = PlainFormatter(os.path.join(opts.prefix, "summary"), opts.verbose,
|
||||
opts.immediate, statistics)
|
||||
|
||||
expected_ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
|
||||
|
||||
|
@ -60,7 +60,7 @@ def parse_results(msg_ops, statistics, fh):
|
||||
|
||||
if not terminated:
|
||||
statistics['TESTS_ERROR']+=1
|
||||
msg_ops.end_test(testname, "error", 1,
|
||||
msg_ops.end_test(testname, "error", True,
|
||||
"reason (%s) interrupted" % result)
|
||||
return 1
|
||||
else:
|
||||
@ -68,27 +68,27 @@ def parse_results(msg_ops, statistics, fh):
|
||||
if result in ("success", "successful"):
|
||||
open_tests.pop() #FIXME: Check that popped value == $testname
|
||||
statistics['TESTS_EXPECTED_OK']+=1
|
||||
msg_ops.end_test(testname, "success", 0, reason)
|
||||
msg_ops.end_test(testname, "success", False, reason)
|
||||
elif result in ("xfail", "knownfail"):
|
||||
open_tests.pop() #FIXME: Check that popped value == $testname
|
||||
statistics['TESTS_EXPECTED_FAIL']+=1
|
||||
msg_ops.end_test(testname, "xfail", 0, reason)
|
||||
msg_ops.end_test(testname, "xfail", False, reason)
|
||||
expected_fail+=1
|
||||
elif result in ("failure", "fail"):
|
||||
open_tests.pop() #FIXME: Check that popped value == $testname
|
||||
statistics['TESTS_UNEXPECTED_FAIL']+=1
|
||||
msg_ops.end_test(testname, "failure", 1, reason)
|
||||
msg_ops.end_test(testname, "failure", True, reason)
|
||||
elif result == "skip":
|
||||
statistics['TESTS_SKIP']+=1
|
||||
# Allow tests to be skipped without prior announcement of test
|
||||
last = open_tests.pop()
|
||||
if last is not None and last != testname:
|
||||
open_tests.append(testname)
|
||||
msg_ops.end_test(testname, "skip", 0, reason)
|
||||
msg_ops.end_test(testname, "skip", False, reason)
|
||||
elif result == "error":
|
||||
statistics['TESTS_ERROR']+=1
|
||||
open_tests.pop() #FIXME: Check that popped value == $testname
|
||||
msg_ops.end_test(testname, "error", 1, reason)
|
||||
msg_ops.end_test(testname, "error", True, reason)
|
||||
elif result == "skip-testsuite":
|
||||
msg_ops.skip_testsuite(testname)
|
||||
elif result == "testsuite-success":
|
||||
@ -107,7 +107,7 @@ def parse_results(msg_ops, statistics, fh):
|
||||
msg_ops.output_msg(l)
|
||||
|
||||
while open_tests:
|
||||
msg_ops.end_test(open_tests.pop(), "error", 1,
|
||||
msg_ops.end_test(open_tests.pop(), "error", True,
|
||||
"was started but never finished!")
|
||||
statistics['TESTS_ERROR']+=1
|
||||
|
||||
@ -118,54 +118,52 @@ def parse_results(msg_ops, statistics, fh):
|
||||
return 0
|
||||
|
||||
|
||||
def start_test(testname):
|
||||
print "test: %s" % testname
|
||||
class SubunitOps(object):
|
||||
|
||||
def end_test(name, result, reason=None):
|
||||
if reason:
|
||||
print "%s: %s [" % (result, name)
|
||||
print "%s" % reason
|
||||
print "]"
|
||||
else:
|
||||
print "%s: %s" % (result, name)
|
||||
def start_test(self, testname):
|
||||
print "test: %s" % testname
|
||||
|
||||
def end_test(self, name, result, reason=None):
|
||||
if reason:
|
||||
print "%s: %s [" % (result, name)
|
||||
print "%s" % reason
|
||||
print "]"
|
||||
else:
|
||||
print "%s: %s" % (result, name)
|
||||
|
||||
def skip_test(name, reason=None):
|
||||
end_test(name, "skip", reason)
|
||||
def skip_test(self, name, reason=None):
|
||||
self.end_test(name, "skip", reason)
|
||||
|
||||
def fail_test(self, name, reason=None):
|
||||
self.end_test(name, "fail", reason)
|
||||
|
||||
def fail_test(name, reason=None):
|
||||
end_test(name, "fail", reason)
|
||||
def success_test(self, name, reason=None):
|
||||
self.end_test(name, "success", reason)
|
||||
|
||||
def xfail_test(self, name, reason=None):
|
||||
self.end_test(name, "xfail", reason)
|
||||
|
||||
def success_test(name, reason=None):
|
||||
end_test(name, "success", reason)
|
||||
def report_time(self, t):
|
||||
(sec, min, hour, mday, mon, year, wday, yday, isdst) = time.localtimet(t)
|
||||
print "time: %04d-%02d-%02d %02d:%02d:%02d" % (year+1900, mon+1, mday, hour, min, sec)
|
||||
|
||||
def xfail_test(name, reason=None):
|
||||
end_test(name, "xfail", reason)
|
||||
# The following are Samba extensions:
|
||||
def start_testsuite(self, name):
|
||||
print "testsuite: %s" % name
|
||||
|
||||
def report_time(t):
|
||||
(sec, min, hour, mday, mon, year, wday, yday, isdst) = time.localtimet(t)
|
||||
print "time: %04d-%02d-%02d %02d:%02d:%02d" % (year+1900, mon+1, mday, hour, min, sec)
|
||||
def skip_testsuite(self, name, reason=None):
|
||||
if reason:
|
||||
print "skip-testsuite: %s [\n%s\n]" % (name, reason)
|
||||
else:
|
||||
print "skip-testsuite: %s" % name
|
||||
|
||||
def end_testsuite(self, name, result, reason=None):
|
||||
if reason:
|
||||
print "testsuite-$result: %s [" % name
|
||||
print "%s" % reason
|
||||
print "]"
|
||||
else:
|
||||
print "testsuite-$result: %s" % name
|
||||
|
||||
# The following are Samba extensions:
|
||||
def start_testsuite(name):
|
||||
print "testsuite: %s" % name
|
||||
|
||||
def skip_testsuite(name, reason=None):
|
||||
if reason:
|
||||
print "skip-testsuite: %s [\n%s\n]" % (name, reason)
|
||||
else:
|
||||
print "skip-testsuite: %s" % name
|
||||
|
||||
def end_testsuite(name, result, reason=None):
|
||||
if reason:
|
||||
print "testsuite-$result: %s [" % name
|
||||
print "%s" % reason
|
||||
print "]"
|
||||
else:
|
||||
print "testsuite-$result: %s" % name
|
||||
|
||||
def testsuite_count(count):
|
||||
print "testsuite-count: %d" % count
|
||||
def testsuite_count(self, count):
|
||||
print "testsuite-count: %d" % count
|
||||
|
Loading…
x
Reference in New Issue
Block a user