summaryrefslogtreecommitdiff
path: root/src/distutils2/command
diff options
context:
space:
mode:
authorKonrad Delong <konryd@gmail.com>2010-07-27 14:56:41 +0200
committerKonrad Delong <konryd@gmail.com>2010-07-27 14:56:41 +0200
commit860dc98c3aa066ef573efa4d5f9508e4c8f86696 (patch)
tree4f1577617208e39a37185dfbb38710281f823634 /src/distutils2/command
parentb31034c2a10e884c4abd76cbe63d3fbcc663dc32 (diff)
downloaddisutils2-860dc98c3aa066ef573efa4d5f9508e4c8f86696.tar.gz
test loader with dotted syntax now working
Diffstat (limited to 'src/distutils2/command')
-rw-r--r--src/distutils2/command/test.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/distutils2/command/test.py b/src/distutils2/command/test.py
index b2b985c..043f22c 100644
--- a/src/distutils2/command/test.py
+++ b/src/distutils2/command/test.py
@@ -2,16 +2,39 @@ import os, sys
from distutils2.core import Command
import unittest
+def get_loader_instance(dotted_path):
+ if dotted_path is None:
+ return None
+ module_name, rest = dotted_path.split('.')[0], dotted_path.split('.')[1:]
+ while True:
+ try:
+ ret = __import__(module_name)
+ break
+ except ImportError:
+ if rest == []:
+ return None
+ module_name += ('.' + rest[0])
+ rest = rest[1:]
+ while rest:
+ try:
+ ret = getattr(ret, rest.pop(0))
+ except AttributeError:
+ return None
+ return ret()
+
class test(Command):
description = "" # TODO
user_options = [
- ('test-suite=','s',
+ ('test-suite=', 's',
"Test suite to run (e.g. 'some_module.test_suite')"),
+ ('test-loader=', None,
+ "Test loader to be used to load the test suite."),
]
def initialize_options(self):
- self.test_suite = None
+ self.test_suite = None
+ self.test_loader = None
def finalize_options(self):
self.build_lib = self.get_finalized_command("build").build_lib
@@ -21,9 +44,15 @@ class test(Command):
try:
if self.distribution.has_ext_modules():
build = self.get_reinitialized_command('build')
- build.inplace = 1
+ build.inplace = 1 # TODO - remove make sure it's needed
self.run_command('build')
os.chdir(self.build_lib)
- unittest.main(module=self.test_suite, argv=sys.argv[:1])
+ args = {"module": self.test_suite,
+ "argv": sys.argv[:1],
+ "testLoader": get_loader_instance(self.test_loader)
+ }
+ if args['testLoader'] is None:
+ del args['testLoader']
+ unittest.main(**args)
finally:
os.chdir(prev_cwd)