Skip to content

Commit 57a9d70

Browse files
committed
Display the top 10 lines in git diff for each modified file in error message.
1 parent f16581b commit 57a9d70

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/model_config_tests/config_tests/test_bit_reproducibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_repro_determinism_restart(
333333
@pytest.mark.repro_payu_setup
334334
def test_repro_payu_setup(control_path, output_path):
335335
"""
336-
Test payu setup with --reproduce which errors if payu manifests full hashes are changed
336+
Test payu setup with `git diff` which errors if any files in payu manifests are changed.
337337
"""
338338
experiment = setup_exp(control_path, output_path, exp_name="repro_payu_setup")
339339
try:

src/model_config_tests/exp_test_helper.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,23 @@ def setup_reproduce(self):
110110
os.chdir(owd)
111111

112112
if result.stdout != "":
113+
# Collect and display the top 10 lines of the diff for each modified file
114+
files = result.stdout.strip().split("\n")
115+
error_message = ""
116+
for file in files:
117+
error_message += f"Modifications are detected in {file}:\n"
118+
diff_details = sp.run(
119+
["git", "diff", f"{file}"],
120+
capture_output=True,
121+
text=True,
122+
)
123+
diff_lines = diff_details.stdout.splitlines()
124+
top_lines = "\n".join(diff_lines[2:12])
125+
if len(diff_lines) > 12:
126+
top_lines += "\n... (truncated)"
127+
error_message += f"Changes are: \n {top_lines}\n"
113128
raise RuntimeError(
114-
f"Manifests have been modified. The modified files include: {result.stdout}.\n"
129+
f"{error_message}"
115130
)
116131

117132
def setup_for_test_run(self):

0 commit comments

Comments
 (0)