Skip to content

Commit 32bffc4

Browse files
committed
test: add regression test for topology float-conversion bug in _read_cfg
Adds test_read_cfg_topology_not_float_converted which simulates the exact field-classification logic from _read_cfg() using string values (as Qt widgets produce), asserting that 'topology' is never passed to float() and no ValueError is raised. https://claude.ai/code/session_01Cjh3nEv91RsUG7MxAukNPg
1 parent d1b4796 commit 32bffc4

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/test_gui_config.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dataclasses
2+
13
import pytest
24

35
from venting.gui.config import GuiCaseConfig
@@ -25,6 +27,48 @@ def test_gui_config_validation_rejects_bad_enum():
2527
cfg.validate()
2628

2729

30+
def test_read_cfg_topology_not_float_converted():
31+
"""Regression: topology='two_chain_shared_vest' must not be passed to float().
32+
33+
Reproduces the bug where _read_cfg() raised:
34+
ValueError: could not convert string to float: 'two_chain_shared_vest'
35+
because 'topology' was missing from the string-exclusion set.
36+
"""
37+
# Simulate the kwargs dict that Qt widgets would produce (all values as str)
38+
kwargs = {f.name: str(f.default) for f in dataclasses.fields(GuiCaseConfig)}
39+
kwargs["topology"] = "two_chain_shared_vest"
40+
41+
int_fields = {
42+
"N_chain",
43+
"N_chain_b",
44+
"N_par",
45+
"n_int_per_interface",
46+
"n_exit",
47+
"n_pts",
48+
}
49+
string_fields = {
50+
"int_model",
51+
"exit_model",
52+
"topology",
53+
"external_model",
54+
"profile_kind",
55+
"profile_pressure_unit",
56+
"thermo",
57+
"wall_model",
58+
"profile_file",
59+
"output_case_name",
60+
}
61+
float_fields = set(kwargs) - int_fields - string_fields
62+
63+
# Must not raise ValueError
64+
for k in int_fields:
65+
int(kwargs[k])
66+
for k in float_fields:
67+
float(kwargs[k])
68+
69+
assert "topology" not in float_fields
70+
71+
2872
def test_gui_config_validation_rejects_nonpositive():
2973
cfg = GuiCaseConfig(V_cell_m3=0.0)
3074
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)