mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(image): image can be fully reconstructed from config
This commit is contained in:
@ -38,9 +38,9 @@ def test_bec_figure_add_remove_plot(bec_figure):
|
||||
initial_count = len(bec_figure._widgets)
|
||||
|
||||
# Adding 3 widgets - 2 WaveformBase and 1 PlotBase
|
||||
w0 = bec_figure.add_plot()
|
||||
w1 = bec_figure.add_plot()
|
||||
w2 = bec_figure.add_widget(widget_type="PlotBase")
|
||||
w0 = bec_figure.plot(new=True)
|
||||
w1 = bec_figure.plot(new=True)
|
||||
w2 = bec_figure.add_widget(widget_type="BECPlotBase")
|
||||
|
||||
# Check if the widgets were added
|
||||
assert len(bec_figure._widgets) == initial_count + 3
|
||||
@ -75,7 +75,7 @@ def test_add_different_types_of_widgets(bec_figure):
|
||||
|
||||
|
||||
def test_access_widgets_access_errors(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=0)
|
||||
|
||||
# access widget by non-existent coordinates
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@ -97,18 +97,18 @@ def test_access_widgets_access_errors(bec_figure):
|
||||
|
||||
|
||||
def test_add_plot_to_occupied_position(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=0)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=0, new=True)
|
||||
assert "Position at row 0 and column 0 is already occupied." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_remove_plots(bec_figure):
|
||||
w1 = bec_figure.add_plot(row=0, col=0)
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
w3 = bec_figure.add_plot(row=1, col=0)
|
||||
w4 = bec_figure.add_plot(row=1, col=1)
|
||||
w1 = bec_figure.plot(row=0, col=0)
|
||||
w2 = bec_figure.plot(row=0, col=1)
|
||||
w3 = bec_figure.plot(row=1, col=0)
|
||||
w4 = bec_figure.plot(row=1, col=1)
|
||||
|
||||
assert bec_figure[0, 0] == w1
|
||||
assert bec_figure[0, 1] == w2
|
||||
@ -135,10 +135,10 @@ def test_remove_plots(bec_figure):
|
||||
|
||||
|
||||
def test_remove_plots_by_coordinates_ints(bec_figure):
|
||||
w1 = bec_figure.add_plot(row=0, col=0)
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
w1 = bec_figure.plot(row=0, col=0)
|
||||
w2 = bec_figure.plot(row=0, col=1)
|
||||
|
||||
bec_figure.remove(0, 0)
|
||||
bec_figure.remove(row=0, col=0)
|
||||
assert w1.gui_id not in bec_figure._widgets
|
||||
assert w2.gui_id in bec_figure._widgets
|
||||
assert bec_figure[0, 0] == w2
|
||||
@ -146,8 +146,8 @@ def test_remove_plots_by_coordinates_ints(bec_figure):
|
||||
|
||||
|
||||
def test_remove_plots_by_coordinates_tuple(bec_figure):
|
||||
w1 = bec_figure.add_plot(row=0, col=0)
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
w1 = bec_figure.plot(row=0, col=0)
|
||||
w2 = bec_figure.plot(row=0, col=1)
|
||||
|
||||
bec_figure.remove(coordinates=(0, 0))
|
||||
assert w1.gui_id not in bec_figure._widgets
|
||||
@ -157,7 +157,7 @@ def test_remove_plots_by_coordinates_tuple(bec_figure):
|
||||
|
||||
|
||||
def test_remove_plot_by_id_error(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot()
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
bec_figure.remove(widget_id="non_existent_widget")
|
||||
@ -165,7 +165,7 @@ def test_remove_plot_by_id_error(bec_figure):
|
||||
|
||||
|
||||
def test_remove_plot_by_coordinates_error(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=0)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
bec_figure.remove(0, 1)
|
||||
@ -173,7 +173,7 @@ def test_remove_plot_by_coordinates_error(bec_figure):
|
||||
|
||||
|
||||
def test_remove_plot_by_providing_nothing(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=0)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
bec_figure.remove()
|
||||
@ -193,10 +193,10 @@ def test_remove_plot_by_providing_nothing(bec_figure):
|
||||
|
||||
|
||||
def test_change_layout(bec_figure):
|
||||
w1 = bec_figure.add_plot(row=0, col=0)
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
w3 = bec_figure.add_plot(row=1, col=0)
|
||||
w4 = bec_figure.add_plot(row=1, col=1)
|
||||
w1 = bec_figure.plot(row=0, col=0)
|
||||
w2 = bec_figure.plot(row=0, col=1)
|
||||
w3 = bec_figure.plot(row=1, col=0)
|
||||
w4 = bec_figure.plot(row=1, col=1)
|
||||
|
||||
bec_figure.change_layout(max_columns=1)
|
||||
|
||||
@ -216,10 +216,10 @@ def test_change_layout(bec_figure):
|
||||
|
||||
|
||||
def test_clear_all(bec_figure):
|
||||
bec_figure.add_plot(row=0, col=0)
|
||||
bec_figure.add_plot(row=0, col=1)
|
||||
bec_figure.add_plot(row=1, col=0)
|
||||
bec_figure.add_plot(row=1, col=1)
|
||||
bec_figure.plot(row=0, col=0)
|
||||
bec_figure.plot(row=0, col=1)
|
||||
bec_figure.plot(row=1, col=0)
|
||||
bec_figure.plot(row=1, col=1)
|
||||
|
||||
bec_figure.clear_all()
|
||||
|
||||
@ -238,3 +238,26 @@ def test_shortcuts(bec_figure):
|
||||
assert im.__class__ == BECImageShow
|
||||
assert motor_map.config.widget_class == "BECMotorMap"
|
||||
assert motor_map.__class__ == BECMotorMap
|
||||
|
||||
|
||||
def test_plot_access_factory(bec_figure):
|
||||
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_10 = bec_figure.plot(new=True)
|
||||
|
||||
assert bec_figure.widget_list[0] == plt_00
|
||||
assert bec_figure.widget_list[1] == plt_01
|
||||
assert bec_figure.widget_list[2] == plt_10
|
||||
assert bec_figure.axes(row=0, col=0) == plt_00
|
||||
assert bec_figure.axes(row=0, col=1) == plt_01
|
||||
assert bec_figure.axes(row=1, col=0) == plt_10
|
||||
|
||||
assert len(plt_00.curves) == 1
|
||||
assert len(plt_01.curves) == 1
|
||||
assert len(plt_10.curves) == 0
|
||||
|
||||
# update plt_00
|
||||
bec_figure.plot(x_name="samx", y_name="bpm3a")
|
||||
bec_figure.plot(x=[1, 2, 3], y=[1, 2, 3], row=0, col=0)
|
||||
|
||||
assert len(plt_00.curves) == 3
|
||||
|
@ -9,14 +9,14 @@ from .test_bec_figure import bec_figure
|
||||
|
||||
|
||||
def test_init_plot_base(bec_figure):
|
||||
plot_base = bec_figure.add_widget(widget_type="PlotBase", 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.config.widget_class == "BECPlotBase"
|
||||
assert plot_base.config.gui_id == "test_plot"
|
||||
|
||||
|
||||
def test_plot_base_axes_by_separate_methods(bec_figure):
|
||||
plot_base = bec_figure.add_widget(widget_type="PlotBase", 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_x_label("Test x Label")
|
||||
@ -66,7 +66,7 @@ def test_plot_base_axes_by_separate_methods(bec_figure):
|
||||
|
||||
|
||||
def test_plot_base_axes_added_by_kwargs(bec_figure):
|
||||
plot_base = bec_figure.add_widget(widget_type="PlotBase", widget_id="test_plot")
|
||||
plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
|
||||
|
||||
plot_base.set(
|
||||
title="Test Title",
|
||||
|
Reference in New Issue
Block a user