Skip to content

Commit dd96596

Browse files
committed
fix(pydantic): adoption to new ScanArgument refactor from bec
1 parent 56799f3 commit dd96596

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

bec_widgets/cli/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def collapse_all(self) -> "None":
738738
@rpc_call
739739
def state_summary(self) -> "dict[str, dict[str, str]]":
740740
"""
741-
Return the displayed beamline states with their current status and label.
741+
Return all beamline states (including filtered ones) with their current status and label.
742742
743743
Returns:
744744
dict: Mapping of state name to a dictionary with ``status`` and ``label`` keys.

bec_widgets/utils/forms_from_types/pydantic_model_info_adapter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections.abc import Mapping
44
from typing import Any
55

6+
from bec_lib.scan_args import ScanArgument
67
from pydantic import BaseModel
78
from pydantic_core import PydanticUndefined
89

@@ -17,6 +18,9 @@ def pydantic_model_input_configs(model: type[BaseModel]) -> list[dict[str, Any]]
1718
for name, info in model.model_fields.items():
1819
metadata: dict[str, Any] = {}
1920
for entry in info.metadata:
21+
if isinstance(entry, ScanArgument):
22+
metadata.update(entry.model_dump(exclude_none=True))
23+
continue
2024
for key in NUMERIC_BOUND_KEYS:
2125
value = getattr(entry, key, None)
2226
if value is not None:

tests/unit_tests/test_generated_form_form.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ def test_pydantic_widget_form_plain_field_has_generated_label_and_no_tooltip(qtb
214214
assert form.field_widget("sample_name").toolTip() == ""
215215

216216

217+
def test_pydantic_model_input_configs_reads_bl_states_annotated_scan_arguments():
218+
"""Contract test: ScanArgument metadata attached via ``Annotated`` in bec_lib's beamline
219+
state configs must reach the generated-form configuration."""
220+
from bec_lib import bl_states
221+
222+
from bec_widgets.utils.forms_from_types.pydantic_model_info_adapter import (
223+
pydantic_model_input_configs,
224+
)
225+
226+
items = {
227+
item["name"]: item
228+
for item in pydantic_model_input_configs(bl_states.DeviceWithinLimitsState.CONFIG_CLASS)
229+
}
230+
231+
assert items["name"]["display_name"] == "State name"
232+
assert items["name"]["tooltip"]
233+
assert items["device"]["display_name"] == "Device"
234+
assert items["low_limit"]["reference_units"] == "device"
235+
assert items["high_limit"]["reference_units"] == "device"
236+
assert items["tolerance"]["reference_units"] == "device"
237+
238+
217239
def test_pydantic_widget_form_uses_scan_argument_metadata(qtbot, mocked_client):
218240
form = PydanticWidgetForm(GeneratedScanArgumentSchema, client=mocked_client)
219241
qtbot.addWidget(form)

0 commit comments

Comments
 (0)