Skip to content

Commit d3a4858

Browse files
authored
Fix command buttons in pva transport (#294)
Remove uneeded controller_api fixture from some tests
1 parent c86f760 commit d3a4858

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

src/fastcs/transports/epics/gui.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
class EpicsGUI:
4545
"""For creating gui in the EPICS transports."""
4646

47+
command_value = "1"
48+
4749
def __init__(self, controller_api: ControllerAPI, pv_prefix: str) -> None:
4850
self._controller_api = controller_api
4951
self._pv_prefix = pv_prefix
@@ -133,8 +135,7 @@ def _get_command_component(self, attr_path: list[str], name: str):
133135
return SignalX(
134136
name=name,
135137
write_pv=pv,
136-
value="1",
137-
write_widget=ButtonPanel(actions={name: "1"}),
138+
write_widget=ButtonPanel(actions={name: self.command_value}),
138139
)
139140

140141
def create_gui(self, options: EpicsGUIOptions | None = None) -> None:

src/fastcs/transports/epics/pva/gui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
class PvaEpicsGUI(EpicsGUI):
1414
"""For creating gui in the PVA EPICS transport."""
1515

16+
command_value = "true"
17+
1618
def _get_pv(self, attr_path: list[str], name: str):
1719
return f"pva://{super()._get_pv(attr_path, name)}"
1820

tests/transports/epics/ca/test_gui.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from fastcs.transports.epics.gui import EpicsGUI
2424

2525

26-
def test_get_pv(controller_api):
27-
gui = EpicsGUI(controller_api, "DEVICE")
26+
def test_get_pv():
27+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
2828

2929
assert gui._get_pv([], "A") == "DEVICE:A"
3030
assert gui._get_pv(["B"], "C") == "DEVICE:B:C"
@@ -42,8 +42,8 @@ def test_get_pv(controller_api):
4242
# (Waveform(array_dtype=np.int32), None),
4343
],
4444
)
45-
def test_get_attribute_component_r(datatype, widget, controller_api):
46-
gui = EpicsGUI(controller_api, "DEVICE")
45+
def test_get_attribute_component_r(datatype, widget):
46+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
4747

4848
assert gui._get_attribute_component([], "Attr", AttrR(datatype)) == SignalR(
4949
name="Attr", read_pv="Attr", read_widget=widget
@@ -60,16 +60,16 @@ def test_get_attribute_component_r(datatype, widget, controller_api):
6060
(Enum(ColourEnum), ComboBox(choices=["RED", "GREEN", "BLUE"])),
6161
],
6262
)
63-
def test_get_attribute_component_w(datatype, widget, controller_api):
64-
gui = EpicsGUI(controller_api, "DEVICE")
63+
def test_get_attribute_component_w(datatype, widget):
64+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
6565

6666
assert gui._get_attribute_component([], "Attr", AttrW(datatype)) == SignalW(
6767
name="Attr", write_pv="Attr", write_widget=widget
6868
)
6969

7070

71-
def test_get_attribute_component_none(mocker, controller_api):
72-
gui = EpicsGUI(controller_api, "DEVICE")
71+
def test_get_attribute_component_none(mocker):
72+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
7373

7474
mocker.patch.object(gui, "_get_read_widget", return_value=None)
7575
mocker.patch.object(gui, "_get_write_widget", return_value=None)
@@ -78,13 +78,13 @@ def test_get_attribute_component_none(mocker, controller_api):
7878
assert gui._get_attribute_component([], "Attr", AttrRW(Int())) is None
7979

8080

81-
def test_get_read_widget_none(controller_api):
82-
gui = EpicsGUI(controller_api, "DEVICE")
81+
def test_get_read_widget_none():
82+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
8383
assert gui._get_read_widget(fastcs_datatype=Waveform(np.int32)) is None
8484

8585

86-
def test_get_write_widget_none(controller_api):
87-
gui = EpicsGUI(controller_api, "DEVICE")
86+
def test_get_write_widget_none():
87+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
8888
assert gui._get_write_widget(fastcs_datatype=Waveform(np.int32)) is None
8989

9090

@@ -164,3 +164,12 @@ def test_get_components_none(mocker):
164164
components = gui.extract_api_components(controller_api)
165165

166166
assert components == []
167+
168+
169+
def test_get_command_component():
170+
gui = EpicsGUI(ControllerAPI(), "DEVICE")
171+
172+
component = gui._get_command_component([], "Command")
173+
174+
assert isinstance(component, SignalX)
175+
assert component.write_widget == ButtonPanel(actions={"Command": "1"})

tests/transports/epics/pva/test_pva_gui.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import numpy as np
22
from pvi.device import (
33
LED,
4+
ButtonPanel,
45
CheckBox,
56
SignalR,
67
SignalW,
8+
SignalX,
79
TableRead,
810
TableWrite,
911
TextFormat,
@@ -13,19 +15,20 @@
1315

1416
from fastcs.attributes import AttrR, AttrW
1517
from fastcs.datatypes import Table
18+
from fastcs.transports import ControllerAPI
1619
from fastcs.transports.epics.pva.gui import PvaEpicsGUI
1720

1821

19-
def test_get_pv_in_pva(controller_api):
20-
gui = PvaEpicsGUI(controller_api, "DEVICE")
22+
def test_get_pv_in_pva():
23+
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")
2124

2225
assert gui._get_pv([], "A") == "pva://DEVICE:A"
2326
assert gui._get_pv(["B"], "C") == "pva://DEVICE:B:C"
2427
assert gui._get_pv(["D", "E"], "F") == "pva://DEVICE:D:E:F"
2528

2629

27-
def test_get_attribute_component_table_write(controller_api):
28-
gui = PvaEpicsGUI(controller_api, "DEVICE")
30+
def test_get_attribute_component_table_write():
31+
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")
2932

3033
attribute_component = gui._get_attribute_component(
3134
[],
@@ -50,8 +53,8 @@ def test_get_attribute_component_table_write(controller_api):
5053
]
5154

5255

53-
def test_get_attribute_component_table_read(controller_api):
54-
gui = PvaEpicsGUI(controller_api, "DEVICE")
56+
def test_get_attribute_component_table_read():
57+
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")
5558

5659
attribute_component = gui._get_attribute_component(
5760
[],
@@ -74,3 +77,12 @@ def test_get_attribute_component_table_read(controller_api):
7477
LED(),
7578
TextRead(format=TextFormat.string),
7679
]
80+
81+
82+
def test_get_command_component():
83+
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")
84+
85+
component = gui._get_command_component([], "Command")
86+
87+
assert isinstance(component, SignalX)
88+
assert component.write_widget == ButtonPanel(actions={"Command": "true"})

0 commit comments

Comments
 (0)