diff options
| author | Konrad Delong <konryd@gmail.com> | 2010-08-05 18:17:38 +0200 |
|---|---|---|
| committer | Konrad Delong <konryd@gmail.com> | 2010-08-05 18:17:38 +0200 |
| commit | 485b7447701a6927f4304dcdb0f4b2b45edcbf5f (patch) | |
| tree | e86e0835cd7d10c42a0a41774c773a3405c9977c /src/distutils2/command | |
| parent | af4263388c51b2b1b0f4f01bf15473050487e476 (diff) | |
| parent | 9da67de95ddac89371ae85e609003fee0331723f (diff) | |
| download | disutils2-485b7447701a6927f4304dcdb0f4b2b45edcbf5f.tar.gz | |
merged from upstream
Diffstat (limited to 'src/distutils2/command')
| -rw-r--r-- | src/distutils2/command/test.py | 65 | ||||
| -rw-r--r-- | src/distutils2/command/upload_docs.py | 3 |
2 files changed, 67 insertions, 1 deletions
diff --git a/src/distutils2/command/test.py b/src/distutils2/command/test.py new file mode 100644 index 0000000..8bbaac2 --- /dev/null +++ b/src/distutils2/command/test.py @@ -0,0 +1,65 @@ +import os, sys +from distutils2.core import Command +from distutils2._backport.pkgutil import get_distribution +import unittest +import warnings + +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 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_loader = None + + def finalize_options(self): + self.build_lib = self.get_finalized_command("build").build_lib + if self.distribution.tests_require: + for requirement in self.distribution.tests_require: + if get_distribution(requirement) is None: + warnings.warn("The test dependency %s is not installed which may couse the tests to fail.", + RuntimeWarning) + + def run(self): + prev_cwd = os.getcwd() + try: + if self.distribution.has_ext_modules(): + build = self.get_reinitialized_command('build') + build.inplace = 1 # TODO - remove make sure it's needed + self.run_command('build') + os.chdir(self.build_lib) + 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) diff --git a/src/distutils2/command/upload_docs.py b/src/distutils2/command/upload_docs.py index 86b2c33..4f6915a 100644 --- a/src/distutils2/command/upload_docs.py +++ b/src/distutils2/command/upload_docs.py @@ -94,9 +94,10 @@ class upload_docs(Command): def run(self): name = self.distribution.metadata['Name'] + version = self.distribution.metadata['Version'] zip_file = zip_dir(self.upload_dir) - fields = {':action': 'doc_upload', 'name': name}.items() + fields = [(':action', 'doc_upload'), ('name', name), ('version', version)] files = [('content', name, zip_file.getvalue())] content_type, body = encode_multipart(fields, files) |
