def render_report(self, report, filename, log_dir, template): template_env = Environment( loader=FileSystemLoader(template_path.strpath) ) data = template_env.get_template(template).render(**report) with open(os.path.join(log_dir, '{}.html'.format(filename)), "w") as f: f.write(data) try: shutil.copytree(template_path.join('dist').strpath, os.path.join(log_dir, 'dist')) except OSError: pass
# if we finish the loop and no group is found, add it else: params = sorted([param for param in group.params if prov in param]) the_group = Group(params) this_suite.groups.append(the_group) # break here as the suite is found and has the right group now break # If the suite is not found, then we create it, and the group else: the_suite = copy.deepcopy(suite) prov_suites[prov].append(the_suite) the_suite.groups = [] params = sorted([param for param in group.params if prov in param]) the_group = Group(params) the_suite.groups.append(the_group) # once we are sure we have the right suite and group, we simple append the # test to the suites groups # darn jinja needing data in the right format the_tests = copy.deepcopy(group.tests) the_group.tests = the_tests # write the page for the specific prov data = template_env.get_template('test_matrix.html').render({'suites': prov_suites[prov]}) with open(os.path.join(log_path.strpath, '{}.html'.format(prov)), "w") as f: f.write(data) try: shutil.copytree(template_path.join('dist').strpath, os.path.join(log_path.strpath, 'dist')) except OSError: pass
def run_report(self, artifacts, log_dir): template_env = Environment( loader=FileSystemLoader(template_path.strpath) ) template_data = {'tests': []} log_dir += "/" counts = {'passed': 0, 'failed': 0, 'skipped': 0, 'error': 0, 'xfailed': 0, 'xpassed': 0} colors = {'passed': 'success', 'failed': 'warning', 'error': 'danger', 'xpassed': 'danger', 'xfailed': 'success', 'skipped': 'info'} # Iterate through the tests and process the counts and durations for test_name, test in artifacts.iteritems(): if not test.get('statuses', None): continue overall_status = overall_test_status(test['statuses']) counts[overall_status] += 1 color = colors[overall_status] # Set the overall status and then process duration test['statuses']['overall'] = overall_status test_data = {'name': test_name, 'outcomes': test['statuses'], 'slaveid': test.get('slaveid', "Unknown"), 'color': color} if test.get('start_time', None): if test.get('finish_time', None): test_data['in_progress'] = False test_data['duration'] = test['finish_time'] - test['start_time'] else: test_data['duration'] = time.time() - test['start_time'] test_data['in_progress'] = True # Set up destinations for the files for ident in test.get('files', []): if "softassert" in ident: clean_files = [] for assertion in test['files']['softassert']: files = {k: v.replace(log_dir, "") for k, v in assertion.iteritems()} clean_files.append(files) test_data['softassert'] = sorted(clean_files) continue for filename in test['files'].get(ident, []): if "screenshot" in filename: test_data['screenshot'] = filename.replace(log_dir, "") elif "short-traceback" in filename: test_data['short_tb'] = open(filename).read() elif "traceback" in filename: test_data['full_tb'] = filename.replace(log_dir, "") elif "video" in filename: test_data['video'] = filename.replace(log_dir, "") elif "cfme.log" in filename: test_data['cfme'] = filename.replace(log_dir, "") elif "function" in filename: test_data['function'] = filename.replace(log_dir, "") elif "emails.html" in filename: test_data['emails'] = filename.replace(log_dir, "") elif "events.html" in filename: test_data['event_testing'] = filename.replace(log_dir, "") elif "qa_contact.txt" in filename: with open(filename) as qafile: test_data['qa_contact'] = qafile.read() if "merkyl" in ident: test_data['merkyl'] = [f.replace(log_dir, "") for f in test['files']['merkyl']] template_data['tests'].append(test_data) template_data['counts'] = counts # Create the tree dict that is used for js tree # Note template_data['tests'] != tests tests = deepcopy(_tests_tpl) tests['_sub']['tests'] = deepcopy(_tests_tpl) for test in template_data['tests']: self.build_dict(test['name'].replace('cfme/', ''), tests, test) template_data['ndata'] = self.build_li(tests) # Sort the test output and if necessary discard tests that have passed template_data['tests'] = sorted(template_data['tests'], key=itemgetter('name')) for test in template_data['tests']: if test.get('duration', None): test['duration'] = str(datetime.timedelta( seconds=math.ceil(test['duration']))) if self.only_failed: template_data['tests'] = [x for x in template_data['tests'] if x['outcomes']['overall'] not in ['passed']] # Render the report data = template_env.get_template('test_report.html').render(**template_data) with open(os.path.join(log_dir, 'report.html'), "w") as f: f.write(data) try: shutil.copytree(template_path.join('dist').strpath, os.path.join(log_dir, 'dist')) except OSError: pass
def run_report(self, artifacts, log_dir): template_env = Environment( loader=FileSystemLoader(template_path.strpath) ) template_data = {'tests': []} log_dir += "/" counts = {'passed': 0, 'failed': 0, 'skipped': 0, 'error': 0, 'xfailed': 0, 'xpassed': 0} for test_name, test in artifacts.iteritems(): if not test.get('statuses', None): continue overall_status = None for when, status in test['statuses'].iteritems(): if when == "call" and status[1] and status[0] == "skipped": counts['xfailed'] += 1 overall_status = "xfailed" break elif when == "call" and status[1] and status[0] == "failed": counts['xpassed'] += 1 overall_status = "xpassed" break elif (when == "setup" or when == "teardown") and status[0] == "failed": counts['error'] += 1 overall_status = "error" break elif status[0] == "skipped": counts['skipped'] += 1 overall_status = "skipped" break elif when == "call" and status[0] == 'failed': counts['failed'] += 1 overall_status = "failed" break else: counts['passed'] += 1 overall_status = "passed" test['statuses']['overall'] = overall_status test_data = {'name': test_name, 'outcomes': test['statuses']} if test.get('start_time', None): if test.get('finish_time', None): test_data['in_progress'] = False test_data['duration'] = test['finish_time'] - test['start_time'] else: test_data['duration'] = time.time() - test['start_time'] test_data['in_progress'] = True for ident in test.get('files', []): for filename in test['files'].get(ident, []): if "screenshot" in filename: test_data['screenshot'] = filename.replace(log_dir, "") elif "short-traceback" in filename: test_data['short_tb'] = open(filename).read() elif "traceback" in filename: test_data['full_tb'] = filename.replace(log_dir, "") elif "video" in filename: test_data['video'] = filename.replace(log_dir, "") elif "cfme.log" in filename: test_data['cfme'] = filename.replace(log_dir, "") elif "function" in filename: test_data['function'] = filename.replace(log_dir, "") if "merkyl" in ident: test_data['merkyl'] = [f.replace(log_dir, "") for f in test['files']['merkyl']] template_data['tests'].append(test_data) template_data['counts'] = counts tests = {'_sub': {'tests': {'_sub': {}, '_stats': { 'passed': 0, 'failed': 0, 'skipped': 0, 'error': 0, 'xpassed': 0, 'xfailed': 0}}}, '_stats': {'passed': 0, 'failed': 0, 'skipped': 0, 'error': 0, 'xpassed': 0, 'xfailed': 0}} for test in template_data['tests']: self.build_dict(test['name'].replace('cfme/', ''), tests, test) template_data['ndata'] = self.build_li(tests) if self.only_failed: template_data['tests'] = [x for x in template_data['tests'] if x['outcomes']['overall'] not in ['skipped', 'passed']] data = template_env.get_template('test_report.html').render(**template_data) with open(os.path.join(log_dir, 'report.html'), "w") as f: f.write(data) try: shutil.copytree(template_path.join('dist').strpath, os.path.join(log_dir, 'dist')) except OSError: pass
this_suite.groups.append(the_group) # break here as the suite is found and has the right group now break # If the suite is not found, then we create it, and the group else: the_suite = copy.deepcopy(suite) prov_suites[prov].append(the_suite) the_suite.groups = [] params = sorted( [param for param in group.params if prov in param]) the_group = Group(params) the_suite.groups.append(the_group) # once we are sure we have the right suite and group, we simple append the # test to the suites groups # darn jinja needing data in the right format the_tests = copy.deepcopy(group.tests) the_group.tests = the_tests # write the page for the specific prov data = template_env.get_template('test_matrix.html').render( {'suites': prov_suites[prov]}) with open(os.path.join(log_path.strpath, '{}.html'.format(prov)), "w") as f: f.write(data) try: shutil.copytree( template_path.join('dist').strpath, os.path.join(log_path.strpath, 'dist')) except OSError: pass