def print_results(self, outdir=None): if outdir: report = HTMLReport(self.analyzer) report.write_to_directory(outdir) else: for (signature, matching_calls) in self.analyzer.get_findings(): if matching_calls: print "# %s" % signature if isinstance(signature, str) else signature.description for traced_call in matching_calls: print " %s" % traced_call
def run(self, options): config = Config() config.pretty_diff = options['pretty_diff'] doc = options['tests'] if os.path.isdir(doc): docs_dir = doc else: docs_dir = os.path.dirname(doc) report = HTMLReport(docs_dir, options['refs_dir'], options['out_dir']) report.create()
def run(self, options): config = Config() config.pretty_diff = options['pretty_diff'] config.abs_paths = options['use_abs_paths'] doc = options['tests'] if os.path.isdir(doc): docs_dir = doc else: docs_dir = os.path.dirname(doc) report = HTMLReport(docs_dir, options['refs_dir'], options['out_dir']) report.create(options['launch_browser']) return 0
def cycle_dir(self): print("Grading") for entry in os.scandir(self.dir): if entry.path.endswith(".py") and entry.is_file and \ entry.name not in ['grader_old.py', 'test.py', 'solution.py', '__init__.py']: print(entry.name) self.test_program(entry.name) print("Done") # Maybe a Reporter becomes an input CSVReport(dir=self.dir, filename=self.csv_report_file).report_csv(self.results) HTMLReport(dir=self.dir, filename=self.html_report_file, results=self.results, rubric=self.rubric)
def test_reporter(self): f = open('rub.json', 'r') rubric = json.load(f) f.close() module = 'solution.py' g = Grader(dir='', rubric_definition=rubric, interpreter='python3', timeout=10) module = os.path.join(currentdir, 'bug_solution.py') module = os.path.join(currentdir, 'stud1.py') student_score: StudentScore = g.test_program(module) n = extract_name(module) HTMLReport(dir=currentdir, results=g.results, rubric=g.rubric, filename="tab.html")
def active(cls, suite=suite, report_name='index'): cls.stream() # cls.check() if os.path.exists(report()): shutil.rmtree(report()) os.makedirs(report()) os.makedirs(BI_protal.downloadpath) assert os.path.exists(BI_protal.driver_path), "chromedriver.exe 不存在" cls.start() HTMLReport.TestRunner( # report_file_name='BI_6.0.7_BeiJing_3_13_2日报周报', report_file_name=report_name, output_path=report('report'), title="BI-PORTAL 测试报告", description="描述测试项目相关信息", sequential_execution=True, lang='cn').run(suite())
def LoadAndRunTestCases(self): curTime = time.strftime("%Y%m%d%H%M%S", time.localtime()) path = os.path.dirname(LOG_PATH + os.sep) name = 'testReport' + str(curTime) suite = unittest.TestSuite() runner = HTMLReport.TestRunner(name, path) for testSet in sorted(self.testSuitlist): url = self.testSuitlist[testSet]["url"] driverType = self.testSuitlist[testSet]["browserType"] print(driverType + "###" + url) d = None if driverType == "chrome": d = webdriver.Chrome(executable_path=CHROMEDRIVER) d.get(url) testCases = self.testSuitlist[testSet]["caseSet"] for case in testCases: print(case) d.get("about:")
def printAndWriteResult(self, flawMap, baseDir, scannerList, title): mainResult = ComparisonResultHolder() scannerResults = OrderedDict() securityModelResultMap = OrderedDict() scannerResults['JULIET'] = ComparisonResultHolder() securityModelResultMap['JULIET'] = SecurityModelComparision(self.securityModel,'JULIET') root = ET.Element("analyzereport") details = ET.SubElement(root, "details") for sc in scannerList: scannerResults[sc.name] = ComparisonResultHolder() securityModelResultMap[sc.name] = SecurityModelComparision(self.securityModel,sc.name) for key, issueComparison in flawMap.items(): issueComparison.compareIssues() #print(key) if(len(issueComparison.existingIssues) >0): totalIssues = 1 else: totalIssues = 0 #print("totalIssues="+str(totalIssues)) mainResult.issueCnt+=totalIssues fileIssue = ET.SubElement(details, 'file', {'totalIssues' : str(totalIssues), 'name' : issueComparison.fileName}) for scanner, issueHolder in issueComparison.foundIssues.items(): #print("\tSecurity-Scanner: "+scanner) #print("\t\tfound issues="+str(len(issueHolder.foundIssues))) #print("\t\tcorrectMath="+str(issueHolder.correctMatchCnt)) secModelResult = securityModelResultMap[scanner] comparisonResult = scannerResults.get(scanner) comparisonResult.addIssue(issueComparison,issueHolder) secModelResult.addIssueComparision(issueComparison) if(scanner!='JULIET'): scannerXMLResult = ET.SubElement(fileIssue, 'scanner', {'name' : scanner, 'foundIssues': str(len(issueHolder.foundIssues)),'realIssues': str(len(issueComparison.existingIssues)), 'correctLineMatches' : str(issueHolder.correctMatchCnt), 'differentLineMatches' : str(issueHolder.differentLineMatches), 'differentTypeMatches' : str(issueHolder.rangeMatch), 'differentTypeMatches' : str(issueHolder.rangeMatch), 'noneMatching' : str(issueComparison.noneMatching)}) print("=============================") print("========"+title+" SUMMARY========") print("=============================") print("Total Issues: "+str(mainResult.issueCnt)) print("Scanners: ") summary = ET.SubElement(root, 'summary', {'totalIssues' : str(mainResult.issueCnt)}) chartData = OrderedDict() chartData['Total Issues'] = mainResult.issueCnt for key, value in scannerResults.items(): if(scanner!='JULIET'): summaryDetail = value.getXMLSubelement(summary, 'scanner', key) print(key+" found "+str(value.issueCnt)+" of "+str(value.realIssues)) value.printDetailData() #print("\t"+str(value.withoutCWE)+" CWE") chartData[key] = value.issueCnt self.printPieChart(key, value, baseDir) secModelXML = ET.SubElement(root, 'securityModel') for key, value in securityModelResultMap.items(): compareResultMap = value.compare() if(scanner!='JULIET'): scannerXML = ET.SubElement(secModelXML, 'scanner', {'name' : key}) print(key) for weaknessClass, resultHolder in compareResultMap.items(): resultHolder.getXMLSubelement(scannerXML, 'weaknessClass', weaknessClass) print(weaknessClass) resultHolder.printDetailData() #write xml with open(baseDir+'report.xml', 'w') as f: f.write(parseString(ET.tostring(root)).toprettyxml()) self.printChart(chartData, baseDir, title) htmlReport = HTMLReport(mainResult, scannerResults, securityModelResultMap, baseDir+"report.html") htmlReport.buildReport()
def printAndWriteResult(self, flawMap, baseDir, scannerList, title): mainResult = ComparisonResultHolder() scannerResults = OrderedDict() securityModelResultMap = OrderedDict() scannerResults['JULIET'] = ComparisonResultHolder() securityModelResultMap['JULIET'] = SecurityModelComparision( self.securityModel, 'JULIET') root = ET.Element("analyzereport") details = ET.SubElement(root, "details") for sc in scannerList: scannerResults[sc.name] = ComparisonResultHolder() securityModelResultMap[sc.name] = SecurityModelComparision( self.securityModel, sc.name) for key, issueComparison in flawMap.items(): issueComparison.compareIssues() #print(key) if (len(issueComparison.existingIssues) > 0): totalIssues = 1 else: totalIssues = 0 #print("totalIssues="+str(totalIssues)) mainResult.issueCnt += totalIssues fileIssue = ET.SubElement(details, 'file', { 'totalIssues': str(totalIssues), 'name': issueComparison.fileName }) for scanner, issueHolder in issueComparison.foundIssues.items(): #print("\tSecurity-Scanner: "+scanner) #print("\t\tfound issues="+str(len(issueHolder.foundIssues))) #print("\t\tcorrectMath="+str(issueHolder.correctMatchCnt)) secModelResult = securityModelResultMap[scanner] comparisonResult = scannerResults.get(scanner) comparisonResult.addIssue(issueComparison, issueHolder) secModelResult.addIssueComparision(issueComparison) if (scanner != 'JULIET'): scannerXMLResult = ET.SubElement( fileIssue, 'scanner', { 'name': scanner, 'foundIssues': str(len(issueHolder.foundIssues)), 'realIssues': str(len(issueComparison.existingIssues)), 'correctLineMatches': str(issueHolder.correctMatchCnt), 'differentLineMatches': str(issueHolder.differentLineMatches), 'differentTypeMatches': str(issueHolder.rangeMatch), 'differentTypeMatches': str(issueHolder.rangeMatch), 'noneMatching': str(issueComparison.noneMatching) }) print("=============================") print("========" + title + " SUMMARY========") print("=============================") print("Total Issues: " + str(mainResult.issueCnt)) print("Scanners: ") summary = ET.SubElement(root, 'summary', {'totalIssues': str(mainResult.issueCnt)}) chartData = OrderedDict() chartData['Total Issues'] = mainResult.issueCnt for key, value in scannerResults.items(): if (scanner != 'JULIET'): summaryDetail = value.getXMLSubelement(summary, 'scanner', key) print(key + " found " + str(value.issueCnt) + " of " + str(value.realIssues)) value.printDetailData() #print("\t"+str(value.withoutCWE)+" CWE") chartData[key] = value.issueCnt self.printPieChart(key, value, baseDir) secModelXML = ET.SubElement(root, 'securityModel') for key, value in securityModelResultMap.items(): compareResultMap = value.compare() if (scanner != 'JULIET'): scannerXML = ET.SubElement(secModelXML, 'scanner', {'name': key}) print(key) for weaknessClass, resultHolder in compareResultMap.items(): resultHolder.getXMLSubelement(scannerXML, 'weaknessClass', weaknessClass) print(weaknessClass) resultHolder.printDetailData() #write xml with open(baseDir + 'report.xml', 'w') as f: f.write(parseString(ET.tostring(root)).toprettyxml()) self.printChart(chartData, baseDir, title) htmlReport = HTMLReport(mainResult, scannerResults, securityModelResultMap, baseDir + "report.html") htmlReport.buildReport()
import time import unittest from test_suites.loginsuite import make_suite from lib.HTMLTestRunner import HTMLTestRunner from HTMLReport import HTMLReport if __name__ == "__main__": # runtime = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) # reportname = "test_result_{}.html".format(runtime) # with open("reports/{}".format(reportname), 'wb') as f: # runner = HTMLTestRunner(stream = f, # title='ECshop自动化登录测试报告', # description='CI版本测试结果', # verbosity=2 # ) # runner.run(make_suite()) HTMLReport.TestRunner(thread_count=3).run(make_suite())
import unittest, os from HTMLReport import HTMLReport import time # test_dir = './' # 表示脚本当前路径 test_dir = os.path.dirname(os.getcwd()) + '/TestCase' # 表示脚本当前路径 discovery = unittest.defaultTestLoader.discover( test_dir, pattern='test*.py') # 匹配所有的test开头的.py文件 if __name__ == '__main__': # 测试用例执行器 runner = HTMLReport.TestRunner( report_file_name='', # 报告文件名,如果未赋值,将采用“test+时间戳” output_path='report', # 保存文件夹名,默认“report” title='测试报告', # 报告标题,默认“测试报告” description='无测试描述', # 报告描述,默认“测试描述” thread_count=1, # 并发线程数量(无序执行测试),默认数量 1 thread_start_wait=0, # 各线程启动延迟,默认 0 s sequential_execution=False, # 是否按照套件添加(addTests)顺序执行, # 会等待一个addTests执行完成,再执行下一个,默认 False # 如果用例中存在 tearDownClass ,建议设置为True, # 否则 tearDownClass 将会在所有用例线程执行完后才会执行。 # lang='en' lang='cn' # 支持中文与英文,默认中文 ) # 执行测试用例套件 runner.run(discovery)
outputsdir = arg def parse(line): if len(line) == 0 or line[0] == '#': return None return line.strip() celist = map(parse, celist_file) # parse lines and mark comments as None celist = filter(lambda x: x, celist) # remove all Nones tdir = testNo print 'USING:', tdir report = HTMLReport() report.beginDocument('LCG2 worker node capability scan: ' + testNo) testscript = 'test_wn_capabilities' shutil.copy(testscript, tdir) report.addParagraph(HTMLMarkup('capability testing script', link=testscript)) i = -1 for ce in celist: i += 1 print 'analysing output of', i, '', ce testcasename = "test_x_%d" % (i, ) fo = "%s/%s" % ( tdir, testcasename,