subunitrun: Use unittest.TestProgram if subunit.TestProgram is not
authorJelmer Vernooij <jelmer@samba.org>
Fri, 10 Dec 2010 02:03:18 +0000 (03:03 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 10 Dec 2010 02:49:03 +0000 (03:49 +0100)
available.

Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Fri Dec 10 03:49:03 CET 2010 on sn-devel-104

source4/scripting/bin/subunitrun
source4/scripting/python/samba/__init__.py

index 21243a73ec5aca4d0a7fcbf7d7f165118b4f50b2..bc7b42c610c38d9f9626e22198ca5d37c548f1e5 100755 (executable)
@@ -26,12 +26,7 @@ import optparse
 import samba
 samba.ensure_external_module("testtools", "testtools")
 samba.ensure_external_module("subunit", "subunit/python")
-try:
-    from subunit.run import SubunitTestRunner, TestProgram
-except ImportError:
-    samba.force_bundled_package("testtools", "testtools")
-    samba.force_bundled_package("subunit", "subunit/python")
-    from subunit.run import SubunitTestRunner, TestProgram
+from subunit.run import SubunitTestRunner
 import samba.getopt as options
 import samba.tests
 
@@ -39,15 +34,20 @@ import samba.tests
 parser = optparse.OptionParser("subunitrun [options] <tests>")
 credopts = options.CredentialsOptions(parser)
 parser.add_option_group(credopts)
-parser.add_option('-l', '--list', dest='listtests', default=False,
-                  help='List tests rather than running them.',
-                  action="store_true")
+try:
+    from subunit.run import TestProgram
+except ImportError:
+    from unittest import TestProgram
+else:
+    parser.add_option('-l', '--list', dest='listtests', default=False,
+                      help='List tests rather than running them.',
+                      action="store_true")
 
 opts, args = parser.parse_args()
 
 samba.tests.cmdline_credentials = credopts.get_credentials(samba.tests.env_loadparm())
-if opts.listtests:
+if getattr(opts, "listtests", False):
     args.insert(0, "--list")
 
 runner = SubunitTestRunner()
-program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner, stdout=sys.stdout)
+program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner)
index 6fcac16691ee85af90722701faa0c31abd14ee22..5294368b6dc5c76574a28a54d9ccb8fc4996e6a9 100644 (file)
@@ -318,27 +318,12 @@ def import_bundled_package(modulename, location):
         sys.path.insert(0,
             os.path.join(os.path.dirname(__file__),
                          "../../../../lib", location))
-        __import__(modulename)
+        sys.modules[modulename] = __import__(modulename)
     else:
         sys.modules[modulename] = __import__(
             "samba.external.%s" % modulename, fromlist=["samba.external"])
 
 
-def force_bundled_package(packagename, location):
-    """Forcibly use the bundled package.
-
-    This will first unload the system module and then load the bundled one.
-
-    :param packagename: The package name
-    :param location: Location to add to sys.path (can be relative to
-        ${srcdir}/lib)
-    """
-    for m in sys.modules.keys():
-        if m.startswith("%s." % packagename):
-            del sys.modules[m]
-    import_bundled_package(packagename, location)
-
-
 def ensure_external_module(modulename, location):
     """Add a location to sys.path if an external dependency can't be found.