Skip to content

Commit

Permalink
Merge pull request #78 from shilorigins/devagr/cl-return-com-error
Browse files Browse the repository at this point in the history
MNT: return error rather than raising in ControlLayer._get_single
  • Loading branch information
shilorigins authored Sep 9, 2024
2 parents b5763e1 + ea0f0ac commit c1685a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
22 changes: 22 additions & 0 deletions docs/source/upcoming_release_notes/78-cl_get_return_com_error.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
78 cl get return com error
#################

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

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

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

Maintenance
-----------
- ControlLayer._get_single: return CommunicationError rather than propagating

Contributors
------------
- shilorigins
10 changes: 7 additions & 3 deletions superscore/control_layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from superscore.control_layers._base_shim import EpicsData
from superscore.control_layers.status import TaskStatus
from superscore.errors import CommunicationError

from ._aioca import AiocaShim
from ._base_shim import _BaseShim
Expand Down Expand Up @@ -96,12 +97,15 @@ def get(self, address: Union[str, Iterable[str]]) -> Union[EpicsData, Iterable[E
"a string or list of strings")

@get.register
def _get_single(self, address: str) -> EpicsData:
def _get_single(self, address: str) -> Union[EpicsData, CommunicationError]:
"""Synchronously get a single ``address``"""
return asyncio.run(self._get_one(address))
try:
return asyncio.run(self._get_one(address))
except CommunicationError as e:
return e

@get.register
def _get_list(self, address: Iterable) -> Iterable[EpicsData]:
def _get_list(self, address: Iterable) -> Iterable[Union[EpicsData, CommunicationError]]:
"""Synchronously get a list of ``address``"""
async def gathered_coros():
coros = []
Expand Down
7 changes: 7 additions & 0 deletions superscore/tests/test_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from superscore.control_layers.status import TaskStatus
from superscore.errors import CommunicationError


def test_get(dummy_cl):
Expand All @@ -17,6 +18,12 @@ def test_get(dummy_cl):
assert dummy_cl.get(['a', 'b', 'c']) == ["ca_value" for i in range(3)]


def test_get_communication_error(dummy_cl):
mock_get = AsyncMock(side_effect=CommunicationError("Example error"))
dummy_cl.shims['ca'].get = mock_get
assert isinstance(dummy_cl.get("SOME_PREFIX"), CommunicationError)


def test_put(dummy_cl):
result = dummy_cl.put("OTHER:PREFIX", 4)
assert isinstance(result, TaskStatus)
Expand Down

0 comments on commit c1685a0

Please sign in to comment.