summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2014-11-01 21:08:49 -0700
committerJelmer Vernooij <jelmer@samba.org>2014-11-22 02:23:10 +0100
commit24035a6b3ed5ffdb1e75ebd375c3f7c2129742ff (patch)
treeb7b7c636a58fde0cc89a2c1a9c4a82236ed49a1d
parented4c07b34b5571c021684e3df6bf5fc63cde69c5 (diff)
downloadsamba-24035a6b3ed5ffdb1e75ebd375c3f7c2129742ff.tar.gz
Move option parsing to samba.tests.subunitrun.
Change-Id: I2939c1b6ebb9739530efa9bc4667668cff7a7aeb Signed-off-by: Jelmer Vernooij <jelmer@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
-rw-r--r--python/samba/tests/subunitrun.py27
-rwxr-xr-xsource4/dsdb/tests/python/dirsync.py2
-rwxr-xr-xsource4/scripting/bin/subunitrun4
3 files changed, 23 insertions, 10 deletions
diff --git a/python/samba/tests/subunitrun.py b/python/samba/tests/subunitrun.py
index 78632f364ac..abb98813dbf 100644
--- a/python/samba/tests/subunitrun.py
+++ b/python/samba/tests/subunitrun.py
@@ -28,18 +28,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-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())
diff --git a/source4/dsdb/tests/python/dirsync.py b/source4/dsdb/tests/python/dirsync.py
index 2de77366ec5..a480518790c 100755
--- a/source4/dsdb/tests/python/dirsync.py
+++ b/source4/dsdb/tests/python/dirsync.py
@@ -702,4 +702,4 @@ if getattr(opts, 'load_list', None):
args.insert(0, "--load-list=%s" % opts.load_list)
-TestProgram(module=__name__, argv=[sys.argv[0]] + args)
+TestProgram(module=__name__)
diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun
index c85fc97fb2f..48b507a7b41 100755
--- a/source4/scripting/bin/subunitrun
+++ b/source4/scripting/bin/subunitrun
@@ -39,7 +39,7 @@ sys.path.insert(0, "bin/python")
import optparse
import samba
-from samba.tests.subunitrun import TestProgram
+from samba.tests.subunitrun import TestProgram, SubunitOptions
import samba.getopt as options
import samba.tests
@@ -71,8 +71,10 @@ parser = optparse.OptionParser(usage=usage, description=description)
parser.format_description = format_description
credopts = options.CredentialsOptions(parser)
sambaopts = options.SambaOptions(parser)
+subunitopts = SubunitOptions(parser)
parser.add_option_group(credopts)
parser.add_option_group(sambaopts)
+parser.add_option_group(subunitopts)
opts, args = parser.parse_args()