from setuptools import Command from distutils.errors import DistutilsOptionError import sys from pkg_resources import * from pkg_resources import _namespace_packages from unittest import TestLoader, main class ScanningLoader(TestLoader): def loadTestsFromModule(self, module): """Return a suite of all tests cases contained in the given module If the module is a package, load tests from all the modules in it. If the module has an ``additional_tests`` function, call it and add the return value to the tests. """ tests = [] if module.__name__!='setuptools.tests.doctest': # ugh tests.append(TestLoader.loadTestsFromModule(self,module)) if hasattr(module, "additional_tests"): tests.append(module.additional_tests()) if hasattr(module, '__path__'): for file in resource_listdir(module.__name__, ''): if file.endswith('.py') and file!='__init__.py': submodule = module.__name__+'.'+file[:-3] else: if resource_exists( module.__name__, file+'/__init__.py' ): submodule = module.__name__+'.'+file else: continue tests.append(self.loadTestsFromName(submodule)) if len(tests)!=1: return self.suiteClass(tests) else: return tests[0] # don't create a nested suite for only one return class test(Command): """Command to run unit tests after in-place build""" description = "run unit tests after in-place build" user_options = [ ('test-module=','m', "Run 'test_suite' in specified module"), ('test-suite=','s', "Test suite to run (e.g. 'some_module.test_suite')"), ] def initialize_options(self): self.test_suite = None self.test_module = None self.test_loader = None def finalize_options(self): if self.test_suite is None: if self.test_module is None: self.test_suite = self.distribution.test_suite else: self.test_suite = self.test_module+".test_suite" elif self.test_module: raise DistutilsOptionError( "You may specify a module or a suite, but not both" ) self.test_args = [self.test_suite] if self.verbose: self.test_args.insert(0,'--verbose') if self.test_loader is None: self.test_loader = getattr(self.distribution,'test_loader',None) if self.test_loader is None: self.test_loader = "setuptools.command.test:ScanningLoader" def with_project_on_sys_path(self, func): if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): # If we run 2to3 we can not do this inplace: # Ensure metadata is up-to-date self.reinitialize_command('build_py', inplace=0) self.run_command('build_py') bpy_cmd = self.get_finalized_command("build_py") build_path = normalize_path(bpy_cmd.build_lib) # Build extensions self.reinitialize_command('egg_info', egg_base=build_path) self.run_command('egg_info') self.reinitialize_command('build_ext', inplace=0) self.run_command('build_ext') else: # Without 2to3 inplace works fine: self.run_command('egg_info') # Build extensions in-place self.reinitialize_command('build_ext', inplace=1) self.run_command('build_ext') ei_cmd = self.get_finalized_command("egg_info") old_path = sys.path[:] old_modules = sys.modules.copy() try: sys.path.insert(0, normalize_path(ei_cmd.egg_base)) working_set.__init__() add_activation_listener(lambda dist: dist.activate()) require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version)) func() finally: sys.path[:] = old_path sys.modules.clear() sys.modules.update(old_modules) working_set.__init__() def run(self): if self.distribution.install_requires: self.distribution.fetch_build_eggs(self.distribution.install_requires) if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) if self.test_suite: cmd = ' '.join(self.test_args) if self.dry_run: self.announce('skipping "unittest %s" (dry run)' % cmd) else: self.announce('running "unittest %s"' % cmd) self.with_project_on_sys_path(self.run_tests) def run_tests(self): import unittest # Purge modules under test from sys.modules. The test loader will # re-import them from the build location. Required when 2to3 is used # with namespace packages. if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): module = self.test_args[-1].split('.')[0] if module in _namespace_packages: del_modules = [] if module in sys.modules: del_modules.append(module) module += '.' for name in sys.modules: if name.startswith(module): del_modules.append(name) list(map(sys.modules.__delitem__, del_modules)) loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) cks = loader_class() unittest.main( None, None, [unittest.__file__]+self.test_args, testLoader = cks )
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.__init__.pyo.40009 | File | 911 B | 0644 |
|
.alias.pyo.40009 | File | 3.16 KB | 0644 |
|
.bdist_egg.pyo.40009 | File | 18.18 KB | 0644 |
|
.bdist_rpm.pyo.40009 | File | 2.24 KB | 0644 |
|
.bdist_wininst.pyo.40009 | File | 2.33 KB | 0644 |
|
.build_py.pyo.40009 | File | 11.38 KB | 0644 |
|
.develop.pyo.40009 | File | 5.68 KB | 0644 |
|
.easy_install.pyo.40009 | File | 65.69 KB | 0644 |
|
.egg_info.pyo.40009 | File | 17.27 KB | 0644 |
|
.install.pyo.40009 | File | 3.67 KB | 0644 |
|
.install_egg_info.pyo.40009 | File | 4.56 KB | 0644 |
|
.install_scripts.pyo.40009 | File | 2.54 KB | 0644 |
|
.register.pyo.40009 | File | 692 B | 0644 |
|
.rotate.pyo.40009 | File | 2.88 KB | 0644 |
|
.saveopts.pyo.40009 | File | 1.2 KB | 0644 |
|
.sdist.pyo.40009 | File | 9.92 KB | 0644 |
|
.setopt.pyo.40009 | File | 5.91 KB | 0644 |
|
.test.pyo.40009 | File | 5.76 KB | 0644 |
|
__init__.py | File | 689 B | 0644 |
|
__init__.pyc | File | 911 B | 0644 |
|
__init__.pyo | File | 911 B | 0644 |
|
alias.py | File | 2.43 KB | 0644 |
|
alias.pyc | File | 3.16 KB | 0644 |
|
alias.pyo | File | 3.16 KB | 0644 |
|
bdist_egg.py | File | 18.28 KB | 0644 |
|
bdist_egg.pyc | File | 18.18 KB | 0644 |
|
bdist_egg.pyo | File | 18.18 KB | 0644 |
|
bdist_rpm.py | File | 1.98 KB | 0644 |
|
bdist_rpm.pyc | File | 2.24 KB | 0644 |
|
bdist_rpm.pyo | File | 2.24 KB | 0644 |
|
bdist_wininst.py | File | 2.23 KB | 0644 |
|
bdist_wininst.pyc | File | 2.33 KB | 0644 |
|
bdist_wininst.pyo | File | 2.33 KB | 0644 |
|
build_ext.py | File | 11.58 KB | 0644 |
|
build_ext.pyc | File | 10.08 KB | 0644 |
|
build_ext.pyo | File | 10.04 KB | 0644 |
|
build_py.py | File | 10.29 KB | 0644 |
|
build_py.pyc | File | 11.38 KB | 0644 |
|
build_py.pyo | File | 11.38 KB | 0644 |
|
develop.py | File | 6.3 KB | 0644 |
|
develop.pyc | File | 5.68 KB | 0644 |
|
develop.pyo | File | 5.68 KB | 0644 |
|
easy_install.py | File | 73.07 KB | 0755 |
|
easy_install.pyc | File | 65.69 KB | 0644 |
|
easy_install.pyo | File | 65.69 KB | 0644 |
|
egg_info.py | File | 15.42 KB | 0644 |
|
egg_info.pyc | File | 17.27 KB | 0644 |
|
egg_info.pyo | File | 17.27 KB | 0644 |
|
install.py | File | 3.97 KB | 0644 |
|
install.pyc | File | 3.67 KB | 0644 |
|
install.pyo | File | 3.67 KB | 0644 |
|
install_egg_info.py | File | 3.74 KB | 0644 |
|
install_egg_info.pyc | File | 4.56 KB | 0644 |
|
install_egg_info.pyo | File | 4.56 KB | 0644 |
|
install_lib.py | File | 2.43 KB | 0644 |
|
install_lib.pyc | File | 3.14 KB | 0644 |
|
install_lib.pyo | File | 3.1 KB | 0644 |
|
install_scripts.py | File | 2.02 KB | 0644 |
|
install_scripts.pyc | File | 2.54 KB | 0644 |
|
install_scripts.pyo | File | 2.54 KB | 0644 |
|
register.py | File | 277 B | 0644 |
|
register.pyc | File | 692 B | 0644 |
|
register.pyo | File | 692 B | 0644 |
|
rotate.py | File | 2.01 KB | 0644 |
|
rotate.pyc | File | 2.88 KB | 0644 |
|
rotate.pyo | File | 2.88 KB | 0644 |
|
saveopts.py | File | 705 B | 0644 |
|
saveopts.pyc | File | 1.2 KB | 0644 |
|
saveopts.pyo | File | 1.2 KB | 0644 |
|
sdist.py | File | 9.6 KB | 0644 |
|
sdist.pyc | File | 9.92 KB | 0644 |
|
sdist.pyo | File | 9.92 KB | 0644 |
|
setopt.py | File | 4.95 KB | 0644 |
|
setopt.pyc | File | 5.91 KB | 0644 |
|
setopt.pyo | File | 5.91 KB | 0644 |
|
test.py | File | 5.79 KB | 0644 |
|
test.pyc | File | 5.76 KB | 0644 |
|
test.pyo | File | 5.76 KB | 0644 |
|
upload.py | File | 6.57 KB | 0644 |
|
upload.pyc | File | 6.28 KB | 0644 |
|
upload.pyo | File | 6.26 KB | 0644 |
|
upload_docs.py | File | 6.81 KB | 0644 |
|
upload_docs.pyc | File | 7.01 KB | 0644 |
|
upload_docs.pyo | File | 6.98 KB | 0644 |
|