diff --git a/python/samba/subunit/__init__.py b/python/samba/subunit/__init__.py index 7b609c3ef79..f452db6dde5 100644 --- a/python/samba/subunit/__init__.py +++ b/python/samba/subunit/__init__.py @@ -16,3 +16,31 @@ # """Subunit test protocol.""" + +import datetime + + +PROGRESS_SET = 0 +PROGRESS_CUR = 1 +PROGRESS_PUSH = 2 +PROGRESS_POP = 3 + + +# From http://docs.python.org/library/datetime.html +_ZERO = datetime.timedelta(0) + +# A UTC class. + +class UTC(datetime.tzinfo): + """UTC""" + + def utcoffset(self, dt): + return _ZERO + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return _ZERO + +utc = UTC() diff --git a/python/samba/subunit/run.py b/python/samba/subunit/run.py index 33efd4f6f76..dbe6b241c82 100755 --- a/python/samba/subunit/run.py +++ b/python/samba/subunit/run.py @@ -24,6 +24,8 @@ $ python -m samba.subunit.run mylib.tests.test_suite """ +from samba.subunit import UTC + import datetime import os import sys @@ -31,25 +33,6 @@ import traceback import unittest -# From http://docs.python.org/library/datetime.html -_ZERO = datetime.timedelta(0) - -# A UTC class. - -class UTC(datetime.tzinfo): - """UTC""" - - def utcoffset(self, dt): - return _ZERO - - def tzname(self, dt): - return "UTC" - - def dst(self, dt): - return _ZERO - -utc = UTC() - # Whether or not to hide layers of the stack trace that are # unittest/testtools internal code. Defaults to True since the # system-under-test is rarely unittest or testtools. diff --git a/selftest/run.py b/selftest/run.py index 222ac8b1a8b..b7638f0daa8 100644 --- a/selftest/run.py +++ b/selftest/run.py @@ -18,10 +18,9 @@ """Test command running.""" import datetime -from subunit import iso8601 import os import subprocess -import subunit +from samba import subunit import sys import tempfile import warnings @@ -89,7 +88,7 @@ def exported_envvars_str(vars, names): def now(): """Return datetime instance for current time in UTC. """ - return datetime.datetime.utcnow().replace(tzinfo=iso8601.Utc()) + return datetime.datetime.utcnow().replace(tzinfo=subunit.UTC()) def run_testsuite_command(name, cmd, subunit_ops, env=None, outf=None): diff --git a/selftest/tests/test_run.py b/selftest/tests/test_run.py index 35f99e83c75..829f488cf85 100644 --- a/selftest/tests/test_run.py +++ b/selftest/tests/test_run.py @@ -21,7 +21,10 @@ import datetime import os -import subunit +from samba.subunit import ( + PROGRESS_PUSH, + PROGRESS_POP, + ) import tempfile from selftest.run import ( @@ -133,10 +136,10 @@ class RunTestsuiteCommandTests(TestCase): exit_code = run_testsuite_command("thetestsuitename", "echo doing something", subunit_ops, outf=outf) self.assertEquals([ ("start-testsuite", "thetestsuitename"), - ("progress", None, subunit.PROGRESS_PUSH), + ("progress", None, PROGRESS_PUSH), ("time", ), ("time", ), - ("progress", None, subunit.PROGRESS_POP), + ("progress", None, PROGRESS_POP), ("end-testsuite", "thetestsuitename", "success", None), ], subunit_ops.calls) self.assertEquals(0, exit_code) @@ -153,10 +156,10 @@ expanded command: echo doing something exit_code = run_testsuite_command("thetestsuitename", "exit 3", subunit_ops, outf=outf) self.assertEquals([ ("start-testsuite", "thetestsuitename"), - ("progress", None, subunit.PROGRESS_PUSH), + ("progress", None, PROGRESS_PUSH), ("time", ), ("time", ), - ("progress", None, subunit.PROGRESS_POP), + ("progress", None, PROGRESS_POP), ("end-testsuite", "thetestsuitename", "failure", "Exit code was 3"), ], subunit_ops.calls) self.assertEquals(3, exit_code) @@ -173,10 +176,10 @@ expanded command: exit 3 "thisisacommandthatdoesnotexist 2>/dev/null", subunit_ops, outf=outf) self.assertEquals([ ("start-testsuite", "thetestsuitename"), - ("progress", None, subunit.PROGRESS_PUSH), + ("progress", None, PROGRESS_PUSH), ("time", ), ("time", ), - ("progress", None, subunit.PROGRESS_POP), + ("progress", None, PROGRESS_POP), ("end-testsuite", "thetestsuitename", "failure", "Exit code was 127"), ], subunit_ops.calls) self.assertEquals(127, exit_code)