class nosetests(Command): description = "Run unit tests using nosetests" __config = Config(files=user_config_files(), plugins=DefaultPluginManager()) __parser = __config.getParser() user_options = get_user_options(__parser) def initialize_options(self): """create the member variables, but change hyphens to underscores """ self.option_to_cmds = {} for opt in self.__parser.option_list: cmd_name = opt._long_opts[0][2:] option_name = cmd_name.replace('-', '_') self.option_to_cmds[option_name] = cmd_name setattr(self, option_name, None) self.attr = None def finalize_options(self): """nothing to do here""" pass def run(self): """ensure tests are capable of being run, then run nose.main with a reconstructed argument list""" self.run_command('egg_info') # Build extensions in-place self.reinitialize_command('build_ext', inplace=1) self.run_command('build_ext') 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) argv = ['nosetests'] for (option_name, cmd_name) in self.option_to_cmds.items(): if option_name in option_blacklist: continue value = getattr(self, option_name) if value is not None: argv.extend( self.cfgToArg(option_name.replace('_', '-'), value)) TestProgram(argv=argv, config=self.__config) def cfgToArg(self, optname, value): argv = [] if flag(value): if _bool(value): argv.append('--' + optname) else: argv.extend(['--' + optname, value]) return argv
class DummyNose(Command): description = "Dummy" manager = PluginManager() manager.plugins = [RandomlyPlugin()] __config = Config(files=user_config_files(), plugins=manager) __parser = __config.getParser() user_options = nose.commands.get_user_options(__parser) def initialize_options(self): pass def finalize_options(self): pass def run(self): pass
class nosetests(Command): description = "Run unit tests using nosetests" __config = Config(files=user_config_files(), plugins=DefaultPluginManager()) __parser = __config.getParser() user_options = get_user_options(__parser) def initialize_options(self): """create the member variables, but change hyphens to underscores """ self.option_to_cmds = {} for opt in self.__parser.option_list: cmd_name = opt._long_opts[0][2:] option_name = cmd_name.replace('-', '_') self.option_to_cmds[option_name] = cmd_name setattr(self, option_name, None) self.attr = None def finalize_options(self): """nothing to do here""" pass def run(self): """ensure tests are capable of being run, then run nose.main with a reconstructed argument list""" if 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 = 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: self.run_command('egg_info') # Build extensions in-place self.reinitialize_command('build_ext', inplace=1) self.run_command('build_ext') 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) ei_cmd = self.get_finalized_command("egg_info") argv = ['nosetests', '--where', ei_cmd.egg_base] for (option_name, cmd_name) in self.option_to_cmds.items(): if option_name in option_blacklist: continue value = getattr(self, option_name) if value is not None: argv.extend( self.cfgToArg(option_name.replace('_', '-'), value)) TestProgram(argv=argv, config=self.__config) def cfgToArg(self, optname, value): argv = [] long_optname = '--' + optname opt = self.__parser.get_option(long_optname) if opt.action in ('store_true', 'store_false'): if not flag(value): raise ValueError("Invalid value '%s' for '%s'" % ( value, optname)) if _bool(value): argv.append(long_optname) else: argv.extend([long_optname, value]) return argv