Skip to content

Commit 482b01b

Browse files
Check for consistency of test cases.
Add a unit test to check for consistency of input files.
1 parent 9bbe5b5 commit 482b01b

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

test_input_file_consistency.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-FileCopyrightText: 2024-present Proxima Fusion GmbH <info@proximafusion.com>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""Tests for consistency between main and large_cpp_tests input files.
5+
6+
The large_cpp_tests test_data contains extended versions of the main repo's
7+
input files, with additional dump_* diagnostic flags. After conversion via
8+
indata_to_json (which strips non-standard fields), the JSON output must be
9+
identical.
10+
11+
Run via: pytest src/vmecpp/cpp/vmecpp_large_cpp_tests/test_input_file_consistency.py -v
12+
"""
13+
14+
import json
15+
import tempfile
16+
from pathlib import Path
17+
18+
import pytest
19+
20+
from vmecpp import _util
21+
22+
REPO_ROOT = Path(__file__).parent.parent.parent.parent.parent
23+
MAIN_TEST_DATA = REPO_ROOT / "src" / "vmecpp" / "cpp" / "vmecpp" / "test_data"
24+
LARGE_TEST_DATA = (
25+
REPO_ROOT / "src" / "vmecpp" / "cpp" / "vmecpp_large_cpp_tests" / "test_data"
26+
)
27+
28+
29+
def _get_input_files(directory: Path) -> set[str]:
30+
"""Return the set of input.* filenames in the given directory."""
31+
return {p.name for p in directory.glob("input.*")}
32+
33+
34+
def test_no_extra_input_files_in_large_tests():
35+
"""Every large tests input file must also exist in the main repo.
36+
37+
The main repo may contain additional input files that are not (yet) in
38+
the large tests repo, but the reverse is not allowed.
39+
"""
40+
main_files = _get_input_files(MAIN_TEST_DATA)
41+
large_files = _get_input_files(LARGE_TEST_DATA)
42+
43+
extra = large_files - main_files
44+
assert not extra, (
45+
f"Large tests input files not present in main repo: {sorted(extra)}. "
46+
f"Add them to vmecpp/test_data/ or remove them from "
47+
f"vmecpp_large_cpp_tests/test_data/."
48+
)
49+
50+
51+
def _discover_large_test_input_files() -> list[str]:
52+
"""Discover input files in the large tests directory."""
53+
return sorted(_get_input_files(LARGE_TEST_DATA))
54+
55+
56+
@pytest.mark.parametrize("input_file", _discover_large_test_input_files())
57+
def test_input_files_produce_identical_json(input_file: str):
58+
"""Input files in both repos must produce identical JSON after conversion."""
59+
with tempfile.TemporaryDirectory() as tmpdir:
60+
main_json_path = _util.indata_to_json(
61+
MAIN_TEST_DATA / input_file,
62+
output_override=Path(tmpdir) / "main.json",
63+
)
64+
large_json_path = _util.indata_to_json(
65+
LARGE_TEST_DATA / input_file,
66+
output_override=Path(tmpdir) / "large.json",
67+
)
68+
69+
main_data = json.loads(main_json_path.read_text())
70+
large_data = json.loads(large_json_path.read_text())
71+
72+
assert main_data == large_data, (
73+
f"JSON mismatch for {input_file}. "
74+
f"Keys only in main: {set(main_data) - set(large_data)}, "
75+
f"Keys only in large: {set(large_data) - set(main_data)}"
76+
)

0 commit comments

Comments
 (0)