Revert "Revert "fix(deprecation): remove all remaining .dumps(), .loads() and producer->connector""

This reverts commit b12292246f
This commit is contained in:
2024-02-17 17:56:44 +01:00
committed by Mathias Guijarro
parent 12fda019df
commit f1e9d1ceaa
20 changed files with 90 additions and 97 deletions

View File

@ -27,7 +27,7 @@ def mock_det():
prefix = "X12SA-ES-EIGER9M:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
), mock.patch(
@ -50,7 +50,7 @@ def test_init():
prefix = "X12SA-ES-EIGER9M:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
), mock.patch(
@ -428,24 +428,24 @@ def test_publish_file_location(mock_det, scaninfo):
done=scaninfo["done"], successful=scaninfo["successful"]
)
if scaninfo["successful"] is None:
msg = messages.FileMessage(file_path=scaninfo["filepath"], done=scaninfo["done"]).dumps()
msg = messages.FileMessage(file_path=scaninfo["filepath"], done=scaninfo["done"])
else:
msg = messages.FileMessage(
file_path=scaninfo["filepath"], done=scaninfo["done"], successful=scaninfo["successful"]
).dumps()
)
expected_calls = [
mock.call(
MessageEndpoints.public_file(scaninfo["scanID"], mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
mock.call(
MessageEndpoints.file_event(mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
]
assert mock_det.producer.set_and_publish.call_args_list == expected_calls
assert mock_det.connector.set_and_publish.call_args_list == expected_calls
def test_stop(mock_det):

View File

@ -27,7 +27,7 @@ def mock_det():
prefix = "X12SA-SITORO:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
) as filemixin, mock.patch(
@ -215,24 +215,24 @@ def test_publish_file_location(mock_det, scaninfo):
done=scaninfo["done"], successful=scaninfo["successful"]
)
if scaninfo["successful"] is None:
msg = messages.FileMessage(file_path=scaninfo["filepath"], done=scaninfo["done"]).dumps()
msg = messages.FileMessage(file_path=scaninfo["filepath"], done=scaninfo["done"])
else:
msg = messages.FileMessage(
file_path=scaninfo["filepath"], done=scaninfo["done"], successful=scaninfo["successful"]
).dumps()
)
expected_calls = [
mock.call(
MessageEndpoints.public_file(scaninfo["scanID"], mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
mock.call(
MessageEndpoints.file_event(mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
]
assert mock_det.producer.set_and_publish.call_args_list == expected_calls
assert mock_det.connector.set_and_publish.call_args_list == expected_calls
@pytest.mark.parametrize(

View File

@ -32,7 +32,7 @@ def mock_det():
prefix = "X12SA-MCS:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
) as filemixin, mock.patch(
@ -53,7 +53,7 @@ def test_init():
prefix = "X12SA-ES-EIGER9M:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
), mock.patch(
@ -184,7 +184,7 @@ def test_send_data_to_bec(mock_det, metadata, mca_data):
mock_det.custom_prepare._send_data_to_bec()
device_metadata = mock_det.scaninfo.scan_msg.metadata
metadata.update({"async_update": "append", "num_lines": mock_det.num_lines.get()})
data = messages.DeviceMessage(signals=dict(mca_data), metadata=device_metadata).dumps()
data = messages.DeviceMessage(signals=dict(mca_data), metadata=device_metadata)
calls = mock.call(
topic=MessageEndpoints.device_async_readback(
scanID=metadata["scanID"], device=mock_det.name
@ -193,7 +193,7 @@ def test_send_data_to_bec(mock_det, metadata, mca_data):
expire=1800,
)
assert mock_det.producer.xadd.call_args == calls
assert mock_det.connector.xadd.call_args == calls
@pytest.mark.parametrize(

View File

@ -28,7 +28,7 @@ def mock_det():
prefix = "X12SA-ES-PILATUS300K:"
sim_mode = False
dm = DMMock()
with mock.patch.object(dm, "producer"):
with mock.patch.object(dm, "connector"):
with mock.patch(
"ophyd_devices.epics.devices.psi_detector_base.FileWriterMixin"
), mock.patch(
@ -207,27 +207,27 @@ def test_publish_file_location(mock_det, scaninfo):
file_path=scaninfo["filepath"],
done=scaninfo["done"],
metadata={"input_path": scaninfo["filepath_raw"]},
).dumps()
)
else:
msg = messages.FileMessage(
file_path=scaninfo["filepath"],
done=scaninfo["done"],
metadata={"input_path": scaninfo["filepath_raw"]},
successful=scaninfo["successful"],
).dumps()
)
expected_calls = [
mock.call(
MessageEndpoints.public_file(scaninfo["scanID"], mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
mock.call(
MessageEndpoints.file_event(mock_det.name),
msg,
pipe=mock_det.producer.pipeline.return_value,
pipe=mock_det.connector.pipeline.return_value,
),
]
assert mock_det.producer.set_and_publish.call_args_list == expected_calls
assert mock_det.connector.set_and_publish.call_args_list == expected_calls
@pytest.mark.parametrize(

View File

@ -1,7 +1,7 @@
from unittest import mock
from bec_lib.devicemanager import DeviceContainer
from bec_lib.tests.utils import ProducerMock
from bec_lib.tests.utils import ConnectorMock
class SocketMock:
@ -296,13 +296,13 @@ class DeviceMock:
class DMMock:
"""Mock for DeviceManager
The mocked DeviceManager creates a device containert and a producer.
The mocked DeviceManager creates a device containert and a connector.
"""
def __init__(self):
self.devices = DeviceContainer()
self.producer = ProducerMock()
self.connector = ConnectorMock()
def add_device(self, name: str, value: float = 0.0):
"""Add device to the DeviceManagerMock"""