diff --git a/src/pvi/device.py b/src/pvi/device.py index cb3dfd2c..e7e09d11 100644 --- a/src/pvi/device.py +++ b/src/pvi/device.py @@ -308,10 +308,12 @@ class SignalR(Signal): read_pv: str = Field(description="PV to use for readback") read_widget: ReadWidgetUnion = Field( - None, description="Widget to use for display. `TextRead` will be used if unset." + None, + description="Widget to use for display. `TextRead` will be used if unset.", + validate_default=True, ) - @field_validator("read_widget") + @field_validator("read_widget", mode="before") @classmethod def _validate_read_widget(cls, read_widget: Any): if read_widget is None: diff --git a/tests/format/input/signal_default_widgets.pvi.device.yaml b/tests/format/input/signal_default_widgets.pvi.device.yaml new file mode 100644 index 00000000..5d6cc223 --- /dev/null +++ b/tests/format/input/signal_default_widgets.pvi.device.yaml @@ -0,0 +1,25 @@ +# yaml-language-server: $schema=../../../schemas/pvi.device.schema.json + +label: label +children: + +- type: SignalR + name: Read + read_pv: Read + +- type: SignalW + name: Write + write_pv: Write + +- type: SignalRW + name: ReadWriteSingle + write_pv: ReadWriteSingle + +- type: SignalRW + name: ReadWrite + write_pv: ReadWrite + read_pv: ReadWrite_RBV + +- type: SignalX + name: Execute + write_pv: Execute diff --git a/tests/format/output/signal_default_widgets.bob b/tests/format/output/signal_default_widgets.bob new file mode 100644 index 00000000..b06b023a --- /dev/null +++ b/tests/format/output/signal_default_widgets.bob @@ -0,0 +1,138 @@ + + Display + 0 + 0 + 274 + 150 + 4 + 4 + + Title + TITLE + label + 0 + 0 + 274 + 26 + + + + + + + + + true + 1 + + + Label + Read + 22 + 30 + 120 + 20 + + + TextUpdate + Read + 146 + 30 + 124 + 20 + + + + + 1 + + + Label + Write + 22 + 54 + 120 + 20 + + + TextEntry + Write + 146 + 54 + 124 + 20 + 1 + + + Label + Read Write Single + 22 + 78 + 120 + 20 + + + TextEntry + ReadWriteSingle + 146 + 78 + 124 + 20 + 1 + + + Label + Read Write + 22 + 102 + 120 + 20 + + + TextEntry + ReadWrite + 146 + 102 + 60 + 20 + 1 + + + TextUpdate + ReadWrite_RBV + 210 + 102 + 60 + 20 + + + + + 1 + + + Label + Execute + 22 + 126 + 120 + 20 + + + WritePV + Execute + + + $(pv_name) + 1 + $(name) + + + Go + 146 + 126 + 124 + 20 + $(actions) + + diff --git a/tests/test_cli.py b/tests/test_cli.py index 877acd39..89204e56 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -49,6 +49,20 @@ def test_format(tmp_path, helper, filename, formatter): ) +def test_signal_default_widgets(tmp_path, helper): + expected_path = HERE / "format" / "output" / "signal_default_widgets.bob" + input_path = HERE / "format" / "input" + formatter_path = input_path / "dls.bob.pvi.formatter.yaml" + helper.assert_cli_output_matches( + app, + expected_path, + "format --yaml-path " + str(input_path), + tmp_path / "signal_default_widgets.bob", + HERE / "format" / "input" / "signal_default_widgets.pvi.device.yaml", + formatter_path, + ) + + def test_convert(tmp_path, helper): expected_path = HERE / "convert" / "output" input_path = HERE / "convert" / "input"