From 32bffc4551676f80716a7a22dcdf5ce33d95d0f0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Feb 2026 00:36:53 +0000 Subject: [PATCH] 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 --- tests/test_gui_config.py | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_gui_config.py b/tests/test_gui_config.py index 5d8fb55..e742e26 100644 --- a/tests/test_gui_config.py +++ b/tests/test_gui_config.py @@ -1,3 +1,5 @@ +import dataclasses + import pytest from venting.gui.config import GuiCaseConfig @@ -25,6 +27,48 @@ def test_gui_config_validation_rejects_bad_enum(): cfg.validate() +def test_read_cfg_topology_not_float_converted(): + """Regression: topology='two_chain_shared_vest' must not be passed to float(). + + Reproduces the bug where _read_cfg() raised: + ValueError: could not convert string to float: 'two_chain_shared_vest' + because 'topology' was missing from the string-exclusion set. + """ + # Simulate the kwargs dict that Qt widgets would produce (all values as str) + kwargs = {f.name: str(f.default) for f in dataclasses.fields(GuiCaseConfig)} + kwargs["topology"] = "two_chain_shared_vest" + + int_fields = { + "N_chain", + "N_chain_b", + "N_par", + "n_int_per_interface", + "n_exit", + "n_pts", + } + string_fields = { + "int_model", + "exit_model", + "topology", + "external_model", + "profile_kind", + "profile_pressure_unit", + "thermo", + "wall_model", + "profile_file", + "output_case_name", + } + float_fields = set(kwargs) - int_fields - string_fields + + # Must not raise ValueError + for k in int_fields: + int(kwargs[k]) + for k in float_fields: + float(kwargs[k]) + + assert "topology" not in float_fields + + def test_gui_config_validation_rejects_nonpositive(): cfg = GuiCaseConfig(V_cell_m3=0.0) with pytest.raises(ValueError):