-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from KevinDeJong-TomTom/fix/too-many-reports
fix: add message when the number of annotation exceeds limit
- Loading branch information
Showing
5 changed files
with
149 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2021 - 2021 TomTom N.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import llvm_diagnostics | ||
from llvm_diagnostics.messages import DiagnosticsLevel, DiagnosticsMessage | ||
import pytest | ||
from unittest.mock import Mock | ||
|
||
from bitbucket_code_insight_reporter import generate | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input, expectation", | ||
( | ||
("error", "HIGH"), | ||
("warning", "MEDIUM"), | ||
("note", "LOW"), | ||
("random_string", "LOW"), | ||
(123, "LOW"), | ||
), | ||
) | ||
def test_get_severity_for_level(input, expectation): | ||
assert generate.get_severity_for_level(input) == expectation | ||
|
||
|
||
def test_retrieve_annotations_from_file(): | ||
llvm_diagnostics.parser.diagnostics_messages_from_file = Mock( | ||
return_value=[ | ||
DiagnosticsMessage( | ||
"first_test.py", 1, 1, "test message", DiagnosticsLevel.ERROR | ||
), | ||
DiagnosticsMessage( | ||
"second_test.py", 2, 2, "test message", DiagnosticsLevel.WARNING | ||
), | ||
] | ||
) | ||
|
||
_expectations = [ | ||
{ | ||
"path": "first_test.py", | ||
"message": "test message", | ||
"line": 1, | ||
"severity": "HIGH", | ||
}, | ||
{ | ||
"path": "second_test.py", | ||
"message": "test message", | ||
"line": 2, | ||
"severity": "MEDIUM", | ||
}, | ||
] | ||
|
||
assert generate.retrieve_annotations_from_file(None, None) == _expectations | ||
|
||
|
||
def test_retrieve_annotations_from_empty_file(): | ||
llvm_diagnostics.parser.diagnostics_messages_from_file = Mock(return_value=[]) | ||
assert generate.retrieve_annotations_from_file(None, None) == [] | ||
|
||
|
||
def test_retrieve_annotations_from_file_workspace(): | ||
llvm_diagnostics.parser.diagnostics_messages_from_file = Mock( | ||
return_value=[DiagnosticsMessage("/code/first_test.py", 1, 1, "test message")] | ||
) | ||
|
||
_expectations = [ | ||
{ | ||
"path": "first_test.py", | ||
"message": "test message", | ||
"line": 1, | ||
"severity": "HIGH", | ||
} | ||
] | ||
|
||
assert generate.retrieve_annotations_from_file(None, "/code/") == _expectations | ||
|
||
|
||
def test_retrieve_annotations_from_file_wrong_workspace(): | ||
llvm_diagnostics.parser.diagnostics_messages_from_file = Mock( | ||
return_value=[DiagnosticsMessage("/code/first_test.py", 1, 1, "test message")] | ||
) | ||
|
||
_expectations = [ | ||
{ | ||
"path": "/code/first_test.py", | ||
"message": "test message", | ||
"line": 1, | ||
"severity": "HIGH", | ||
} | ||
] | ||
|
||
assert ( | ||
generate.retrieve_annotations_from_file(None, "/wrong_workspace/") | ||
== _expectations | ||
) |