Skip to content

Commit 34c6cea

Browse files
committed
reapplying fix from main 843dedf
1 parent a70141b commit 34c6cea

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

scripts_bazel/merge_sourcelinks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def main():
3939
)
4040
_ = parser.add_argument(
4141
"--known_good",
42-
required=True,
4342
help="Path to a required 'known good' JSON file (provided by Bazel).",
4443
)
4544
_ = parser.add_argument(

scripts_bazel/tests/generate_sourcelinks_cli_test.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414
"""Tests for generate_sourcelinks_cli.py"""
1515

1616
import json
17-
import subprocess
1817
import sys
1918
from pathlib import Path
2019

20+
import pytest
21+
22+
import scripts_bazel.generate_sourcelinks_cli
23+
2124
_MY_PATH = Path(__file__).parent
2225

2326

24-
def test_generate_sourcelinks_cli_basic(tmp_path: Path) -> None:
27+
def test_generate_sourcelinks_cli_basic(
28+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
29+
) -> None:
2530
"""Test basic functionality of generate_sourcelinks_cli."""
2631
# Create a test source file with a traceability tag
2732
test_file = tmp_path / "test_source.py"
@@ -37,17 +42,19 @@ def some_function():
3742
output_file = tmp_path / "output.json"
3843

3944
# Execute the script
40-
result = subprocess.run(
45+
monkeypatch.setattr(
46+
sys,
47+
"argv",
4148
[
42-
sys.executable,
4349
_MY_PATH.parent / "generate_sourcelinks_cli.py",
4450
"--output",
4551
str(output_file),
4652
str(test_file),
4753
],
4854
)
55+
result = scripts_bazel.generate_sourcelinks_cli.main()
4956

50-
assert result.returncode == 0
57+
assert result == 0
5158
assert output_file.exists()
5259

5360
# Check the output content

scripts_bazel/tests/merge_sourcelinks_test.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414
"""Tests for merge_sourcelinks.py"""
1515

1616
import json
17-
import subprocess
1817
import sys
1918
from pathlib import Path
2019

20+
import pytest
21+
22+
import scripts_bazel.merge_sourcelinks
23+
2124
_MY_PATH = Path(__file__).parent
2225

2326

24-
def test_merge_sourcelinks_basic(tmp_path: Path) -> None:
27+
def test_merge_sourcelinks_basic(
28+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
29+
) -> None:
2530
"""Test basic merge functionality."""
2631
# Each sourcelinks JSON starts with a metadata dict followed by need entries
2732
local_meta = {"repo_name": "local_repo", "hash": "", "url": ""}
@@ -58,26 +63,22 @@ def test_merge_sourcelinks_basic(tmp_path: Path) -> None:
5863
)
5964
)
6065

61-
# known_good.json is required by the script; for local_repo it is never read
62-
known_good_file = tmp_path / "known_good.json"
63-
known_good_file.write_text(json.dumps({"modules": {}}))
64-
6566
output_file = tmp_path / "merged.json"
6667

67-
result = subprocess.run(
68+
monkeypatch.setattr(
69+
sys,
70+
"argv",
6871
[
69-
sys.executable,
7072
_MY_PATH.parent / "merge_sourcelinks.py",
7173
"--output",
7274
str(output_file),
73-
"--known_good",
74-
str(known_good_file),
7575
str(file1),
7676
str(file2),
7777
],
7878
)
79+
result = scripts_bazel.merge_sourcelinks.main()
7980

80-
assert result.returncode == 0
81+
assert result == 0
8182
assert output_file.exists()
8283

8384
with open(output_file) as f:

0 commit comments

Comments
 (0)