|
1 | | -from core_codemods.sonar.results import SonarResult |
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from core_codemods.sonar.results import SonarResult, SonarResultSet |
| 4 | + |
| 5 | +SAMPLE_DIR = Path(__file__).parent / "samples" |
2 | 6 |
|
3 | 7 |
|
4 | 8 | def test_result_without_textrange(): |
@@ -29,3 +33,33 @@ def test_result_without_textrange(): |
29 | 33 | assert sonar_result.finding_id == "AZJnP4pZPJb5bI8DP25Y" |
30 | 34 | assert sonar_result.locations == () |
31 | 35 | assert sonar_result.codeflows == () |
| 36 | + |
| 37 | + |
| 38 | +def test_parse_issues_json(): |
| 39 | + results = SonarResultSet.from_json(SAMPLE_DIR / "sonar_issues.json") |
| 40 | + assert len(results) == 34 |
| 41 | + |
| 42 | + |
| 43 | +def test_parse_hotspots_json(): |
| 44 | + results = SonarResultSet.from_json(SAMPLE_DIR / "sonar_hotspots.json") |
| 45 | + assert len(results) == 2 |
| 46 | + |
| 47 | + |
| 48 | +def test_empty_issues(tmpdir, caplog): |
| 49 | + empty_json = tmpdir / "empty.json" |
| 50 | + empty_json.write_text('{"issues": []}', encoding="utf-8") |
| 51 | + |
| 52 | + results = SonarResultSet.from_json(empty_json) |
| 53 | + |
| 54 | + assert len(results) == 0 |
| 55 | + assert "Could not parse sonar json" not in caplog.text |
| 56 | + |
| 57 | + |
| 58 | +def test_empty_hotspots(tmpdir, caplog): |
| 59 | + empty_json = tmpdir / "empty.json" |
| 60 | + empty_json.write_text('{"hotspots": []}', encoding="utf-8") |
| 61 | + |
| 62 | + results = SonarResultSet.from_json(empty_json) |
| 63 | + |
| 64 | + assert len(results) == 0 |
| 65 | + assert "Could not parse sonar json" not in caplog.text |
0 commit comments