def test_get_source_file_content(self): # also for testing Unicode support runid = self._runid simple_filters = [ReportFilter(checkerId='*', filepath='*.c*')] run_result_count = self._cc_client.getRunResultCount( runid, simple_filters) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, [], simple_filters) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) for run_res in run_results: self.assertTrue(re.match(r'.*\.c(pp)?$', run_res.checkedFile)) debug('Getting the content of ' + run_res.checkedFile) file_data = self._cc_client.getSourceFileData(run_res.fileId, True) self.assertIsNotNone(file_data) file_content1 = file_data.fileContent self.assertIsNotNone(file_content1) with open(run_res.checkedFile) as source_file: file_content2 = source_file.read() self.assertEqual(file_content1, file_content2) debug('got ' + str(len(run_results)) + ' files')
def test_get_source_file_content(self): # also for testing Unicode support runid = self._runid simple_filters = [ReportFilter(checkerId='*', filepath='*.c*')] run_result_count = self._cc_client.getRunResultCount(runid, simple_filters) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, [], simple_filters) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) for run_res in run_results: self.assertTrue(re.match(r'.*\.c(pp)?$', run_res.checkedFile)) debug('Getting the content of ' + run_res.checkedFile) file_data = self._cc_client.getSourceFileData(run_res.fileId, True) self.assertIsNotNone(file_data) file_content1 = file_data.fileContent self.assertIsNotNone(file_content1) with open(run_res.checkedFile) as source_file: file_content2 = source_file.read() self.assertEqual(file_content1, file_content2) debug('got ' + str(len(run_results)) + ' files')
def test_zzzzz_get_run_results_checker_msg_filter_suppressed(self): # this function must be run for last runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) simple_filters = [ReportFilter(suppressed=False)] run_results = self._cc_client.getRunResults(runid, 50, 0, [], simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) suppress_msg = r'My beautiful Unicode comment.' bug = run_results[0] success = self._cc_client.suppressBug([runid], bug.reportId, suppress_msg) self.assertTrue(success) debug('Bug suppressed successfully') simple_filters = [ReportFilter(suppressed=True)] run_results = self._cc_client.getRunResults(runid, 50, 0, [], simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) filtered_run_results = filter( lambda result: (result.reportId == bug.reportId) and result.suppressed, run_results) self.assertEqual(len(filtered_run_results), 1) suppressed_bug = filtered_run_results[0] self.assertEqual(suppressed_bug.suppressComment, suppress_msg) success = self._cc_client.unSuppressBug([runid], suppressed_bug.reportId) self.assertTrue(success) debug('Bug unsuppressed successfully') simple_filters = [ReportFilter(suppressed=False)] run_results = self._cc_client.getRunResults(runid, 50, 0, [], simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) filtered_run_results = filter( lambda result: (result.reportId == bug.reportId) and not result.suppressed, run_results) self.assertEqual(len(filtered_run_results), 1) debug('Done.\n')
def test_get_run_results_checker_id_and_file_path(self): runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, [], []) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) found_all = True for bug in self._testproject_data['bugs']: found = False for run_res in run_results: found |= (run_res.checkedFile.endswith(bug['file'])) and \ (run_res.lastBugPosition.startLine == bug['line']) and \ (run_res.checkerId == bug['checker']) and \ (run_res.bugHash == bug['hash']) found_all &= found self.assertTrue(found_all) for run_res in run_results: debug('{0:15s} {1}'.format(run_res.checkedFile, run_res.checkerId)) debug('reportId: {0} suppressed: {1}'.format( run_res.reportId, run_res.suppressed)) debug(run_res.lastBugPosition) debug('-------------------------------------------------') debug('got ' + str(len(run_results)) + ' reports')
def test_get_run_results_no_filter(self): runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, [], []) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) for run_res in run_results: debug('{0:15s} {1}'.format(run_res.checkedFile, run_res.checkerId)) debug('{0:15d} {1}'.format(run_res.reportId, run_res.suppressed)) debug(run_res.lastBugPosition) debug('-------------------------------------------------') debug('got ' + str(len(run_results)) + ' reports') debug('Done.\n')
def test_get_run_results_sorted2(self): runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) sortMode1 = SortMode(SortType.FILENAME, Order.ASC) sortMode2 = SortMode(SortType.CHECKER_NAME, Order.ASC) sort_types = [sortMode1, sortMode2] run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, sort_types, []) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) for i in range(run_result_count - 1): bug1 = run_results[i] bug2 = run_results[i + 1] self.assertTrue(bug1.checkedFile <= bug2.checkedFile) self.assertTrue((bug1.checkedFile != bug2.checkedFile) or (bug1.lastBugPosition.startLine <= bug2.lastBugPosition.startLine) or (bug1.checkerId <= bug2.checkerId)) for run_res in run_results: debug('{0:15s} {1}'.format(run_res.checkedFile, run_res.checkerId)) debug('{0:15d} {1}'.format(run_res.reportId, run_res.suppressed)) debug(run_res.lastBugPosition) debug('-------------------------------------------------') debug('got ' + str(len(run_results)) + ' reports') debug('Done.\n')
def test_get_run_results_checker_id_and_file_path(self): runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, [], []) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) found_all = True for bug in self._testproject_data['bugs']: found = False for run_res in run_results: found |= (run_res.checkedFile.endswith(bug['file'])) and \ (run_res.lastBugPosition.startLine == bug['line']) and \ (run_res.checkerId == bug['checker']) and \ (run_res.bugHash == bug['hash']) found_all &= found self.assertTrue(found_all) for run_res in run_results: debug('{0:15s} {1}'.format(run_res.checkedFile, run_res.checkerId)) debug('reportId: {0} suppressed: {1}'.format(run_res.reportId, run_res.suppressed)) debug(run_res.lastBugPosition) debug('-------------------------------------------------') debug('got ' + str(len(run_results)) + ' reports')
def test_get_run_results_sorted2(self): runid = self._runid debug('Get all run results from the db for runid: ' + str(runid)) sortMode1 = SortMode(SortType.FILENAME, Order.ASC) sortMode2 = SortMode(SortType.CHECKER_NAME, Order.ASC) sort_types = [sortMode1, sortMode2] run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = self._cc_client.getRunResults(runid, run_result_count, 0, sort_types, []) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) for i in range(run_result_count - 1): bug1 = run_results[i] bug2 = run_results[i + 1] self.assertTrue(bug1.checkedFile <= bug2.checkedFile) self.assertTrue((bug1.checkedFile != bug2.checkedFile) or (bug1.checkerId <= bug2.checkerId)) for run_res in run_results: debug('{0:15s} {1}'.format(run_res.checkedFile, run_res.checkerId)) debug('{0:15d} {1}'.format(run_res.reportId, run_res.suppressed)) debug(run_res.lastBugPosition) debug('-------------------------------------------------') debug('got ' + str(len(run_results)) + ' reports') debug('Done.\n')