diff --git a/tools/report-converter/codechecker_report_converter/analyzers/pyflakes/parser.py b/tools/report-converter/codechecker_report_converter/analyzers/pyflakes/parser.py index e940e020f4..8a6012bfdf 100644 --- a/tools/report-converter/codechecker_report_converter/analyzers/pyflakes/parser.py +++ b/tools/report-converter/codechecker_report_converter/analyzers/pyflakes/parser.py @@ -27,12 +27,16 @@ def __init__(self, analyzer_result): self.analyzer_result = analyzer_result - # Regex for parsing a clang-tidy message. + # Regex for parsing a Pyflakes message. self.message_line_re = re.compile( # File path followed by a ':'. r'^(?P[\S ]+?):' # Line number followed by a ':'. r'(?P\d+?):' + # Optional column number. Pyflakes 2.2.0 to 2.4.0 print it + # followed by a space, later versions followed by ':'. Older + # versions do not print it. + r'(?:(?P\d+):?(?=\s))?' # Message. r'(?P[\S \t]+)\s*') @@ -52,7 +56,7 @@ def _parse_line( report = Report( get_or_create_file(file_path, self._file_cache), int(match.group('line')), - 0, + int(match.group('column') or 0), match.group('message').strip(), '') diff --git a/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.expected.plist b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.expected.plist new file mode 100644 index 0000000000..5bc37bbeaf --- /dev/null +++ b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.expected.plist @@ -0,0 +1,151 @@ + + + + + diagnostics + + + category + unknown + check_name + pyflakes + description + 'collections.namedtuple' imported but unused + issue_hash_content_of_line_in_context + 79e37db99c90a6d72c2ac46c4de6ff53 + location + + col + 1 + file + 0 + line + 1 + + path + + + depth + 0 + kind + event + location + + col + 1 + file + 0 + line + 1 + + message + 'collections.namedtuple' imported but unused + + + type + pyflakes + + + category + unknown + check_name + pyflakes + description + undefined name 'self' + issue_hash_content_of_line_in_context + f2f60366a1abf13ed3d6c5ba426e3004 + location + + col + 12 + file + 0 + line + 5 + + path + + + depth + 0 + kind + event + location + + col + 12 + file + 0 + line + 5 + + message + undefined name 'self' + + + type + pyflakes + + + category + unknown + check_name + pyflakes + description + local variable 'name' is assigned to but never used + issue_hash_content_of_line_in_context + 7b0f81fa6d601131bdbd2a537230346f + location + + col + 5 + file + 0 + line + 9 + + path + + + depth + 0 + kind + event + location + + col + 5 + file + 0 + line + 9 + + message + local variable 'name' is assigned to but never used + + + type + pyflakes + + + files + + files/simple.py + + metadata + + analyzer + + name + pyflakes + + generated_by + + name + report-converter + version + x.y.z + + + + diff --git a/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.out b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.out new file mode 100644 index 0000000000..9bdd27237d --- /dev/null +++ b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column.out @@ -0,0 +1,3 @@ +files/simple.py:1:1: 'collections.namedtuple' imported but unused +files/simple.py:5:12: undefined name 'self' +files/simple.py:9:5: local variable 'name' is assigned to but never used diff --git a/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column_no_colon.out b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column_no_colon.out new file mode 100644 index 0000000000..6c71cd788d --- /dev/null +++ b/tools/report-converter/tests/unit/analyzers/pyflakes_output_test_files/simple_column_no_colon.out @@ -0,0 +1,3 @@ +files/simple.py:1:1 'collections.namedtuple' imported but unused +files/simple.py:5:12 undefined name 'self' +files/simple.py:9:5 local variable 'name' is assigned to but never used diff --git a/tools/report-converter/tests/unit/analyzers/test_pyflakes_parser.py b/tools/report-converter/tests/unit/analyzers/test_pyflakes_parser.py index 442cfa6845..3cb3384c4c 100644 --- a/tools/report-converter/tests/unit/analyzers/test_pyflakes_parser.py +++ b/tools/report-converter/tests/unit/analyzers/test_pyflakes_parser.py @@ -55,9 +55,10 @@ def test_transform_dir(self): file_name="{source_file}_{analyzer}") self.assertFalse(ret) - def test_transform_single_file(self): - """ Test transforming single output file. """ - analyzer_result = os.path.join(self.test_files, 'simple.out') + def _check_transform(self, output_file, expected_plist): + """ Transform the given Pyflakes output and compare the result with + the expected plist file. """ + analyzer_result = os.path.join(self.test_files, output_file) self.analyzer_result.transform( [analyzer_result], self.cc_result_dir, plist.EXTENSION, file_name="{source_file}_{analyzer}") @@ -74,9 +75,24 @@ def test_transform_single_file(self): self.assertTrue(res['metadata']['generated_by']['version']) res['metadata']['generated_by']['version'] = "x.y.z" - plist_file = os.path.join(self.test_files, - 'simple.expected.plist') + plist_file = os.path.join(self.test_files, expected_plist) with open(plist_file, mode='rb') as pfile: exp = plistlib.load(pfile) self.assertEqual(res, exp) + + def test_transform_single_file(self): + """ Test transforming single output file. """ + self._check_transform('simple.out', 'simple.expected.plist') + + def test_transform_output_with_column(self): + """ Test transforming output of Pyflakes 2.5.0 and later, which + prints the column number followed by a ':'. """ + self._check_transform('simple_column.out', + 'simple_column.expected.plist') + + def test_transform_output_with_column_no_colon(self): + """ Test transforming output of Pyflakes 2.2.0 to 2.4.0, which + prints the column number followed by a space. """ + self._check_transform('simple_column_no_colon.out', + 'simple_column.expected.plist')