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)