Skip to content

Commit 77631e3

Browse files
committed
test(par_dict): Improve the tests with a copilot suggestion
1 parent 0e7a534 commit 77631e3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/test_data_model_par_dict.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,12 +1469,14 @@ def test_parameter_validation_rejects_invalid_names(self) -> None:
14691469
with tempfile.NamedTemporaryFile(mode="w", suffix=".param", delete=False) as f:
14701470
f.write(invalid_content)
14711471
f.flush()
1472+
file_path = f.name
14721473

1474+
try:
14731475
# Act & Assert: Invalid names rejected
14741476
with pytest.raises(SystemExit):
1475-
ParDict.load_param_file_into_dict(f.name)
1476-
1477-
os.unlink(f.name)
1477+
ParDict.load_param_file_into_dict(file_path)
1478+
finally:
1479+
os.unlink(file_path)
14781480

14791481
def test_parameter_validation_rejects_invalid_values(self) -> None:
14801482
"""
@@ -1490,12 +1492,14 @@ def test_parameter_validation_rejects_invalid_values(self) -> None:
14901492
with tempfile.NamedTemporaryFile(mode="w", suffix=".param", delete=False) as f:
14911493
f.write(invalid_content)
14921494
f.flush()
1495+
file_path = f.name
14931496

1497+
try:
14941498
# Act & Assert: Invalid values rejected
1495-
with pytest.raises(SystemExit, match="Invalid parameter value"):
1496-
ParDict.load_param_file_into_dict(f.name)
1497-
1498-
os.unlink(f.name)
1499+
with pytest.raises(SystemExit, match=_("Invalid parameter value {value!r}").format(value="not_a_number")):
1500+
ParDict.load_param_file_into_dict(file_path)
1501+
finally:
1502+
os.unlink(file_path)
14991503

15001504
def test_parameter_validation_rejects_non_finite_values(self) -> None:
15011505
"""
@@ -1516,7 +1520,7 @@ def test_parameter_validation_rejects_non_finite_values(self) -> None:
15161520
file_path = f.name
15171521

15181522
try:
1519-
with pytest.raises(SystemExit, match=_("Non-finite parameter value {value}").format(value=bad_value)):
1523+
with pytest.raises(SystemExit, match=_("Non-finite parameter value {value!r}").format(value=bad_value)):
15201524
ParDict.load_param_file_into_dict(file_path)
15211525
finally:
15221526
os.unlink(file_path)

0 commit comments

Comments
 (0)