def run_suite(self, nose_argv): signals.before_suite_run.send(sender=self) result_plugin = ResultPlugin() plugins_to_add = [ DjangoSetUpPlugin(self), result_plugin, TestReorderer() ] for plugin in _get_plugins_from_settings(): plugins_to_add.append(plugin) cfg_files = all_config_files() manager = DefaultPluginManager() config = Config(env=os.environ, files=cfg_files, plugins=manager) config.plugins.addPlugins(plugins=plugins_to_add) text_test_runner = XMLTextNoseTestRunner(config=config, verbosity=self.verbosity) nose.core.TestProgram(argv=nose_argv, exit=False, config=config, testRunner=text_test_runner) result = result_plugin.result if self.with_reports: result.dump_xml(self.output_dir) signals.after_suite_run.send(sender=self) return result
def makeNoseConfig(env): """Load a Config, pre-filled with user config files if any are found. """ cfg_files = all_config_files() manager = DefaultPluginManager() return Config(env=env, files=cfg_files, plugins=manager)
def run_suite(self, nose_argv): signals.before_suite_run.send(sender=self) result_plugin = ResultPlugin() plugins_to_add = [DjangoSetUpPlugin(self), result_plugin, TestReorderer()] for plugin in _get_plugins_from_settings(): plugins_to_add.append(plugin) cfg_files = all_config_files() manager = DefaultPluginManager() config = Config(env=os.environ, files=cfg_files, plugins=manager) config.plugins.addPlugins(plugins=plugins_to_add) text_test_runner = XMLTextNoseTestRunner(config=config, verbosity=self.verbosity) nose.core.TestProgram(argv=nose_argv, exit=False, config=config, testRunner=text_test_runner) result = result_plugin.result if self.with_reports: result.dump_xml(self.output_dir) signals.after_suite_run.send(sender=self) return result
def collector(): """TestSuite replacement entry point. Use anywhere you might use a unittest.TestSuite. The collector will, by default, load options from all config files and execute loader.loadTestsFromNames() on the configured testNames, or '.' if no testNames are configured. """ # plugins that implement any of these methods are disabled, since # we don't control the test runner and won't be able to run them # finalize() is also not called, but plugins that use it aren't disabled, # because capture needs it. setuptools_incompat = ('report', 'prepareTest', 'prepareTestLoader', 'prepareTestRunner', 'setOutputStream') plugins = RestrictedPluginManager(exclude=setuptools_incompat) conf = Config(files=all_config_files(), plugins=plugins) conf.configure(argv=['collector']) loader = defaultTestLoader(conf) if conf.testNames: suite = loader.loadTestsFromNames(conf.testNames) else: suite = loader.loadTestsFromNames(('.',)) return FinalizingSuiteWrapper(suite, plugins.finalize)
def run_nose(self, params): """ :type params: Params """ thread.set_index(params.thread_index) log.debug("[%s] Starting nose iterations: %s", params.worker_index, params) assert isinstance(params.tests, list) # argv.extend(['--with-apiritif', '--nocapture', '--exe', '--nologcapture']) end_time = self.params.ramp_up + self.params.hold_for end_time += time.time() if end_time else 0 time.sleep(params.delay) plugin = ApiritifPlugin() store.writer.concurrency += 1 config = Config(env=os.environ, files=all_config_files(), plugins=DefaultPluginManager()) config.plugins.addPlugins(extraplugins=[plugin]) config.testNames = params.tests config.verbosity = 3 if params.verbose else 0 if params.verbose: config.stream = open( os.devnull, "w") # FIXME: use "with", allow writing to file/log iteration = 0 try: while True: log.debug("Starting iteration:: index=%d,start_time=%.3f", iteration, time.time()) thread.set_iteration(iteration) ApiritifTestProgram(config=config) log.debug("Finishing iteration:: index=%d,end_time=%.3f", iteration, time.time()) iteration += 1 # reasons to stop if plugin.stop_reason: log.debug("[%s] finished prematurely: %s", params.worker_index, plugin.stop_reason) elif 0 < params.iterations <= iteration: log.debug("[%s] iteration limit reached: %s", params.worker_index, params.iterations) elif 0 < end_time <= time.time(): log.debug("[%s] duration limit reached: %s", params.worker_index, params.hold_for) else: continue # continue if no one is faced break finally: store.writer.concurrency -= 1 if params.verbose: config.stream.close()
def run_nose(self, params): """ :type params: Params """ log.debug("[%s] Starting nose iterations: %s", params.worker_index, params) print("%s:%s" % (params.worker_index, params.thread_index)) assert isinstance(params.tests, list) # argv.extend(['--with-apiritif', '--nocapture', '--exe', '--nologcapture']) end_time = self.params.ramp_up + self.params.hold_for end_time += time.time() if end_time else 0 time.sleep(params.delay) iteration = 0 local_data.total_concurrency = params.total_concurrency local_data.thread_index = params.thread_index plugin = ApiritifPlugin(self._writer) self._writer.concurrency += 1 config = Config(env=os.environ, files=all_config_files(), plugins=DefaultPluginManager()) config.plugins.addPlugins(extraplugins=[plugin]) config.testNames = params.tests config.verbosity = 3 if params.verbose else 0 if params.verbose: config.stream = open( os.devnull, "w") # FIXME: use "with", allow writing to file/log try: while True: local_data.iteration = iteration iteration += 1 log.debug("Starting iteration:: index=%d,start_time=%.3f", iteration, time.time()) ApiritifTestProgram(config=config) log.debug("Finishing iteration:: index=%d,end_time=%.3f", iteration, time.time()) if iteration >= params.iterations: log.debug("[%s] iteration limit reached: %s", params.worker_index, params.iterations) break if 0 < end_time <= time.time(): log.debug("[%s] duration limit reached: %s", params.worker_index, params.hold_for) break finally: self._writer.concurrency -= 1 if params.verbose: config.stream.close()
def all_config_files(options): ''' Get the list of configuration files. ''' # Get default configuration files files = config.all_config_files() # Get files from options files.extend(getattr(options, 'selenose_configs', [])) # Return the full list return files
def makeConfig(self, env, plugins=None): """Load a Config, pre-filled with user config files if any are found. """ cfg_files = all_config_files() if plugins: manager = PluginManager(plugins=plugins) else: manager = DefaultPluginManager() return Config(env=env, files=cfg_files, plugins=manager)
def run_nose(): #{{{ argv = list(sys.argv) execpath = op.realpath(argv[0]) testdir = op.abspath(op.dirname(execpath)) if len(argv) == 1: argv.extend(['doc', 'unit']) os.chdir(testdir) env = os.environ cfg_files = all_config_files() config = Config(env=env, files=cfg_files, plugins=NosePluginManager()) TestProgram(argv=argv, env=env, config=config)
def get_nosetest_cmd_attribute_val(attribute): env = os.environ manager = nose_manager.DefaultPluginManager() cfg_files = nose_config.all_config_files() tmp_config = nose_config.Config(env=env, files=cfg_files, plugins=manager) tmp_config.configure() try: attr_list = getattr(tmp_config.options, 'attr') value = dict(token.split('=') for token in attr_list) return value[attribute] except TypeError: return None
def all_config_files(options, conf): ''' Get the list of configuration files. ''' # Get default configuration files files = config.all_config_files() # Get the files from configuration files.extend(getattr(conf, 'files', [])) # Check if options has files if getattr(options, 'files', []): # Get files from options files.extend(options.files) # Return the full list return files
standalone.initialize(name='python') from maya import cmds elif app_name == 'nuke': from units import nuke as app_specific import nuke elif app_name == 'houdini': pass os.environ['KIKO_APP_NAME'] = app_name kiko.initialize() current_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) nose_config = os.path.join(current_dir, 'config', 'nose.cfg') config_files = [nose_config] + all_config_files() c = Config(env=os.environ, files=config_files, plugins=DefaultPluginManager()) app_s_loader = nose.loader.TestLoader() if unit_test is None: app_s_suite = app_s_loader.loadTestsFromModule(app_specific) else: app_s_suite = app_s_loader.loadTestsFromName(unit_test) test_suite = nose.suite.ContextSuite() test_suite.addTest(app_s_suite) sys.exit(nose.main(config=c, suite=test_suite))
def test_getAllConfigFiles(self): self.assertEqual(self.program.getAllConfigFiles(), all_config_files())
def getAllConfigFiles(self, env=None): env = env or {} if env.get('NOSE_IGNORE_CONFIG_FILES', False): return [] else: return all_config_files()
def run(): import argparse parser = argparse.ArgumentParser(description='Run TestBenches.') parser.add_argument('--max_configs', type=int) parser.add_argument('--run_desert', action='store_true') parser.add_argument('model_file') parser.add_argument('nose_options', nargs=argparse.REMAINDER) command_line_args = parser.parse_args() project = Dispatch("Mga.MgaProject") mga_file = command_line_args.model_file if mga_file.endswith('.xme'): project = Dispatch("Mga.MgaProject") parser = Dispatch("Mga.MgaParser") resolver = Dispatch("Mga.MgaResolver") resolver.IsInteractive = False parser.Resolver = resolver mga_file = os.path.splitext( command_line_args.model_file)[0] + ".mga" project.Create("MGA=" + os.path.abspath(mga_file), "CyPhyML") parser.ParseProject(project, command_line_args.model_file) else: # n.b. without abspath, things break (e.g. CyPhy2CAD) project.OpenEx( "MGA=" + os.path.abspath(command_line_args.model_file), "CyPhyML", None) project.BeginTransactionInNewTerr() try: if command_line_args.run_desert: desert = Dispatch("MGA.Interpreter.DesignSpaceHelper") desert.Initialize(project) filter = project.CreateFilter() filter.Kind = "DesignContainer" # FIXME wont work right for TBs that point to non-root design sace designContainers = [ tb for tb in project.AllFCOs(filter) if not tb.IsLibObject and tb.ParentFolder is not None ] for designContainer in designContainers: desert.InvokeEx(project, designContainer, Dispatch("MGA.MgaFCOs"), 128) def add_fail(masterContext, configName, message): def fail(self): raise ValueError(message) fail.__name__ = str('test_' + masterContext.Name + "__" + configName) setattr(TestBenchTest, fail.__name__, fail) def add_test(masterContext, mi_config, config): def testTestBench(self): self._testTestBench(masterContext, master, mi_config) # testTestBench.__name__ = str('test_' + masterContext.Name + "_" + masterContext.ID + "__" + config.Name) testTestBench.__name__ = str('test_' + masterContext.Name + "__" + config.Name) setattr(TestBenchTest, testTestBench.__name__, testTestBench) master = Dispatch( "CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI") master.Initialize(project) modelKinds = set( ("TestBench", "CADTestBench", "KinematicTestBench", "BlastTestBench", "BallisticTestBench", "CarTestBench", "CFDTestBench", "ParametricExploration")) # masterContexts = [tb for tb in itertools.chain(*(project.AllFCOs(filter) for filter in filters)) if not tb.IsLibObject] masterContexts = list( crawlForKinds(project.RootFolder, ("ParametricExplorationFolder", "Testing"), modelKinds)) print repr([t.Name for t in masterContexts]) for masterContext in masterContexts: configs = None if masterContext.Meta.Name == "ParametricExploration": tbs = [ tb for tb in masterContext.ChildFCOs if tb.MetaBase.Name == 'TestBenchRef' and tb.Referred is not None ] if not tbs: configs = [masterContext] else: testBench = tbs[0].Referred else: testBench = masterContext if not configs: suts = [ sut for sut in testBench.ChildFCOs if sut.MetaRole.Name == 'TopLevelSystemUnderTest' ] if len(suts) == 0: add_fail( masterContext, 'invalid', 'Error: TestBench "{}" has no TopLevelSystemUnderTest' .format(testBench.Name)) continue if len(suts) > 1: add_fail( masterContext, 'invalid', 'Error: TestBench "{}" has more than one TopLevelSystemUnderTest' .format(testBench.Name)) continue sut = suts[0] if sut.Referred.MetaBase.Name == 'ComponentAssembly': configs = [sut.Referred] else: configurations = [ config for config in sut.Referred.ChildFCOs if config.MetaBase.Name == 'Configurations' ] if not configurations: add_fail( masterContext, 'invalid', 'Error: design has no Configurations models. Try using the --run_desert option' ) continue configurations = configurations[0] cwcs = [ cwc for cwc in configurations.ChildFCOs if cwc.MetaBase.Name == 'CWC' and cwc.Name ] if not cwcs: raise ValueError( 'Error: could not find CWCs for "{}"'.format( testBench.Name)) configs = list(cwcs) # FIXME cfg2 > cfg10 configs.sort(key=operator.attrgetter('Name')) configs = configs[slice(0, command_line_args.max_configs)] for config in configs: mi_config = Dispatch( "CyPhyMasterInterpreter.ConfigurationSelectionLight") # GME id, or guid, or abs path or path to Test bench or SoT or PET mi_config.ContextId = masterContext.ID mi_config.SetSelectedConfigurationIds([config.ID]) # mi_config.KeepTemporaryModels = True mi_config.PostToJobManager = False add_test(masterContext, mi_config, config) finally: project.CommitTransaction() config = Config(files=all_config_files(), plugins=BuiltinPluginManager()) config.configure(argv=['nose'] + command_line_args.nose_options) loader = TestLoader(config=config) tests = [loader.loadTestsFromTestClass(TestBenchTest)] try: nose.core.TestProgram(suite=tests, argv=['nose'] + command_line_args.nose_options, exit=True, testLoader=loader, config=config) finally: # project.Save(project.ProjectConnStr + "_debug.mga", True) project.Close(True)
def __init__(self, name, app): """ Init command :param name: Name of the command :type name: str :param app: The application :type app: edmunds.application.Application """ super(TestCommand, self).__init__(name, app) # Fetch nose options config = Config(env=os.environ, files=all_config_files(), plugins=DefaultPluginManager()) nose_options = config.getParser(doc=TestProgram.usage()).option_list # Override run-function to be able to load the click-options dynamically # Dynamic click.option does not work for class-methods because of __click_params__ original_function = self.run def run_wrapper(**kwargs): return original_function(**kwargs) self.run = run_wrapper # Don't show --help nose_options = filter( lambda nose_option: '--help' not in nose_option._long_opts, nose_options) for nose_option in nose_options: args = nose_option._short_opts + nose_option._long_opts if not args: continue type_mapping = { 'string': str, 'int': int, 'long': int, 'float': float, # 'complex': str, # 'choice': str, } unsupported_attr = ['action', 'dest', 'const'] kwargs = {} for attr in OptParseOption.ATTRS: if attr in unsupported_attr: continue attr_value = getattr(nose_option, attr) if attr_value is None: continue if attr == 'type': attr_value = type_mapping[attr_value] if nose_option.nargs > 1: attr_value = click.Tuple([attr_value]) if attr == 'default': if attr_value == optparse.NO_DEFAULT: continue kwargs[attr] = attr_value click.option(*args[:2], **kwargs)(run_wrapper)