mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(cli): fixed support for devices as cli input
This commit is contained in:
@ -36,6 +36,17 @@ def rpc_call(func):
|
|||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
|
# we could rely on a strict type check here, but this is more flexible
|
||||||
|
# moreover, it would anyway crash for objects...
|
||||||
|
out = []
|
||||||
|
for arg in args:
|
||||||
|
if hasattr(arg, "name"):
|
||||||
|
arg = arg.name
|
||||||
|
out.append(arg)
|
||||||
|
args = tuple(out)
|
||||||
|
for key, val in kwargs.items():
|
||||||
|
if hasattr(val, "name"):
|
||||||
|
kwargs[key] = val.name
|
||||||
if not self.gui_is_alive():
|
if not self.gui_is_alive():
|
||||||
raise RuntimeError("GUI is not alive")
|
raise RuntimeError("GUI is not alive")
|
||||||
return self._run_rpc(func.__name__, *args, **kwargs)
|
return self._run_rpc(func.__name__, *args, **kwargs)
|
||||||
|
29
tests/unit_tests/test_client_utils.py
Normal file
29
tests/unit_tests/test_client_utils.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from bec_widgets.cli.client import BECFigure
|
||||||
|
|
||||||
|
from .client_mocks import FakeDevice
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def cli_figure():
|
||||||
|
fig = BECFigure(gui_id="test")
|
||||||
|
with mock.patch.object(fig, "_run_rpc") as mock_rpc_call:
|
||||||
|
with mock.patch.object(fig, "gui_is_alive", return_value=True):
|
||||||
|
yield fig, mock_rpc_call
|
||||||
|
|
||||||
|
|
||||||
|
def test_rpc_call_plot(cli_figure):
|
||||||
|
fig, mock_rpc_call = cli_figure
|
||||||
|
fig.plot("samx", "bpm4i")
|
||||||
|
mock_rpc_call.assert_called_with("plot", "samx", "bpm4i")
|
||||||
|
|
||||||
|
|
||||||
|
def test_rpc_call_accepts_device_as_input(cli_figure):
|
||||||
|
dev1 = FakeDevice("samx")
|
||||||
|
dev2 = FakeDevice("bpm4i")
|
||||||
|
fig, mock_rpc_call = cli_figure
|
||||||
|
fig.plot(dev1, dev2)
|
||||||
|
mock_rpc_call.assert_called_with("plot", "samx", "bpm4i")
|
Reference in New Issue
Block a user