def test_branch_coverage(self): project_root = CLEAN_LINKED_LIST_ROOT # trace_root = create_new_temp_dir() trace_root = CLEAN_LINKED_LIST_ROOT exclude_folders = ["venv", "dataset"] cfg = ProjectCFG.create_from_path(project_root, exclude_folders=exclude_folders, use_cached_if_possible=False) thorough.run_tests(CLEAN_LINKED_LIST_ROOT, trace_root, exclude_folders) trace_reader = TraceReader(trace_root) ll_py = str(CLEAN_LINKED_LIST_LL) ll_py_cfg = cfg.module_cfgs[ll_py] total_exercised = set() available_branches = ll_py_cfg.branches for node_id, path in zip(*trace_reader.get_traces_for(ll_py)): df, size = read_as_dataframe(path) covered = find_covered_branches(df, ll_py_cfg.branches) total_exercised.update(covered) print("Coverage") print_percent("Branches covered", total_exercised, ll_py_cfg.branches) print(available_branches) print(total_exercised) not_exercised_branches = set(available_branches) - set(total_exercised) print("Not exercised branches total ({}): ".format(len(not_exercised_branches)), not_exercised_branches) self.assertEqual(13, len(not_exercised_branches))
def test_intra_method_pairs(self): len_pairs = [ 9, 8, 13, 19, 3, 20, 8, 5, 18, 16, 12, 19, 3, 18, 18, 24, 9, 2, 8 ] project_root = CLEAN_LINKED_LIST_ROOT trace_root = create_new_temp_dir() exclude_folders = ["venv"] cfg = ProjectCFG.create_from_path(project_root, exclude_folders=exclude_folders) thorough.run_tests(CLEAN_LINKED_LIST_ROOT, trace_root, exclude_folders) trace_reader = TraceReader(trace_root) cppvi = VarIndexFactory.new_cpp_index(project_root, trace_root) ll_py = str(CLEAN_LINKED_LIST_LL) def get_pairs(trace_file_path): np_array, _ = read_as_np_array(trace_file_path) idx_pairs = analyze_trace_w_index(trace_file_path, cppvi) def rename_vars(s): return {(el[0], el[1]) for el in s} idx_pairs = rename_vars(idx_pairs) return idx_pairs node_ids, paths = trace_reader.get_traces_for(ll_py) for node_id, path, expected_pairs_count in zip(node_ids, paths, len_pairs): pairs = get_pairs(path) self.assertEqual( expected_pairs_count, len(pairs), "Pairs count don't match for test case: {}".format(node_id))
def test_def_use_coverage(self): project_root = CLEAN_LINKED_LIST_ROOT trace_root = create_new_temp_dir() exclude_folders = ["venv", "dataset"] thorough.run_tests(project_root, trace_root, exclude_folders) coverage = DefUsePairsCoverage(trace_root, project_root, exclude_folders=exclude_folders) report = coverage.report() # check that there are no NaN values in report self.assertFalse(report.isnull().values.any())
def test_inter_method_pairs_test_interclass_pairs(self): len_im_pairs = [ 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ] len_ic_pairs = [ 5, 2, 5, 4, 1, 4, 2, 1, 5, 5, 7, 4, 1, 10, 7, 5, 9, 1, 4 ] project_root = CLEAN_LINKED_LIST_ROOT trace_root = create_new_temp_dir() exclude_folders = ["venv"] cfg = ProjectCFG.create_from_path(project_root, exclude_folders=exclude_folders) thorough.run_tests(CLEAN_LINKED_LIST_ROOT, trace_root, exclude_folders) trace_reader = TraceReader(trace_root) cppvi = VarIndexFactory.new_py_index(project_root, trace_root) ll_py = str(CLEAN_LINKED_LIST_LL) def get_pairs(trace_file_path): np_array, _ = read_as_np_array(trace_file_path) scopes = read_scopes_for_trace_file(trace_file_path) im_pairs, ic_pairs = analyze(trace_file_path, cppvi, scopes) def rename_vars(s): return {(el[0], el[1]) for el in s} im_pairs = rename_vars(im_pairs) ic_pairs = rename_vars(ic_pairs) return im_pairs, ic_pairs node_ids, paths = trace_reader.get_traces_for(ll_py) for node_id, path, expected_im_len, expected_ic_len in zip( node_ids, paths, len_im_pairs, len_ic_pairs): im_pairs, ic_pairs = get_pairs(path) self.assertEqual( expected_im_len, len(im_pairs), "Intermethod pairs count don't match for test case: {}".format( node_id)) self.assertEqual( expected_ic_len, len(ic_pairs), "Intermethod pairs count don't match for test case: {}".format( node_id))
def test_merge_reports(self): pd.options.display.float_format = '{:,.2f}'.format pd.options.display.width = 0 project_root = CLEAN_LINKED_LIST_ROOT.parent / "dictionary" trace_root = create_new_temp_dir() exclude_folders = ["venv", "dataset"] thorough.run_tests(project_root, trace_root, exclude_folders) stcoverage = StatementCoverage(trace_root, project_root, exclude_folders=exclude_folders, max_trace_size=30) brcoverage = BranchCoverage(trace_root, project_root, exclude_folders=exclude_folders, max_trace_size=30) ducoverage = DefUsePairsCoverage(trace_root, project_root, exclude_folders=exclude_folders, max_trace_size=30) streport = stcoverage.report() brreport = brcoverage.report() dureport = ducoverage.report() merged_report:pd.DataFrame = pd.concat([streport, brreport, dureport], axis=1) merged_report = merged_report[pd.notnull(merged_report['StCov'])]
def test_generate_fixed_size(self): pd.options.display.float_format = '{:,.2f}'.format pd.options.display.width = 0 project_root = PROJECT_ROOT / "dataset" / "linked_list_clean" trace_root = create_new_temp_dir() exclude_folders = ["venv", "dataset"] thorough.run_tests(project_root, trace_root, exclude_folders) module_under_test_path = str(project_root / "core" / "ll.py") sg = SuiteGenerator(trace_root, project_root, exclude_folders=exclude_folders) suites = sg.fix_sized_suites( module_under_test_path=module_under_test_path, coverage_metric=CoverageMetric.BRANCH, exact_size=3, check_unique_items_covered=False, n=10) self.assertTrue(len(suites) > 0)
support = args.support test_suite_sizes = args.test_suite_sizes coverage_boundaries_count = args.test_suite_coverages_count max_trace_size = args.max_trace_size out_folder = maybe_expand(args.out) module = args.module timeout = args.timeout revealing_node_ids = args.revealing_node_ids exclude_folders_tracing = COMMON_EXCLUDE thorough.run_tests(project_root, trace_root, exclude_folders_tracing=exclude_folders_tracing, exclude_folders_collection=None, show_time_per_test=False, quiet=False, deselect_tests=None) trace_reader = TraceReader(trace_root) failed_node_ids = trace_reader.read_failed_test_cases() module = maybe_expand(module) coverage_metrics = (CoverageMetric.STATEMENT, CoverageMetric.BRANCH, CoverageMetric.ALL_PAIRS) # coverage_metrics = (CoverageMetric.ALL_PAIRS, CoverageMetric.ALL_C_USES, CoverageMetric.ALL_P_USES) new_module_path = module_path(out_folder, project_root, module) shutil.copy(module, new_module_path)