mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
test: use factory instead of fixture to properly cleanup widgets on teardown
This commit is contained in:
@ -9,18 +9,11 @@ from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap
|
|||||||
from bec_widgets.widgets.figure.plots.waveform.waveform import BECWaveform
|
from bec_widgets.widgets.figure.plots.waveform.waveform import BECWaveform
|
||||||
|
|
||||||
from .client_mocks import mocked_client
|
from .client_mocks import mocked_client
|
||||||
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_bec_figure_init(qtbot, mocked_client):
|
||||||
def bec_figure(qtbot, mocked_client):
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
widget = BECFigure(client=mocked_client)
|
|
||||||
qtbot.addWidget(widget)
|
|
||||||
qtbot.waitExposed(widget)
|
|
||||||
yield widget
|
|
||||||
widget.close()
|
|
||||||
|
|
||||||
|
|
||||||
def test_bec_figure_init(bec_figure):
|
|
||||||
assert bec_figure is not None
|
assert bec_figure is not None
|
||||||
assert bec_figure.client is not None
|
assert bec_figure.client is not None
|
||||||
assert isinstance(bec_figure, BECFigure)
|
assert isinstance(bec_figure, BECFigure)
|
||||||
@ -34,7 +27,8 @@ def test_bec_figure_init_with_config(mocked_client):
|
|||||||
assert widget.config.theme == "dark"
|
assert widget.config.theme == "dark"
|
||||||
|
|
||||||
|
|
||||||
def test_bec_figure_add_remove_plot(bec_figure):
|
def test_bec_figure_add_remove_plot(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
initial_count = len(bec_figure._widgets)
|
initial_count = len(bec_figure._widgets)
|
||||||
|
|
||||||
# Adding 3 widgets - 2 WaveformBase and 1 PlotBase
|
# Adding 3 widgets - 2 WaveformBase and 1 PlotBase
|
||||||
@ -64,7 +58,8 @@ def test_bec_figure_add_remove_plot(bec_figure):
|
|||||||
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
||||||
|
|
||||||
|
|
||||||
def test_add_different_types_of_widgets(bec_figure):
|
def test_add_different_types_of_widgets(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
||||||
im = bec_figure.image("eiger")
|
im = bec_figure.image("eiger")
|
||||||
motor_map = bec_figure.motor_map("samx", "samy")
|
motor_map = bec_figure.motor_map("samx", "samy")
|
||||||
@ -74,7 +69,8 @@ def test_add_different_types_of_widgets(bec_figure):
|
|||||||
assert motor_map.__class__ == BECMotorMap
|
assert motor_map.__class__ == BECMotorMap
|
||||||
|
|
||||||
|
|
||||||
def test_access_widgets_access_errors(bec_figure):
|
def test_access_widgets_access_errors(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot(row=0, col=0)
|
bec_figure.plot(row=0, col=0)
|
||||||
|
|
||||||
# access widget by non-existent coordinates
|
# access widget by non-existent coordinates
|
||||||
@ -96,7 +92,8 @@ def test_access_widgets_access_errors(bec_figure):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_add_plot_to_occupied_position(bec_figure):
|
def test_add_plot_to_occupied_position(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot(row=0, col=0)
|
bec_figure.plot(row=0, col=0)
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
@ -104,7 +101,8 @@ def test_add_plot_to_occupied_position(bec_figure):
|
|||||||
assert "Position at row 0 and column 0 is already occupied." in str(excinfo.value)
|
assert "Position at row 0 and column 0 is already occupied." in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plots(bec_figure):
|
def test_remove_plots(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot(row=0, col=0)
|
w1 = bec_figure.plot(row=0, col=0)
|
||||||
w2 = bec_figure.plot(row=0, col=1)
|
w2 = bec_figure.plot(row=0, col=1)
|
||||||
w3 = bec_figure.plot(row=1, col=0)
|
w3 = bec_figure.plot(row=1, col=0)
|
||||||
@ -134,7 +132,8 @@ def test_remove_plots(bec_figure):
|
|||||||
assert len(bec_figure._widgets) == 1
|
assert len(bec_figure._widgets) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plots_by_coordinates_ints(bec_figure):
|
def test_remove_plots_by_coordinates_ints(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot(row=0, col=0)
|
w1 = bec_figure.plot(row=0, col=0)
|
||||||
w2 = bec_figure.plot(row=0, col=1)
|
w2 = bec_figure.plot(row=0, col=1)
|
||||||
|
|
||||||
@ -145,7 +144,8 @@ def test_remove_plots_by_coordinates_ints(bec_figure):
|
|||||||
assert len(bec_figure._widgets) == 1
|
assert len(bec_figure._widgets) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plots_by_coordinates_tuple(bec_figure):
|
def test_remove_plots_by_coordinates_tuple(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot(row=0, col=0)
|
w1 = bec_figure.plot(row=0, col=0)
|
||||||
w2 = bec_figure.plot(row=0, col=1)
|
w2 = bec_figure.plot(row=0, col=1)
|
||||||
|
|
||||||
@ -156,7 +156,8 @@ def test_remove_plots_by_coordinates_tuple(bec_figure):
|
|||||||
assert len(bec_figure._widgets) == 1
|
assert len(bec_figure._widgets) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plot_by_id_error(bec_figure):
|
def test_remove_plot_by_id_error(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot()
|
bec_figure.plot()
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
@ -164,7 +165,8 @@ def test_remove_plot_by_id_error(bec_figure):
|
|||||||
assert "Widget with ID 'non_existent_widget' does not exist." in str(excinfo.value)
|
assert "Widget with ID 'non_existent_widget' does not exist." in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plot_by_coordinates_error(bec_figure):
|
def test_remove_plot_by_coordinates_error(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot(row=0, col=0)
|
bec_figure.plot(row=0, col=0)
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
@ -172,7 +174,8 @@ def test_remove_plot_by_coordinates_error(bec_figure):
|
|||||||
assert "No widget at coordinates (0, 1)" in str(excinfo.value)
|
assert "No widget at coordinates (0, 1)" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_plot_by_providing_nothing(bec_figure):
|
def test_remove_plot_by_providing_nothing(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot(row=0, col=0)
|
bec_figure.plot(row=0, col=0)
|
||||||
|
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
@ -192,7 +195,8 @@ def test_remove_plot_by_providing_nothing(bec_figure):
|
|||||||
# assert bec_figure.backgroundBrush().color().name() == "#000000"
|
# assert bec_figure.backgroundBrush().color().name() == "#000000"
|
||||||
|
|
||||||
|
|
||||||
def test_change_layout(bec_figure):
|
def test_change_layout(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot(row=0, col=0)
|
w1 = bec_figure.plot(row=0, col=0)
|
||||||
w2 = bec_figure.plot(row=0, col=1)
|
w2 = bec_figure.plot(row=0, col=1)
|
||||||
w3 = bec_figure.plot(row=1, col=0)
|
w3 = bec_figure.plot(row=1, col=0)
|
||||||
@ -215,7 +219,8 @@ def test_change_layout(bec_figure):
|
|||||||
assert bec_figure[0, 3] == w4
|
assert bec_figure[0, 3] == w4
|
||||||
|
|
||||||
|
|
||||||
def test_clear_all(bec_figure):
|
def test_clear_all(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
bec_figure.plot(row=0, col=0)
|
bec_figure.plot(row=0, col=0)
|
||||||
bec_figure.plot(row=0, col=1)
|
bec_figure.plot(row=0, col=1)
|
||||||
bec_figure.plot(row=1, col=0)
|
bec_figure.plot(row=1, col=0)
|
||||||
@ -227,7 +232,8 @@ def test_clear_all(bec_figure):
|
|||||||
assert np.shape(bec_figure.grid) == (0,)
|
assert np.shape(bec_figure.grid) == (0,)
|
||||||
|
|
||||||
|
|
||||||
def test_shortcuts(bec_figure):
|
def test_shortcuts(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
||||||
im = bec_figure.image("eiger")
|
im = bec_figure.image("eiger")
|
||||||
motor_map = bec_figure.motor_map("samx", "samy")
|
motor_map = bec_figure.motor_map("samx", "samy")
|
||||||
@ -240,7 +246,8 @@ def test_shortcuts(bec_figure):
|
|||||||
assert motor_map.__class__ == BECMotorMap
|
assert motor_map.__class__ == BECMotorMap
|
||||||
|
|
||||||
|
|
||||||
def test_plot_access_factory(bec_figure):
|
def test_plot_access_factory(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plt_00 = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
plt_00 = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
||||||
plt_01 = bec_figure.plot(x_name="samx", y_name="bpm4i", row=0, col=1)
|
plt_01 = bec_figure.plot(x_name="samx", y_name="bpm4i", row=0, col=1)
|
||||||
plt_10 = bec_figure.plot(new=True)
|
plt_10 = bec_figure.plot(new=True)
|
||||||
|
@ -6,8 +6,10 @@ import pytest
|
|||||||
from bec_lib import messages
|
from bec_lib import messages
|
||||||
from qtpy.QtGui import QFontInfo
|
from qtpy.QtGui import QFontInfo
|
||||||
|
|
||||||
|
from bec_widgets.widgets.figure import BECFigure
|
||||||
|
|
||||||
from .client_mocks import mocked_client
|
from .client_mocks import mocked_client
|
||||||
from .test_bec_figure import bec_figure
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -15,7 +17,8 @@ def bec_image_show(bec_figure):
|
|||||||
yield bec_figure.image("eiger")
|
yield bec_figure.image("eiger")
|
||||||
|
|
||||||
|
|
||||||
def test_on_image_update(bec_image_show):
|
def test_on_image_update(qtbot, mocked_client):
|
||||||
|
bec_image_show = create_widget(qtbot, BECFigure, client=mocked_client).image("eiger")
|
||||||
data = np.random.rand(100, 100)
|
data = np.random.rand(100, 100)
|
||||||
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
||||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||||
@ -23,7 +26,8 @@ def test_on_image_update(bec_image_show):
|
|||||||
assert np.array_equal(img.get_data(), data)
|
assert np.array_equal(img.get_data(), data)
|
||||||
|
|
||||||
|
|
||||||
def test_autorange_on_image_update(bec_image_show):
|
def test_autorange_on_image_update(qtbot, mocked_client):
|
||||||
|
bec_image_show = create_widget(qtbot, BECFigure, client=mocked_client).image("eiger")
|
||||||
# Check if autorange mode "mean" works, should be default
|
# Check if autorange mode "mean" works, should be default
|
||||||
data = np.random.rand(100, 100)
|
data = np.random.rand(100, 100)
|
||||||
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
||||||
|
@ -2,14 +2,16 @@ import numpy as np
|
|||||||
import pytest
|
import pytest
|
||||||
from bec_lib.messages import DeviceMessage
|
from bec_lib.messages import DeviceMessage
|
||||||
|
|
||||||
|
from bec_widgets.widgets.figure import BECFigure
|
||||||
from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap, MotorMapConfig
|
from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap, MotorMapConfig
|
||||||
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import SignalData
|
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import SignalData
|
||||||
|
|
||||||
from .client_mocks import mocked_client
|
from .client_mocks import mocked_client
|
||||||
from .test_bec_figure import bec_figure
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_init(bec_figure):
|
def test_motor_map_init(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
default_config = MotorMapConfig(widget_class="BECMotorMap")
|
default_config = MotorMapConfig(widget_class="BECMotorMap")
|
||||||
|
|
||||||
mm = bec_figure.motor_map(config=default_config.model_dump())
|
mm = bec_figure.motor_map(config=default_config.model_dump())
|
||||||
@ -18,7 +20,8 @@ def test_motor_map_init(bec_figure):
|
|||||||
assert mm.config == default_config
|
assert mm.config == default_config
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_change_motors(bec_figure):
|
def test_motor_map_change_motors(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
|
|
||||||
assert mm.motor_x == "samx"
|
assert mm.motor_x == "samx"
|
||||||
@ -32,7 +35,8 @@ def test_motor_map_change_motors(bec_figure):
|
|||||||
assert mm.config.signals.y == SignalData(name="samz", entry="samz", limits=[-8, 8])
|
assert mm.config.signals.y == SignalData(name="samz", entry="samz", limits=[-8, 8])
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_get_limits(bec_figure):
|
def test_motor_map_get_limits(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
expected_limits = {"samx": [-10, 10], "samy": [-5, 5]}
|
expected_limits = {"samx": [-10, 10], "samy": [-5, 5]}
|
||||||
|
|
||||||
@ -41,7 +45,8 @@ def test_motor_map_get_limits(bec_figure):
|
|||||||
assert actual_limit == expected_limit
|
assert actual_limit == expected_limit
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_get_init_position(bec_figure):
|
def test_motor_map_get_init_position(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
mm.set_precision(2)
|
mm.set_precision(2)
|
||||||
|
|
||||||
@ -57,7 +62,8 @@ def test_motor_map_get_init_position(bec_figure):
|
|||||||
assert actual_position == expected_position
|
assert actual_position == expected_position
|
||||||
|
|
||||||
|
|
||||||
def test_motor_movement_updates_position_and_database(bec_figure):
|
def test_motor_movement_updates_position_and_database(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
motor_map_dev = mm.client.device_manager.devices
|
motor_map_dev = mm.client.device_manager.devices
|
||||||
|
|
||||||
@ -85,7 +91,8 @@ def test_motor_movement_updates_position_and_database(bec_figure):
|
|||||||
assert mm.database_buffer["y"] == init_positions["samy"]
|
assert mm.database_buffer["y"] == init_positions["samy"]
|
||||||
|
|
||||||
|
|
||||||
def test_scatter_plot_rendering(bec_figure):
|
def test_scatter_plot_rendering(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
motor_map_dev = mm.client.device_manager.devices
|
motor_map_dev = mm.client.device_manager.devices
|
||||||
|
|
||||||
@ -115,7 +122,8 @@ def test_scatter_plot_rendering(bec_figure):
|
|||||||
), "Scatter plot Y data should retain last known position"
|
), "Scatter plot Y data should retain last known position"
|
||||||
|
|
||||||
|
|
||||||
def test_plot_visualization_consistency(bec_figure):
|
def test_plot_visualization_consistency(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
mm.change_motors("samx", "samy")
|
mm.change_motors("samx", "samy")
|
||||||
# Simulate updating the plot with new data
|
# Simulate updating the plot with new data
|
||||||
@ -133,7 +141,8 @@ def test_plot_visualization_consistency(bec_figure):
|
|||||||
), "Plot not updated correctly with new data"
|
), "Plot not updated correctly with new data"
|
||||||
|
|
||||||
|
|
||||||
def test_change_background_value(bec_figure, qtbot):
|
def test_change_background_value(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
|
|
||||||
assert mm.config.background_value == 25
|
assert mm.config.background_value == 25
|
||||||
@ -146,7 +155,8 @@ def test_change_background_value(bec_figure, qtbot):
|
|||||||
assert np.all(mm.plot_components["limit_map"].image == 50.0)
|
assert np.all(mm.plot_components["limit_map"].image == 50.0)
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_init_from_config(bec_figure):
|
def test_motor_map_init_from_config(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
config = {
|
config = {
|
||||||
"widget_class": "BECMotorMap",
|
"widget_class": "BECMotorMap",
|
||||||
"gui_id": "mm_id",
|
"gui_id": "mm_id",
|
||||||
@ -200,7 +210,8 @@ def test_motor_map_init_from_config(bec_figure):
|
|||||||
assert mm._config_dict == config
|
assert mm._config_dict == config
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_set_scatter_size(bec_figure, qtbot):
|
def test_motor_map_set_scatter_size(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
|
|
||||||
assert mm.config.scatter_size == 5
|
assert mm.config.scatter_size == 5
|
||||||
@ -213,7 +224,8 @@ def test_motor_map_set_scatter_size(bec_figure, qtbot):
|
|||||||
assert mm.plot_components["scatter"].opts["size"] == 10
|
assert mm.plot_components["scatter"].opts["size"] == 10
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_change_precision(bec_figure):
|
def test_motor_map_change_precision(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
|
|
||||||
assert mm.config.precision == 2
|
assert mm.config.precision == 2
|
||||||
@ -221,7 +233,8 @@ def test_motor_map_change_precision(bec_figure):
|
|||||||
assert mm.config.precision == 10
|
assert mm.config.precision == 10
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_set_color(bec_figure, qtbot):
|
def test_motor_map_set_color(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
|
|
||||||
assert mm.config.color == (255, 255, 255, 255)
|
assert mm.config.color == (255, 255, 255, 255)
|
||||||
@ -231,7 +244,8 @@ def test_motor_map_set_color(bec_figure, qtbot):
|
|||||||
assert mm.config.color == (0, 0, 0, 255)
|
assert mm.config.color == (0, 0, 0, 255)
|
||||||
|
|
||||||
|
|
||||||
def test_motor_map_get_data_max_points(bec_figure, qtbot):
|
def test_motor_map_get_data_max_points(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
mm = bec_figure.motor_map("samx", "samy")
|
mm = bec_figure.motor_map("samx", "samy")
|
||||||
motor_map_dev = mm.client.device_manager.devices
|
motor_map_dev = mm.client.device_manager.devices
|
||||||
|
|
||||||
|
@ -4,18 +4,22 @@ from unittest import mock
|
|||||||
import pytest
|
import pytest
|
||||||
from qtpy.QtGui import QFontInfo
|
from qtpy.QtGui import QFontInfo
|
||||||
|
|
||||||
|
from bec_widgets.widgets.figure import BECFigure
|
||||||
|
|
||||||
from .client_mocks import mocked_client
|
from .client_mocks import mocked_client
|
||||||
from .test_bec_figure import bec_figure
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
def test_init_plot_base(bec_figure):
|
def test_init_plot_base(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
||||||
assert plot_base is not None
|
assert plot_base is not None
|
||||||
assert plot_base.config.widget_class == "BECPlotBase"
|
assert plot_base.config.widget_class == "BECPlotBase"
|
||||||
assert plot_base.config.gui_id == "test_plot"
|
assert plot_base.config.gui_id == "test_plot"
|
||||||
|
|
||||||
|
|
||||||
def test_plot_base_axes_by_separate_methods(bec_figure):
|
def test_plot_base_axes_by_separate_methods(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
||||||
|
|
||||||
plot_base.set_title("Test Title")
|
plot_base.set_title("Test Title")
|
||||||
@ -65,7 +69,8 @@ def test_plot_base_axes_by_separate_methods(bec_figure):
|
|||||||
assert mock_set_title.call_args == call
|
assert mock_set_title.call_args == call
|
||||||
|
|
||||||
|
|
||||||
def test_plot_base_axes_added_by_kwargs(bec_figure):
|
def test_plot_base_axes_added_by_kwargs(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
||||||
|
|
||||||
plot_base.set(
|
plot_base.set(
|
||||||
|
@ -4,13 +4,15 @@ from unittest import mock
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from bec_widgets.widgets.figure import BECFigure
|
||||||
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import CurveConfig, Signal, SignalData
|
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import CurveConfig, Signal, SignalData
|
||||||
|
|
||||||
from .client_mocks import mocked_client
|
from .client_mocks import mocked_client
|
||||||
from .test_bec_figure import bec_figure
|
from .conftest import create_widget
|
||||||
|
|
||||||
|
|
||||||
def test_adding_curve_to_waveform(bec_figure):
|
def test_adding_curve_to_waveform(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
# adding curve which is in bec - only names
|
# adding curve which is in bec - only names
|
||||||
@ -38,7 +40,8 @@ def test_adding_curve_to_waveform(bec_figure):
|
|||||||
assert c3.config.label == "non_existent_device-non_existent_device"
|
assert c3.config.label == "non_existent_device-non_existent_device"
|
||||||
|
|
||||||
|
|
||||||
def test_adding_curve_with_same_id(bec_figure):
|
def test_adding_curve_with_same_id(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
||||||
|
|
||||||
@ -47,7 +50,8 @@ def test_adding_curve_with_same_id(bec_figure):
|
|||||||
assert "Curve with ID 'test_curve' already exists." in str(excinfo.value)
|
assert "Curve with ID 'test_curve' already exists." in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_create_waveform1D_by_config(bec_figure):
|
def test_create_waveform1D_by_config(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1_config_input = {
|
w1_config_input = {
|
||||||
"widget_class": "BECWaveform",
|
"widget_class": "BECWaveform",
|
||||||
"gui_id": "widget_1",
|
"gui_id": "widget_1",
|
||||||
@ -132,7 +136,8 @@ def test_create_waveform1D_by_config(bec_figure):
|
|||||||
assert w1.config.axis.title == "Widget 1"
|
assert w1.config.axis.title == "Widget 1"
|
||||||
|
|
||||||
|
|
||||||
def test_change_gui_id(bec_figure):
|
def test_change_gui_id(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
w1.change_gui_id("new_id")
|
w1.change_gui_id("new_id")
|
||||||
@ -141,7 +146,8 @@ def test_change_gui_id(bec_figure):
|
|||||||
assert c1.config.parent_id == "new_id"
|
assert c1.config.parent_id == "new_id"
|
||||||
|
|
||||||
|
|
||||||
def test_getting_curve(bec_figure):
|
def test_getting_curve(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
||||||
c1_expected_config = CurveConfig(
|
c1_expected_config = CurveConfig(
|
||||||
@ -173,7 +179,8 @@ def test_getting_curve(bec_figure):
|
|||||||
assert c1.get_config() == c1_expected_config.model_dump()
|
assert c1.get_config() == c1_expected_config.model_dump()
|
||||||
|
|
||||||
|
|
||||||
def test_getting_curve_errors(bec_figure):
|
def test_getting_curve_errors(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
|
||||||
|
|
||||||
@ -190,7 +197,8 @@ def test_getting_curve_errors(bec_figure):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_add_curve(bec_figure):
|
def test_add_curve(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -201,7 +209,8 @@ def test_add_curve(bec_figure):
|
|||||||
assert c1.config.source == "scan_segment"
|
assert c1.config.source == "scan_segment"
|
||||||
|
|
||||||
|
|
||||||
def test_change_legend_font_size(bec_figure):
|
def test_change_legend_font_size(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
plot = bec_figure.plot()
|
plot = bec_figure.plot()
|
||||||
|
|
||||||
w1 = plot.add_curve_bec(x_name="samx", y_name="bpm4i")
|
w1 = plot.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -213,7 +222,8 @@ def test_change_legend_font_size(bec_figure):
|
|||||||
assert mock_set_scale.call_args == mock.call(2)
|
assert mock_set_scale.call_args == mock.call(2)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_curve(bec_figure):
|
def test_remove_curve(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -231,7 +241,8 @@ def test_remove_curve(bec_figure):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_change_curve_appearance_methods(bec_figure, qtbot):
|
def test_change_curve_appearance_methods(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -260,7 +271,8 @@ def test_change_curve_appearance_methods(bec_figure, qtbot):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_change_curve_appearance_args(bec_figure):
|
def test_change_curve_appearance_args(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -290,7 +302,8 @@ def test_change_curve_appearance_args(bec_figure):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_set_custom_curve_data(bec_figure, qtbot):
|
def test_set_custom_curve_data(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_custom(
|
c1 = w1.add_curve_custom(
|
||||||
@ -326,7 +339,8 @@ def test_set_custom_curve_data(bec_figure, qtbot):
|
|||||||
assert np.array_equal(y_new, [7, 8, 9])
|
assert np.array_equal(y_new, [7, 8, 9])
|
||||||
|
|
||||||
|
|
||||||
def test_custom_data_2D_array(bec_figure, qtbot):
|
def test_custom_data_2D_array(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
|
|
||||||
data = np.random.rand(10, 2)
|
data = np.random.rand(10, 2)
|
||||||
|
|
||||||
@ -338,7 +352,8 @@ def test_custom_data_2D_array(bec_figure, qtbot):
|
|||||||
assert np.array_equal(y, data[:, 1])
|
assert np.array_equal(y, data[:, 1])
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_data(bec_figure):
|
def test_get_all_data(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_custom(
|
c1 = w1.add_curve_custom(
|
||||||
@ -373,7 +388,8 @@ def test_get_all_data(bec_figure):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_curve_add_by_config(bec_figure):
|
def test_curve_add_by_config(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1_config_input = {
|
c1_config_input = {
|
||||||
@ -413,7 +429,8 @@ def test_curve_add_by_config(bec_figure):
|
|||||||
assert c1.get_config(False) == CurveConfig(**c1_config_input)
|
assert c1.get_config(False) == CurveConfig(**c1_config_input)
|
||||||
|
|
||||||
|
|
||||||
def test_scan_update(bec_figure, qtbot):
|
def test_scan_update(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
|
||||||
@ -447,7 +464,8 @@ def test_scan_update(bec_figure, qtbot):
|
|||||||
assert c1.get_data() == ([10], [5])
|
assert c1.get_data() == ([10], [5])
|
||||||
|
|
||||||
|
|
||||||
def test_scan_history_with_val_access(bec_figure, qtbot):
|
def test_scan_history_with_val_access(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
w1.plot(x_name="samx", y_name="bpm4i")
|
w1.plot(x_name="samx", y_name="bpm4i")
|
||||||
@ -472,7 +490,8 @@ def test_scan_history_with_val_access(bec_figure, qtbot):
|
|||||||
assert np.array_equal(y_data, [4, 5, 6])
|
assert np.array_equal(y_data, [4, 5, 6])
|
||||||
|
|
||||||
|
|
||||||
def test_scatter_2d_update(bec_figure, qtbot):
|
def test_scatter_2d_update(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
c1 = w1.add_curve_bec(x_name="samx", y_name="samx", z_name="bpm4i")
|
c1 = w1.add_curve_bec(x_name="samx", y_name="samx", z_name="bpm4i")
|
||||||
@ -512,7 +531,8 @@ def test_scatter_2d_update(bec_figure, qtbot):
|
|||||||
assert colors == expected_z_colors
|
assert colors == expected_z_colors
|
||||||
|
|
||||||
|
|
||||||
def test_waveform_single_arg_inputs(bec_figure, qtbot):
|
def test_waveform_single_arg_inputs(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
|
|
||||||
w1.plot("bpm4i")
|
w1.plot("bpm4i")
|
||||||
@ -544,7 +564,8 @@ def test_waveform_single_arg_inputs(bec_figure, qtbot):
|
|||||||
assert np.array_equal(w1._curves_data["custom"]["np_ndarray 2D"].get_data(), data_array_2D.T)
|
assert np.array_equal(w1._curves_data["custom"]["np_ndarray 2D"].get_data(), data_array_2D.T)
|
||||||
|
|
||||||
|
|
||||||
def test_waveform_set_x_sync(bec_figure, qtbot):
|
def test_waveform_set_x_sync(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot()
|
w1 = bec_figure.plot()
|
||||||
custom_label = "custom_label"
|
custom_label = "custom_label"
|
||||||
w1.plot("bpm4i")
|
w1.plot("bpm4i")
|
||||||
@ -601,7 +622,8 @@ def test_waveform_set_x_sync(bec_figure, qtbot):
|
|||||||
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [timestamp]"
|
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [timestamp]"
|
||||||
|
|
||||||
|
|
||||||
def test_waveform_async_data_update(bec_figure, qtbot):
|
def test_waveform_async_data_update(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot("async_device")
|
w1 = bec_figure.plot("async_device")
|
||||||
custom_label = "custom_label"
|
custom_label = "custom_label"
|
||||||
w1.set_x_label(custom_label)
|
w1.set_x_label(custom_label)
|
||||||
@ -647,7 +669,8 @@ def test_waveform_async_data_update(bec_figure, qtbot):
|
|||||||
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]"
|
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]"
|
||||||
|
|
||||||
|
|
||||||
def test_waveform_set_x_async(bec_figure, qtbot):
|
def test_waveform_set_x_async(qtbot, mocked_client):
|
||||||
|
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
||||||
w1 = bec_figure.plot("async_device")
|
w1 = bec_figure.plot("async_device")
|
||||||
custom_label = "custom_label"
|
custom_label = "custom_label"
|
||||||
w1.set_x_label(custom_label)
|
w1.set_x_label(custom_label)
|
||||||
|
Reference in New Issue
Block a user