mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
test: added test_start_zmq_consumer for eiger_plot.py
This commit is contained in:
0
bec_widgets/examples/eiger_plot/__init__.py
Normal file
0
bec_widgets/examples/eiger_plot/__init__.py
Normal file
@ -1,6 +1,10 @@
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch, Mock
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
import zmq
|
||||
import json
|
||||
from PyQt5.QtWidgets import QPushButton
|
||||
from bec_widgets.examples.eiger_plot.eiger_plot import EigerPlot
|
||||
|
||||
|
||||
@ -13,7 +17,7 @@ def eiger_plot_instance(qtbot):
|
||||
|
||||
|
||||
# Tests for on_image_update method
|
||||
class TestOnImageUpdate:
|
||||
# class TestOnImageUpdate:
|
||||
@pytest.mark.parametrize(
|
||||
"fft_checked, rotation_index, transpose_checked, log_checked, expected_image",
|
||||
[
|
||||
@ -26,7 +30,6 @@ class TestOnImageUpdate:
|
||||
],
|
||||
)
|
||||
def test_on_image_update(
|
||||
self,
|
||||
qtbot,
|
||||
eiger_plot_instance,
|
||||
fft_checked,
|
||||
@ -60,3 +63,49 @@ class TestOnImageUpdate:
|
||||
eiger_plot_instance.imageItem.setImage.assert_called_with(
|
||||
eiger_plot_instance.image, autoLevels=False
|
||||
)
|
||||
|
||||
|
||||
def test_init_ui(eiger_plot_instance):
|
||||
assert isinstance(eiger_plot_instance.plot_item, pg.PlotItem)
|
||||
assert isinstance(eiger_plot_instance.imageItem, pg.ImageItem)
|
||||
assert isinstance(eiger_plot_instance.hist, pg.HistogramLUTItem)
|
||||
|
||||
|
||||
def test_start_zmq_consumer(eiger_plot_instance):
|
||||
with patch("threading.Thread") as MockThread:
|
||||
eiger_plot_instance.start_zmq_consumer()
|
||||
MockThread.assert_called_once()
|
||||
MockThread.return_value.start.assert_called_once()
|
||||
|
||||
|
||||
# TODO fix this test
|
||||
|
||||
# def test_zmq_consumer(eiger_plot_instance):
|
||||
# fake_meta = json.dumps({"type": "int32", "shape": (2, 2)}).encode("utf-8")
|
||||
# fake_data = np.array([[1, 2], [3, 4]], dtype="int32").tobytes()
|
||||
#
|
||||
# with patch("zmq.Context") as MockContext:
|
||||
# # Mocking zmq socket and its methods
|
||||
# mock_socket = MagicMock()
|
||||
# MockContext().socket.return_value = mock_socket
|
||||
# mock_socket.recv_multipart.return_value = [fake_meta, fake_data]
|
||||
#
|
||||
# # Mocking the update_signal to check if it gets emitted
|
||||
# eiger_plot_instance.update_signal = MagicMock()
|
||||
#
|
||||
# # Run the method under test
|
||||
# eiger_plot_instance.zmq_consumer()
|
||||
#
|
||||
# # Check if zmq methods are called
|
||||
# MockContext.assert_called_once()
|
||||
# mock_socket.connect.assert_called_with("tcp://129.129.95.38:20000")
|
||||
# mock_socket.setsockopt_string.assert_called_with(zmq.SUBSCRIBE, "")
|
||||
# mock_socket.recv_multipart.assert_called_once()
|
||||
#
|
||||
# # Check if update_signal was emitted
|
||||
# eiger_plot_instance.update_signal.emit.assert_called_once()
|
||||
#
|
||||
# # Validate the image data
|
||||
# np.testing.assert_array_equal(
|
||||
# eiger_plot_instance.image, np.array([[1, 2], [3, 4]], dtype="int32")
|
||||
# )
|
||||
|
Reference in New Issue
Block a user