Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/fastcs/transports/epics/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class EpicsGUI:
"""For creating gui in the EPICS transports."""

command_value = "1"

def __init__(self, controller_api: ControllerAPI, pv_prefix: str) -> None:
self._controller_api = controller_api
self._pv_prefix = pv_prefix
Expand Down Expand Up @@ -133,8 +135,7 @@ def _get_command_component(self, attr_path: list[str], name: str):
return SignalX(
name=name,
write_pv=pv,
value="1",
write_widget=ButtonPanel(actions={name: "1"}),
write_widget=ButtonPanel(actions={name: self.command_value}),
)

def create_gui(self, options: EpicsGUIOptions | None = None) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/fastcs/transports/epics/pva/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class PvaEpicsGUI(EpicsGUI):
"""For creating gui in the PVA EPICS transport."""

command_value = "true"

def _get_pv(self, attr_path: list[str], name: str):
return f"pva://{super()._get_pv(attr_path, name)}"

Expand Down
33 changes: 21 additions & 12 deletions tests/transports/epics/ca/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from fastcs.transports.epics.gui import EpicsGUI


def test_get_pv(controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_pv():
gui = EpicsGUI(ControllerAPI(), "DEVICE")

assert gui._get_pv([], "A") == "DEVICE:A"
assert gui._get_pv(["B"], "C") == "DEVICE:B:C"
Expand All @@ -42,8 +42,8 @@ def test_get_pv(controller_api):
# (Waveform(array_dtype=np.int32), None),
],
)
def test_get_attribute_component_r(datatype, widget, controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_attribute_component_r(datatype, widget):
gui = EpicsGUI(ControllerAPI(), "DEVICE")

assert gui._get_attribute_component([], "Attr", AttrR(datatype)) == SignalR(
name="Attr", read_pv="Attr", read_widget=widget
Expand All @@ -60,16 +60,16 @@ def test_get_attribute_component_r(datatype, widget, controller_api):
(Enum(ColourEnum), ComboBox(choices=["RED", "GREEN", "BLUE"])),
],
)
def test_get_attribute_component_w(datatype, widget, controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_attribute_component_w(datatype, widget):
gui = EpicsGUI(ControllerAPI(), "DEVICE")

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


def test_get_attribute_component_none(mocker, controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_attribute_component_none(mocker):
gui = EpicsGUI(ControllerAPI(), "DEVICE")

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


def test_get_read_widget_none(controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_read_widget_none():
gui = EpicsGUI(ControllerAPI(), "DEVICE")
assert gui._get_read_widget(fastcs_datatype=Waveform(np.int32)) is None


def test_get_write_widget_none(controller_api):
gui = EpicsGUI(controller_api, "DEVICE")
def test_get_write_widget_none():
gui = EpicsGUI(ControllerAPI(), "DEVICE")
assert gui._get_write_widget(fastcs_datatype=Waveform(np.int32)) is None


Expand Down Expand Up @@ -164,3 +164,12 @@ def test_get_components_none(mocker):
components = gui.extract_api_components(controller_api)

assert components == []


def test_get_command_component():
gui = EpicsGUI(ControllerAPI(), "DEVICE")

component = gui._get_command_component([], "Command")

assert isinstance(component, SignalX)
assert component.write_widget == ButtonPanel(actions={"Command": "1"})
24 changes: 18 additions & 6 deletions tests/transports/epics/pva/test_pva_gui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import numpy as np
from pvi.device import (
LED,
ButtonPanel,
CheckBox,
SignalR,
SignalW,
SignalX,
TableRead,
TableWrite,
TextFormat,
Expand All @@ -13,19 +15,20 @@

from fastcs.attributes import AttrR, AttrW
from fastcs.datatypes import Table
from fastcs.transports import ControllerAPI
from fastcs.transports.epics.pva.gui import PvaEpicsGUI


def test_get_pv_in_pva(controller_api):
gui = PvaEpicsGUI(controller_api, "DEVICE")
def test_get_pv_in_pva():
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")

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


def test_get_attribute_component_table_write(controller_api):
gui = PvaEpicsGUI(controller_api, "DEVICE")
def test_get_attribute_component_table_write():
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")

attribute_component = gui._get_attribute_component(
[],
Expand All @@ -50,8 +53,8 @@ def test_get_attribute_component_table_write(controller_api):
]


def test_get_attribute_component_table_read(controller_api):
gui = PvaEpicsGUI(controller_api, "DEVICE")
def test_get_attribute_component_table_read():
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")

attribute_component = gui._get_attribute_component(
[],
Expand All @@ -74,3 +77,12 @@ def test_get_attribute_component_table_read(controller_api):
LED(),
TextRead(format=TextFormat.string),
]


def test_get_command_component():
gui = PvaEpicsGUI(ControllerAPI(), "DEVICE")

component = gui._get_command_component([], "Command")

assert isinstance(component, SignalX)
assert component.write_widget == ButtonPanel(actions={"Command": "true"})