Skip to content

Commit a70141b

Browse files
committed
fix broken tests
1 parent 9afb731 commit a70141b

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

scripts_bazel/tests/generate_sourcelinks_cli_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ def some_function():
5454
with open(output_file) as f:
5555
data: list[dict[str, str | int]] = json.load(f)
5656
assert isinstance(data, list)
57-
assert len(data) > 0
57+
# First element is the metadata dict; there must be at least one need entry after it
58+
assert len(data) > 1
5859

59-
# Verify schema of each entry
60-
for entry in data:
60+
# Verify schema of each need entry (skip the first metadata element)
61+
for entry in data[1:]:
6162
assert "file" in entry
6263
assert "line" in entry
6364
assert "tag" in entry
@@ -71,4 +72,4 @@ def some_function():
7172
assert isinstance(entry["need"], str)
7273
assert isinstance(entry["full_line"], str)
7374

74-
assert any(entry["need"] == "tool_req__docs_arch_types" for entry in data)
75+
assert any(entry["need"] == "tool_req__docs_arch_types" for entry in data[1:])

scripts_bazel/tests/merge_sourcelinks_test.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@
2323

2424
def test_merge_sourcelinks_basic(tmp_path: Path) -> None:
2525
"""Test basic merge functionality."""
26-
# Create test JSON files with correct schema
26+
# Each sourcelinks JSON starts with a metadata dict followed by need entries
27+
local_meta = {"repo_name": "local_repo", "hash": "", "url": ""}
28+
2729
file1 = tmp_path / "links1.json"
2830
file1.write_text(
2931
json.dumps(
3032
[
33+
local_meta,
3134
{
3235
"file": "test1.py",
3336
"line": 10,
3437
"tag": "# req-Id:",
3538
"need": "tool_req__docs_arch_types",
3639
"full_line": "# req-Id: tool_req__docs_arch_types",
37-
}
40+
},
3841
]
3942
)
4043
)
@@ -43,17 +46,22 @@ def test_merge_sourcelinks_basic(tmp_path: Path) -> None:
4346
file2.write_text(
4447
json.dumps(
4548
[
49+
local_meta,
4650
{
4751
"file": "test2.py",
4852
"line": 20,
4953
"tag": "# req-Id:",
5054
"need": "gd_req__req_validity",
5155
"full_line": "# req-Id: gd_req__req_validity",
52-
}
56+
},
5357
]
5458
)
5559
)
5660

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+
5765
output_file = tmp_path / "merged.json"
5866

5967
result = subprocess.run(
@@ -62,6 +70,8 @@ def test_merge_sourcelinks_basic(tmp_path: Path) -> None:
6270
_MY_PATH.parent / "merge_sourcelinks.py",
6371
"--output",
6472
str(output_file),
73+
"--known_good",
74+
str(known_good_file),
6575
str(file1),
6676
str(file2),
6777
],

0 commit comments

Comments
 (0)