|
1 | 1 | import subprocess |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | +from sarif_pydantic.sarif import Run, Sarif, Tool, ToolDriver |
2 | 6 |
|
3 | 7 | from core_codemods.remove_assertion_in_pytest_raises import ( |
4 | 8 | RemoveAssertionInPytestRaises, |
@@ -26,14 +30,50 @@ def test_codemods_include_exclude_conflict(self): |
26 | 30 | ) |
27 | 31 | assert completed_process.returncode == 3 |
28 | 32 |
|
29 | | - def test_load_sast_only_by_flag(self, tmp_path): |
| 33 | + @pytest.mark.parametrize( |
| 34 | + "cli_args", |
| 35 | + [ |
| 36 | + "--sonar-issues-json", |
| 37 | + "--sonar-hotspots-json", |
| 38 | + "--sonar-json", |
| 39 | + ], |
| 40 | + ) |
| 41 | + def test_load_sast_only_by_sonar_flag(self, tmp_path, cli_args): |
30 | 42 | tmp_file_path = tmp_path / "sonar.json" |
31 | 43 | tmp_file_path.touch() |
32 | 44 | completed_process = subprocess.run( |
33 | 45 | [ |
34 | 46 | "codemodder", |
35 | 47 | "tests/samples/", |
36 | | - "--sonar-issues-json", |
| 48 | + cli_args, |
| 49 | + f"{tmp_file_path}", |
| 50 | + "--dry-run", |
| 51 | + ], |
| 52 | + check=False, |
| 53 | + capture_output=True, |
| 54 | + text=True, |
| 55 | + ) |
| 56 | + print(completed_process.stdout) |
| 57 | + print(completed_process.stderr) |
| 58 | + assert completed_process.returncode == 0 |
| 59 | + assert RemoveAssertionInPytestRaises.id not in completed_process.stdout |
| 60 | + |
| 61 | + def test_load_sast_only_by_sarif_flag(self, tmp_path: Path): |
| 62 | + tmp_file_path = tmp_path / "sarif.json" |
| 63 | + sarif_run = Run( |
| 64 | + tool=Tool(driver=ToolDriver(name="test")), |
| 65 | + results=[], |
| 66 | + ) |
| 67 | + sarif = Sarif(runs=[sarif_run], **{"$schema": ""}) |
| 68 | + tmp_file_path.write_text( |
| 69 | + sarif.model_dump_json(indent=2, exclude_none=True, by_alias=True) |
| 70 | + ) |
| 71 | + |
| 72 | + completed_process = subprocess.run( |
| 73 | + [ |
| 74 | + "codemodder", |
| 75 | + "tests/samples/", |
| 76 | + "--sarif", |
37 | 77 | f"{tmp_file_path}", |
38 | 78 | "--dry-run", |
39 | 79 | ], |
|
0 commit comments