Skip to content

Commit

Permalink
Merge branch 'master' into mnt_common_views
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong authored Sep 6, 2024
2 parents 7a07729 + aaa05b7 commit 7e8f9e1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
23 changes: 23 additions & 0 deletions docs/source/upcoming_release_notes/77-mnt_snap_ro_readback.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
77 mnt_snap_ro_readback
#######################

API Breaks
----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- N/A

Maintenance
-----------
- Adjusts Client.snap so that if a `Parameter` in a `Collection` is marked as
read_only=True, it should be captured as a `Readback` in the corresponding `Snapshot`.

Contributors
------------
- tangkong
34 changes: 24 additions & 10 deletions superscore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,34 @@ def _build_snapshot(
description=child.readback.description,
data=edata.data,
status=edata.status,
severity=edata.severity
severity=edata.severity,
rel_tolerance=child.readback.rel_tolerance,
abs_tolerance=child.readback.abs_tolerance,
)
else:
readback = None
edata = self._value_or_default(values.get(child.pv_name, None))
setpoint = Setpoint(
pv_name=child.pv_name,
description=child.description,
data=edata.data,
status=edata.status,
severity=edata.severity,
readback=readback
)
snapshot.children.append(setpoint)
if child.read_only:
# create a readback and propagate tolerances
new_entry = Readback(
pv_name=child.pv_name,
description=child.description,
data=edata.data,
status=edata.status,
severity=edata.severity,
rel_tolerance=child.rel_tolerance,
abs_tolerance=child.abs_tolerance,
)
else:
new_entry = Setpoint(
pv_name=child.pv_name,
description=child.description,
data=edata.data,
status=edata.status,
severity=edata.severity,
readback=readback
)
snapshot.children.append(new_entry)
elif isinstance(child, Collection):
snapshot.children.append(self._build_snapshot(child, values))

Expand Down
22 changes: 21 additions & 1 deletion superscore/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from superscore.client import Client
from superscore.control_layers import EpicsData
from superscore.errors import CommunicationError
from superscore.model import Parameter, Readback, Root, Setpoint
from superscore.model import Collection, Parameter, Readback, Root, Setpoint

from .conftest import MockTaskStatus

Expand Down Expand Up @@ -104,6 +104,26 @@ def test_snap_exception(get_mock, mock_client: Client, sample_database: Root):
assert snapshot.children[2].data is None


@patch('superscore.control_layers.core.ControlLayer._get_one')
def test_snap_RO(get_mock, mock_client: Client, sample_database: Root):
coll: Collection = sample_database.entries[2]
coll.children.append(
Parameter(pv_name="RO:PV",
abs_tolerance=1,
rel_tolerance=-.1,
read_only=True)
)
get_mock.side_effect = [EpicsData(i) for i in range(5)]
snapshot = mock_client.snap(coll)

assert get_mock.call_count == 4
for coll_child, snap_child in zip(coll.children, snapshot.children):
if coll_child.read_only:
assert isinstance(snap_child, Readback)
else:
assert isinstance(snap_child, Setpoint)


def test_from_cfg(sscore_cfg: str):
client = Client.from_config()
assert isinstance(client.backend, FilestoreBackend)
Expand Down

0 comments on commit 7e8f9e1

Please sign in to comment.