Skip to content

Commit

Permalink
TST #881
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jan 9, 2024
1 parent 4ab77b4 commit cfdf1ff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
40 changes: 37 additions & 3 deletions apstools/utils/tests/test_listdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from ophyd import Signal
from ophyd.signal import EpicsSignalBase

from .._core import TableStyle
from ...devices import SwaitRecord
from ...tests import IOC_GP
from ..device_info import _list_epics_signals
from .._core import TableStyle
from ..device_info import DEFAULT_COLUMN_WIDTH
from ..device_info import listdevice
from ..device_info import NOT_CONNECTED_VALUE
from ..device_info import _list_epics_signals
from ..device_info import listdevice


class MySignals(Device):
Expand Down Expand Up @@ -208,3 +208,37 @@ def test_maximum_column_width(width):
if width is not None:
for column, content in enumerate(result[0].split()):
assert len(content) <= (width), f"{column=} {content=}"


@pytest.mark.parametrize(
"sig, has_cname, has_dname, has_PV",
[
[{}, False, True, False],
[{"cname": True, "dname": False}, True, False, False],
[{"cname": True}, True, True, False],
[{"show_pv": False}, False, True, False],
[{"show_pv": True, "cname": False, "dname": True}, False, True, True],
[{"show_pv": True, "cname": False}, True, False, True],
[{"show_pv": True, "cname": True, "dname": False}, True, False, True],
[{"show_pv": True, "cname": True}, True, False, True],
[{"show_pv": True, "dname": False}, True, False, True],
[{"show_pv": True, "dname": True}, True, True, True],
[{"show_pv": True}, True, False, True],
],
)
def test_listdevice_show_pv(sig, has_cname, has_dname, has_PV):
line = str(listdevice(motor, **sig)).splitlines()[1].strip()
if has_cname:
assert line.split()[0] == "name", f"{line=}"
else:
assert line.split()[0] != "name", f"{line=}"

if has_dname:
assert "data name" in line, f"{line=}"
else:
assert "data name" not in line, f"{line=}"

if has_PV:
assert "PV" in line, f"{line=}"
else:
assert "PV" not in line, f"{line=}"
34 changes: 34 additions & 0 deletions apstools/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ... import utils
from .._core import MAX_EPICS_STRINGOUT_LENGTH
from .._core import TableStyle
from ..misc import call_signature_decorator

CATALOG = "usaxs_test"
COUNT = "555a604" # <-- uid, scan_id: 2
Expand Down Expand Up @@ -530,3 +531,36 @@ def test_utils_getStreamValues_Exception(
def test_count_common_subdirs(p1, p2, expected):
icommon = utils.count_common_subdirs(p1, p2)
assert icommon == expected, f"{p1=} {p2=}"


@pytest.mark.parametrize(
"args, kwargs, expect",
[
[[1], {}, (False, False, False, False)],
[[1], {}, (False, False, False, False)],
[[1, 2], {}, (True, False, False, False)],
[[1, 2], {"show_pv": 1}, (True, False, False, True)],
[[1], {"cname": 1}, (False, True, False, False)],
[[1], {"dname": 1}, (False, False, True, False)],
[[1], {"b": 1, "cname": 1}, (True, True, False, False)],
[[1], {"b": 1, "dname": 1}, (True, False, True, False)],
[[1], {"show_pv": 1, "cname": False}, (False, True, False, True)],
[[1], {"show_pv": 1, "cname": True}, (False, True, False, True)],
[[1], {"show_pv": 1, "dname": False}, (False, False, True, True)],
[[1], {"show_pv": 1, "dname": True}, (False, False, True, True)],
[[1], {"show_pv": 1, "dname": False, "cname": False}, (False, True, True, True)],
[[1], {"show_pv": 1, "dname": True, "cname": True}, (False, True, True, True)],
],
)
def test_call_signature_decorator(args, kwargs, expect):
@call_signature_decorator
def func1(a, b=1, *, cname=False, dname=True, show_pv=None, _call_args=None):
return (
"b" in _call_args,
"cname" in _call_args,
"dname" in _call_args,
"show_pv" in _call_args,
)

result = func1(*args, **kwargs)
assert result == expect, f"{result=} {expect=}"

0 comments on commit cfdf1ff

Please sign in to comment.