1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

subunit: Use subunit standard functions for handling time and progress.

This commit is contained in:
Jelmer Vernooij 2010-09-13 21:31:08 +02:00
parent fb1c966652
commit 1626dc2bc9
2 changed files with 15 additions and 35 deletions

View File

@ -14,10 +14,10 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
import subunithelper
import subunit
import testtools
def format_time(t):
minutes, seconds = divmod(t, 60)
def format_time(delta):
minutes, seconds = divmod(delta.seconds, 60)
hours, minutes = divmod(minutes, 60)
ret = ""
if hours:
@ -57,10 +57,10 @@ class PlainFormatter(subunithelper.TestsuiteEnabledTestResult):
elif whence == subunit.PROGRESS_CUR:
raise NotImplementedError
def report_time(self, time):
def time(self, dt):
if self.start_time is None:
self.start_time = time
self.last_time = time
self.start_time = dt
self.last_time = dt
def start_testsuite(self, name):
self.index += 1

View File

@ -20,8 +20,8 @@ __all__ = ['parse_results']
import re
import sys
import subunit
import subunit.iso8601
import testtools
import time
VALID_RESULTS = ['success', 'successful', 'failure', 'fail', 'skip', 'knownfail', 'error', 'xfail', 'skip-testsuite', 'testsuite-failure', 'testsuite-xfail', 'testsuite-success', 'testsuite-error']
@ -51,15 +51,12 @@ def parse_results(msg_ops, statistics, fh):
open_tests.append(arg.rstrip())
elif command == "time":
msg_ops.control_msg(l)
grp = re.match(
'(\d+)-(\d+)-(\d+) (\d+):(\d+):([.0-9]+)\n', arg)
if grp is None:
grp = re.match(
'(\d+)-(\d+)-(\d+) (\d+):(\d+):([.0-9]+)Z\n', arg)
if grp is None:
print "Unable to parse time line: %s" % arg
if grp is not None:
msg_ops.report_time(time.mktime((int(grp.group(1)), int(grp.group(2)), int(grp.group(3)), int(grp.group(4)), int(grp.group(5)), int(float(grp.group(6))), 0, 0, 0)))
try:
dt = subunit.iso8601.parse_date(arg.rstrip("\n"))
except TypeError, e:
print "Unable to parse time line: %s" % arg.rstrip("\n")
else:
msg_ops.time(dt)
elif command in VALID_RESULTS:
msg_ops.control_msg(l)
result = command
@ -195,23 +192,6 @@ class SubunitOps(subunit.TestProtocolClient,TestsuiteEnabledTestResult):
def xfail_test(self, name, reason=None):
self.end_test(name, "xfail", reason)
def report_time(self, t):
(year, mon, mday, hour, min, sec, wday, yday, isdst) = time.localtime(t)
self._stream.write("time: %04d-%02d-%02d %02d:%02d:%02d\n" % (year, mon, mday, hour, min, sec))
def progress(self, offset, whence):
if whence == subunit.PROGRESS_CUR and offset > -1:
prefix = "+"
elif whence == subunit.PROGRESS_PUSH:
prefix = ""
offset = "push"
elif whence == subunit.PROGRESS_POP:
prefix = ""
offset = "pop"
else:
prefix = ""
self._stream.write("progress: %s%s\n" % (prefix, offset))
# The following are Samba extensions:
def start_testsuite(self, name):
self._stream.write("testsuite: %s\n" % name)
@ -261,8 +241,8 @@ class FilterOps(testtools.testresult.TestResult):
def control_msg(self, msg):
pass # We regenerate control messages, so ignore this
def report_time(self, time):
self._ops.report_time(time)
def time(self, time):
self._ops.time(time)
def progress(self, delta, whence):
self._ops.progress(delta, whence)