From 24035a6b3ed5ffdb1e75ebd375c3f7c2129742ff Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Nov 2014 21:08:49 -0700 Subject: Move option parsing to samba.tests.subunitrun. Change-Id: I2939c1b6ebb9739530efa9bc4667668cff7a7aeb Signed-off-by: Jelmer Vernooij Reviewed-by: Andrew Bartlett --- python/samba/tests/subunitrun.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/samba/tests/subunitrun.py b/python/samba/tests/subunitrun.py index 78632f364a..abb98813db 100644 --- a/python/samba/tests/subunitrun.py +++ b/python/samba/tests/subunitrun.py @@ -28,18 +28,15 @@ # along with this program. If not, see . # -import sys - # make sure the script dies immediately when hitting control-C, # rather than raising KeyboardInterrupt. As we do all database # operations using transactions, this is safe. import signal signal.signal(signal.SIGINT, signal.SIG_DFL) -# Find right directory when running from source tree -sys.path.insert(0, "bin/python") - +import optparse import samba +import sys samba.ensure_external_module("mimeparse", "mimeparse") samba.ensure_external_module("extras", "extras") samba.ensure_external_module("testtools", "testtools") @@ -47,13 +44,27 @@ samba.ensure_external_module("subunit", "subunit/python") import subunit.run try: - from subunit.run import TestProgram + from subunit.run import TestProgram as BaseTestProgram except ImportError: - from unittest import TestProgram + from unittest import TestProgram as BaseTestProgram + + +class SubunitOptions(optparse.OptionGroup): + """Command line options for subunit test runners.""" + + def __init__(self, parser): + optparse.OptionGroup.__init__(self, parser, "Subunit Options") + self.add_option('-l', '--list', dest='listtests', default=False, + help='List tests rather than running them.', + action="store_true") + self.add_option('--load-list', dest='load_list', default=None, + help='Specify a filename containing the test ids to use.') -class TestProgram(TestProgram): +class TestProgram(BaseTestProgram): def __init__(self, module=None, argv=None): + if argv is None: + argv = [sys.argv[0]] super(TestProgram, self).__init__(module=module, argv=argv, testRunner=subunit.run.SubunitTestRunner()) -- cgit