def autohelp_directive(dirname, arguments, options, content, lineno, content_offset, block_text, state, state_machine): """produces rst from nose help""" config = Config(parserClass=OptBucket, plugins=BuiltinPluginManager()) parser = config.getParser(TestProgram.usage()) rst = ViewList() for line in parser.format_help().split('\n'): rst.append(line, '<autodoc>') rst.append('Options', '<autodoc>') rst.append('-------', '<autodoc>') rst.append('', '<autodoc>') for opt in parser: rst.append(opt.options(), '<autodoc>') rst.append(' \n', '<autodoc>') rst.append(' ' + opt.help + '\n', '<autodoc>') rst.append('\n', '<autodoc>') node = nodes.section() node.document = state.document surrounding_title_styles = state.memo.title_styles surrounding_section_level = state.memo.section_level state.memo.title_styles = [] state.memo.section_level = 0 state.nested_parse(rst, 0, node, match_titles=1) state.memo.title_styles = surrounding_title_styles state.memo.section_level = surrounding_section_level return node.children
print("Commands...") cmds = publish_parts(nose.commands.__doc__, reader=DocReader(), writer_name='html') docs['commands'] = cmds['body'] print("Changelog...") changes = open(os.path.join(root, 'CHANGELOG'), 'r').read() changes_html = publish_parts(changes, reader=DocReader(), writer_name='html') docs['changelog'] = changes_html['body'] print("News...") news = open(os.path.join(root, 'NEWS'), 'r').read() news_html = publish_parts(news, reader=DocReader(), writer_name='html') docs['news'] = news_html['body'] print("Usage...") conf = Config(plugins=BuiltinPluginManager()) usage_txt = conf.help(nose.main.__doc__).replace('mkindex.py', 'nosetests') docs['usage'] = '<pre>%s</pre>' % usage_txt out = tpl % docs index = open(os.path.join(root, 'index.html'), 'w') index.write(out) index.close() readme = open(os.path.join(root, 'README.txt'), 'w') readme.write(nose.__doc__) readme.close()
def usage(): conf = Config(plugins=BuiltinPluginManager()) usage_text = conf.help(nose.main.__doc__).replace('mkwiki.py', 'nosetests') out = '{{{\n%s\n}}}\n' % usage_text return out
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)