bec-widgets 0.93.2__py3-none-any.whl → 0.93.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. CHANGELOG.md +32 -34
  2. PKG-INFO +1 -1
  3. bec_widgets/cli/client.py +9 -16
  4. bec_widgets/qt_utils/settings_dialog.py +11 -0
  5. bec_widgets/widgets/color_button/color_button.py +7 -0
  6. bec_widgets/widgets/dock/dock.py +4 -1
  7. bec_widgets/widgets/dock/dock_area.py +19 -5
  8. bec_widgets/widgets/figure/figure.py +21 -16
  9. bec_widgets/widgets/figure/plots/image/image.py +14 -0
  10. bec_widgets/widgets/figure/plots/plot_base.py +8 -0
  11. bec_widgets/widgets/image/image_widget.py +2 -0
  12. bec_widgets/widgets/motor_map/motor_map_dialog/motor_map_settings.py +9 -0
  13. bec_widgets/widgets/{device_box/device_box.py → positioner_box/positioner_box.py} +88 -11
  14. bec_widgets/widgets/positioner_box/positioner_box.pyproject +1 -0
  15. bec_widgets/widgets/{device_box/device_box.ui → positioner_box/positioner_box.ui} +20 -3
  16. bec_widgets/widgets/{device_box/device_box_plugin.py → positioner_box/positioner_box_plugin.py} +9 -14
  17. bec_widgets/widgets/{device_box/register_device_box.py → positioner_box/register_positioner_box.py} +2 -2
  18. bec_widgets/widgets/website/website.py +6 -0
  19. {bec_widgets-0.93.2.dist-info → bec_widgets-0.93.4.dist-info}/METADATA +1 -1
  20. {bec_widgets-0.93.2.dist-info → bec_widgets-0.93.4.dist-info}/RECORD +50 -50
  21. pyproject.toml +1 -1
  22. tests/end-2-end/test_scan_control_e2e.py +0 -1
  23. tests/unit_tests/conftest.py +33 -2
  24. tests/unit_tests/test_bec_dock.py +6 -5
  25. tests/unit_tests/test_bec_figure.py +31 -24
  26. tests/unit_tests/test_bec_image.py +7 -3
  27. tests/unit_tests/test_bec_image_widget.py +0 -1
  28. tests/unit_tests/test_bec_motor_map.py +28 -14
  29. tests/unit_tests/test_bec_queue.py +0 -1
  30. tests/unit_tests/test_bec_status_box.py +0 -1
  31. tests/unit_tests/test_color_map_selector.py +0 -1
  32. tests/unit_tests/test_device_input_base.py +0 -1
  33. tests/unit_tests/test_device_input_widgets.py +0 -6
  34. tests/unit_tests/test_motor_map_widget.py +0 -2
  35. tests/unit_tests/test_plot_base.py +9 -4
  36. tests/unit_tests/test_positioner_box.py +104 -0
  37. tests/unit_tests/test_ring_progress_bar.py +0 -1
  38. tests/unit_tests/test_scan_control.py +0 -1
  39. tests/unit_tests/test_setting_dialog.py +1 -2
  40. tests/unit_tests/test_stop_button.py +0 -1
  41. tests/unit_tests/test_text_box_widget.py +0 -1
  42. tests/unit_tests/test_toggle.py +0 -1
  43. tests/unit_tests/test_vscode_widget.py +2 -2
  44. tests/unit_tests/test_waveform1d.py +46 -23
  45. tests/unit_tests/test_waveform_widget.py +0 -1
  46. tests/unit_tests/test_website_widget.py +0 -2
  47. bec_widgets/widgets/device_box/device_box.pyproject +0 -1
  48. tests/unit_tests/test_device_box.py +0 -98
  49. /bec_widgets/widgets/{device_box → positioner_box}/__init__.py +0 -0
  50. {bec_widgets-0.93.2.dist-info → bec_widgets-0.93.4.dist-info}/WHEEL +0 -0
  51. {bec_widgets-0.93.2.dist-info → bec_widgets-0.93.4.dist-info}/entry_points.txt +0 -0
  52. {bec_widgets-0.93.2.dist-info → bec_widgets-0.93.4.dist-info}/licenses/LICENSE +0 -0
@@ -2,14 +2,16 @@ import numpy as np
2
2
  import pytest
3
3
  from bec_lib.messages import DeviceMessage
4
4
 
5
+ from bec_widgets.widgets.figure import BECFigure
5
6
  from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap, MotorMapConfig
6
7
  from bec_widgets.widgets.figure.plots.waveform.waveform_curve import SignalData
7
8
 
8
9
  from .client_mocks import mocked_client
9
- from .test_bec_figure import bec_figure
10
+ from .conftest import create_widget
10
11
 
11
12
 
12
- def test_motor_map_init(bec_figure):
13
+ def test_motor_map_init(qtbot, mocked_client):
14
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
13
15
  default_config = MotorMapConfig(widget_class="BECMotorMap")
14
16
 
15
17
  mm = bec_figure.motor_map(config=default_config.model_dump())
@@ -18,7 +20,8 @@ def test_motor_map_init(bec_figure):
18
20
  assert mm.config == default_config
19
21
 
20
22
 
21
- def test_motor_map_change_motors(bec_figure):
23
+ def test_motor_map_change_motors(qtbot, mocked_client):
24
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
22
25
  mm = bec_figure.motor_map("samx", "samy")
23
26
 
24
27
  assert mm.motor_x == "samx"
@@ -32,7 +35,8 @@ def test_motor_map_change_motors(bec_figure):
32
35
  assert mm.config.signals.y == SignalData(name="samz", entry="samz", limits=[-8, 8])
33
36
 
34
37
 
35
- def test_motor_map_get_limits(bec_figure):
38
+ def test_motor_map_get_limits(qtbot, mocked_client):
39
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
36
40
  mm = bec_figure.motor_map("samx", "samy")
37
41
  expected_limits = {"samx": [-10, 10], "samy": [-5, 5]}
38
42
 
@@ -41,7 +45,8 @@ def test_motor_map_get_limits(bec_figure):
41
45
  assert actual_limit == expected_limit
42
46
 
43
47
 
44
- def test_motor_map_get_init_position(bec_figure):
48
+ def test_motor_map_get_init_position(qtbot, mocked_client):
49
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
45
50
  mm = bec_figure.motor_map("samx", "samy")
46
51
  mm.set_precision(2)
47
52
 
@@ -57,7 +62,8 @@ def test_motor_map_get_init_position(bec_figure):
57
62
  assert actual_position == expected_position
58
63
 
59
64
 
60
- def test_motor_movement_updates_position_and_database(bec_figure):
65
+ def test_motor_movement_updates_position_and_database(qtbot, mocked_client):
66
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
61
67
  mm = bec_figure.motor_map("samx", "samy")
62
68
  motor_map_dev = mm.client.device_manager.devices
63
69
 
@@ -85,7 +91,8 @@ def test_motor_movement_updates_position_and_database(bec_figure):
85
91
  assert mm.database_buffer["y"] == init_positions["samy"]
86
92
 
87
93
 
88
- def test_scatter_plot_rendering(bec_figure):
94
+ def test_scatter_plot_rendering(qtbot, mocked_client):
95
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
89
96
  mm = bec_figure.motor_map("samx", "samy")
90
97
  motor_map_dev = mm.client.device_manager.devices
91
98
 
@@ -115,7 +122,8 @@ def test_scatter_plot_rendering(bec_figure):
115
122
  ), "Scatter plot Y data should retain last known position"
116
123
 
117
124
 
118
- def test_plot_visualization_consistency(bec_figure):
125
+ def test_plot_visualization_consistency(qtbot, mocked_client):
126
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
119
127
  mm = bec_figure.motor_map("samx", "samy")
120
128
  mm.change_motors("samx", "samy")
121
129
  # Simulate updating the plot with new data
@@ -133,7 +141,8 @@ def test_plot_visualization_consistency(bec_figure):
133
141
  ), "Plot not updated correctly with new data"
134
142
 
135
143
 
136
- def test_change_background_value(bec_figure, qtbot):
144
+ def test_change_background_value(qtbot, mocked_client):
145
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
137
146
  mm = bec_figure.motor_map("samx", "samy")
138
147
 
139
148
  assert mm.config.background_value == 25
@@ -146,7 +155,8 @@ def test_change_background_value(bec_figure, qtbot):
146
155
  assert np.all(mm.plot_components["limit_map"].image == 50.0)
147
156
 
148
157
 
149
- def test_motor_map_init_from_config(bec_figure):
158
+ def test_motor_map_init_from_config(qtbot, mocked_client):
159
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
150
160
  config = {
151
161
  "widget_class": "BECMotorMap",
152
162
  "gui_id": "mm_id",
@@ -200,7 +210,8 @@ def test_motor_map_init_from_config(bec_figure):
200
210
  assert mm._config_dict == config
201
211
 
202
212
 
203
- def test_motor_map_set_scatter_size(bec_figure, qtbot):
213
+ def test_motor_map_set_scatter_size(qtbot, mocked_client):
214
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
204
215
  mm = bec_figure.motor_map("samx", "samy")
205
216
 
206
217
  assert mm.config.scatter_size == 5
@@ -213,7 +224,8 @@ def test_motor_map_set_scatter_size(bec_figure, qtbot):
213
224
  assert mm.plot_components["scatter"].opts["size"] == 10
214
225
 
215
226
 
216
- def test_motor_map_change_precision(bec_figure):
227
+ def test_motor_map_change_precision(qtbot, mocked_client):
228
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
217
229
  mm = bec_figure.motor_map("samx", "samy")
218
230
 
219
231
  assert mm.config.precision == 2
@@ -221,7 +233,8 @@ def test_motor_map_change_precision(bec_figure):
221
233
  assert mm.config.precision == 10
222
234
 
223
235
 
224
- def test_motor_map_set_color(bec_figure, qtbot):
236
+ def test_motor_map_set_color(qtbot, mocked_client):
237
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
225
238
  mm = bec_figure.motor_map("samx", "samy")
226
239
 
227
240
  assert mm.config.color == (255, 255, 255, 255)
@@ -231,7 +244,8 @@ def test_motor_map_set_color(bec_figure, qtbot):
231
244
  assert mm.config.color == (0, 0, 0, 255)
232
245
 
233
246
 
234
- def test_motor_map_get_data_max_points(bec_figure, qtbot):
247
+ def test_motor_map_get_data_max_points(qtbot, mocked_client):
248
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
235
249
  mm = bec_figure.motor_map("samx", "samy")
236
250
  motor_map_dev = mm.client.device_manager.devices
237
251
 
@@ -93,7 +93,6 @@ def bec_queue(qtbot, mocked_client):
93
93
  qtbot.addWidget(widget)
94
94
  qtbot.waitExposed(widget)
95
95
  yield widget
96
- widget.close()
97
96
 
98
97
 
99
98
  def test_bec_queue(bec_queue, bec_queue_msg_full):
@@ -20,7 +20,6 @@ def status_box(qtbot, mocked_client, service_status_fixture):
20
20
  qtbot.addWidget(widget)
21
21
  qtbot.waitExposed(widget)
22
22
  yield widget
23
- widget.close()
24
23
 
25
24
 
26
25
  def test_update_top_item(status_box):
@@ -10,7 +10,6 @@ def color_map_selector(qtbot):
10
10
  qtbot.addWidget(widget)
11
11
  qtbot.waitExposed(widget)
12
12
  yield widget
13
- widget.close()
14
13
 
15
14
 
16
15
  def test_color_map_selector_init(color_map_selector):
@@ -19,7 +19,6 @@ def device_input_base(qtbot, mocked_client):
19
19
  qtbot.addWidget(widget)
20
20
  qtbot.waitExposed(widget)
21
21
  yield widget
22
- widget.close()
23
22
 
24
23
 
25
24
  def test_device_input_base_init(device_input_base):
@@ -12,7 +12,6 @@ def device_input_combobox(qtbot, mocked_client):
12
12
  qtbot.addWidget(widget)
13
13
  qtbot.waitExposed(widget)
14
14
  yield widget
15
- widget.close()
16
15
 
17
16
 
18
17
  @pytest.fixture
@@ -28,7 +27,6 @@ def device_input_combobox_with_config(qtbot, mocked_client):
28
27
  qtbot.addWidget(widget)
29
28
  qtbot.waitExposed(widget)
30
29
  yield widget
31
- widget.close()
32
30
 
33
31
 
34
32
  @pytest.fixture
@@ -43,7 +41,6 @@ def device_input_combobox_with_kwargs(qtbot, mocked_client):
43
41
  qtbot.addWidget(widget)
44
42
  qtbot.waitExposed(widget)
45
43
  yield widget
46
- widget.close()
47
44
 
48
45
 
49
46
  def test_device_input_combobox_init(device_input_combobox):
@@ -101,7 +98,6 @@ def device_input_line_edit(qtbot, mocked_client):
101
98
  qtbot.addWidget(widget)
102
99
  qtbot.waitExposed(widget)
103
100
  yield widget
104
- widget.close()
105
101
 
106
102
 
107
103
  @pytest.fixture
@@ -117,7 +113,6 @@ def device_input_line_edit_with_config(qtbot, mocked_client):
117
113
  qtbot.addWidget(widget)
118
114
  qtbot.waitExposed(widget)
119
115
  yield widget
120
- widget.close()
121
116
 
122
117
 
123
118
  @pytest.fixture
@@ -132,7 +127,6 @@ def device_input_line_edit_with_kwargs(qtbot, mocked_client):
132
127
  qtbot.addWidget(widget)
133
128
  qtbot.waitExposed(widget)
134
129
  yield widget
135
- widget.close()
136
130
 
137
131
 
138
132
  def test_device_input_line_edit_init(device_input_line_edit):
@@ -16,7 +16,6 @@ def motor_map_widget(qtbot, mocked_client):
16
16
  qtbot.addWidget(widget)
17
17
  qtbot.waitExposed(widget)
18
18
  yield widget
19
- widget.close()
20
19
 
21
20
 
22
21
  @pytest.fixture
@@ -139,7 +138,6 @@ def motor_map_settings(qtbot):
139
138
  qtbot.addWidget(widget)
140
139
  qtbot.waitExposed(widget)
141
140
  yield widget
142
- widget.close()
143
141
 
144
142
 
145
143
  def test_display_current_settings(motor_map_settings):
@@ -4,18 +4,22 @@ from unittest import mock
4
4
  import pytest
5
5
  from qtpy.QtGui import QFontInfo
6
6
 
7
+ from bec_widgets.widgets.figure import BECFigure
8
+
7
9
  from .client_mocks import mocked_client
8
- from .test_bec_figure import bec_figure
10
+ from .conftest import create_widget
9
11
 
10
12
 
11
- def test_init_plot_base(bec_figure):
13
+ def test_init_plot_base(qtbot, mocked_client):
14
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
12
15
  plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
13
16
  assert plot_base is not None
14
17
  assert plot_base.config.widget_class == "BECPlotBase"
15
18
  assert plot_base.config.gui_id == "test_plot"
16
19
 
17
20
 
18
- def test_plot_base_axes_by_separate_methods(bec_figure):
21
+ def test_plot_base_axes_by_separate_methods(qtbot, mocked_client):
22
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
19
23
  plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
20
24
 
21
25
  plot_base.set_title("Test Title")
@@ -65,7 +69,8 @@ def test_plot_base_axes_by_separate_methods(bec_figure):
65
69
  assert mock_set_title.call_args == call
66
70
 
67
71
 
68
- def test_plot_base_axes_added_by_kwargs(bec_figure):
72
+ def test_plot_base_axes_added_by_kwargs(qtbot, mocked_client):
73
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
69
74
  plot_base = bec_figure.add_widget(widget_type="BECPlotBase", widget_id="test_plot")
70
75
 
71
76
  plot_base.set(
@@ -0,0 +1,104 @@
1
+ from unittest import mock
2
+
3
+ import pytest
4
+ from bec_lib.device import Positioner
5
+ from bec_lib.endpoints import MessageEndpoints
6
+ from bec_lib.messages import ScanQueueMessage
7
+ from qtpy.QtGui import QValidator
8
+
9
+ from bec_widgets.widgets.positioner_box.positioner_box import PositionerBox
10
+
11
+ from .client_mocks import mocked_client
12
+
13
+
14
+ @pytest.fixture
15
+ def positioner_box(qtbot, mocked_client):
16
+ with mock.patch("bec_widgets.widgets.positioner_box.positioner_box.uuid.uuid4") as mock_uuid:
17
+ mock_uuid.return_value = "fake_uuid"
18
+ with mock.patch(
19
+ "bec_widgets.widgets.positioner_box.positioner_box.PositionerBox._check_device_is_valid",
20
+ return_value=True,
21
+ ):
22
+ db = PositionerBox(device="samx", client=mocked_client)
23
+ qtbot.addWidget(db)
24
+ yield db
25
+
26
+
27
+ def test_positioner_box(positioner_box):
28
+ assert positioner_box.device == "samx"
29
+ data = positioner_box.dev["samx"].read()
30
+ # Avoid check for Positioner class from BEC in _init_device
31
+
32
+ setpoint_text = positioner_box.ui.setpoint.text()
33
+ # check that the setpoint is taken correctly after init
34
+ assert float(setpoint_text) == data["samx_setpoint"]["value"]
35
+
36
+ # check that the precision is taken correctly after isnit
37
+ precision = positioner_box.dev["samx"].precision
38
+ assert setpoint_text == f"{data['samx_setpoint']['value']:.{precision}f}"
39
+
40
+ # check that the step size is set according to the device precision
41
+ assert positioner_box.ui.step_size.value() == 10**-precision * 10
42
+
43
+
44
+ def test_positioner_box_update_limits(positioner_box):
45
+ positioner_box._limits = None
46
+ positioner_box.update_limits([0, 10])
47
+ assert positioner_box._limits == [0, 10]
48
+ assert positioner_box.setpoint_validator.bottom() == 0
49
+ assert positioner_box.setpoint_validator.top() == 10
50
+ assert positioner_box.setpoint_validator.validate("100", 0) == (
51
+ QValidator.State.Intermediate,
52
+ "100",
53
+ 0,
54
+ )
55
+
56
+ positioner_box.update_limits(None)
57
+ assert positioner_box._limits is None
58
+ assert positioner_box.setpoint_validator.validate("100", 0) == (
59
+ QValidator.State.Acceptable,
60
+ "100",
61
+ 0,
62
+ )
63
+
64
+
65
+ def test_positioner_box_on_stop(positioner_box):
66
+ with mock.patch.object(positioner_box.client.connector, "send") as mock_send:
67
+ positioner_box.on_stop()
68
+ params = {"device": "samx", "rpc_id": "fake_uuid", "func": "stop", "args": [], "kwargs": {}}
69
+ msg = ScanQueueMessage(
70
+ scan_type="device_rpc",
71
+ parameter=params,
72
+ queue="emergency",
73
+ metadata={"RID": "fake_uuid", "response": False},
74
+ )
75
+ mock_send.assert_called_once_with(MessageEndpoints.scan_queue_request(), msg)
76
+
77
+
78
+ def test_positioner_box_setpoint_change(positioner_box):
79
+ with mock.patch.object(positioner_box.dev["samx"], "move") as mock_move:
80
+ positioner_box.ui.setpoint.setText("100")
81
+ positioner_box.on_setpoint_change()
82
+ mock_move.assert_called_once_with(100, relative=False)
83
+
84
+
85
+ def test_positioner_box_on_tweak_right(positioner_box):
86
+ with mock.patch.object(positioner_box.dev["samx"], "move") as mock_move:
87
+ positioner_box.ui.step_size.setValue(0.1)
88
+ positioner_box.on_tweak_right()
89
+ mock_move.assert_called_once_with(0.1, relative=True)
90
+
91
+
92
+ def test_positioner_box_on_tweak_left(positioner_box):
93
+ with mock.patch.object(positioner_box.dev["samx"], "move") as mock_move:
94
+ positioner_box.ui.step_size.setValue(0.1)
95
+ positioner_box.on_tweak_left()
96
+ mock_move.assert_called_once_with(-0.1, relative=True)
97
+
98
+
99
+ def test_positioner_box_setpoint_out_of_range(positioner_box):
100
+ positioner_box.update_limits([0, 10])
101
+ positioner_box.ui.setpoint.setText("100")
102
+ positioner_box.on_setpoint_change()
103
+ assert positioner_box.ui.setpoint.text() == "100"
104
+ assert positioner_box.ui.setpoint.hasAcceptableInput() == False
@@ -18,7 +18,6 @@ def ring_progress_bar(qtbot, mocked_client):
18
18
  qtbot.addWidget(widget)
19
19
  qtbot.waitExposed(widget)
20
20
  yield widget
21
- widget.close()
22
21
 
23
22
 
24
23
  def test_bar_init(ring_progress_bar):
@@ -220,7 +220,6 @@ def scan_control(qtbot, mocked_client): # , mock_dev):
220
220
  qtbot.addWidget(widget)
221
221
  qtbot.waitExposed(widget)
222
222
  yield widget
223
- widget.close()
224
223
 
225
224
 
226
225
  def test_populate_scans(scan_control, mocked_client):
@@ -16,7 +16,6 @@ def setting_widget(qtbot):
16
16
  qtbot.addWidget(widget)
17
17
  qtbot.waitExposed(widget)
18
18
  yield widget
19
- widget.close()
20
19
 
21
20
 
22
21
  def test_setting_widget_initialization(setting_widget):
@@ -61,8 +60,8 @@ def settings_dialog(qtbot, setting_widget):
61
60
  qtbot.addWidget(dialog)
62
61
  qtbot.waitExposed(dialog)
63
62
  yield dialog, parent_widget, setting_widget
64
- dialog.close()
65
63
  parent_widget.close()
64
+ parent_widget.deleteLater()
66
65
 
67
66
 
68
67
  def test_settings_dialog_initialization(settings_dialog):
@@ -13,7 +13,6 @@ def stop_button(qtbot, mocked_client):
13
13
  qtbot.addWidget(widget)
14
14
  qtbot.waitExposed(widget)
15
15
  yield widget
16
- widget.close()
17
16
 
18
17
 
19
18
  def test_stop_button(stop_button):
@@ -14,7 +14,6 @@ def text_box_widget(qtbot, mocked_client):
14
14
  qtbot.addWidget(widget)
15
15
  qtbot.waitExposed(widget)
16
16
  yield widget
17
- widget.close()
18
17
 
19
18
 
20
19
  def test_textbox_widget(text_box_widget):
@@ -10,7 +10,6 @@ def toggle(qtbot):
10
10
  qtbot.addWidget(widget)
11
11
  qtbot.waitExposed(widget)
12
12
  yield widget
13
- widget.close()
14
13
 
15
14
 
16
15
  def test_toggle(toggle):
@@ -14,9 +14,9 @@ from .client_mocks import mocked_client
14
14
  def vscode_widget(qtbot, mocked_client):
15
15
  with mock.patch("bec_widgets.widgets.vscode.vscode.subprocess.Popen") as mock_popen:
16
16
  widget = VSCodeEditor(client=mocked_client)
17
- # qtbot.addWidget(widget)
17
+ qtbot.addWidget(widget)
18
+ qtbot.waitExposed(widget)
18
19
  yield widget
19
- # widget.close()
20
20
 
21
21
 
22
22
  def test_vscode_widget(qtbot, vscode_widget):
@@ -4,13 +4,15 @@ from unittest import mock
4
4
  import numpy as np
5
5
  import pytest
6
6
 
7
+ from bec_widgets.widgets.figure import BECFigure
7
8
  from bec_widgets.widgets.figure.plots.waveform.waveform_curve import CurveConfig, Signal, SignalData
8
9
 
9
10
  from .client_mocks import mocked_client
10
- from .test_bec_figure import bec_figure
11
+ from .conftest import create_widget
11
12
 
12
13
 
13
- def test_adding_curve_to_waveform(bec_figure):
14
+ def test_adding_curve_to_waveform(qtbot, mocked_client):
15
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
14
16
  w1 = bec_figure.plot()
15
17
 
16
18
  # adding curve which is in bec - only names
@@ -38,7 +40,8 @@ def test_adding_curve_to_waveform(bec_figure):
38
40
  assert c3.config.label == "non_existent_device-non_existent_device"
39
41
 
40
42
 
41
- def test_adding_curve_with_same_id(bec_figure):
43
+ def test_adding_curve_with_same_id(qtbot, mocked_client):
44
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
42
45
  w1 = bec_figure.plot()
43
46
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
44
47
 
@@ -47,7 +50,8 @@ def test_adding_curve_with_same_id(bec_figure):
47
50
  assert "Curve with ID 'test_curve' already exists." in str(excinfo.value)
48
51
 
49
52
 
50
- def test_create_waveform1D_by_config(bec_figure):
53
+ def test_create_waveform1D_by_config(qtbot, mocked_client):
54
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
51
55
  w1_config_input = {
52
56
  "widget_class": "BECWaveform",
53
57
  "gui_id": "widget_1",
@@ -132,7 +136,8 @@ def test_create_waveform1D_by_config(bec_figure):
132
136
  assert w1.config.axis.title == "Widget 1"
133
137
 
134
138
 
135
- def test_change_gui_id(bec_figure):
139
+ def test_change_gui_id(qtbot, mocked_client):
140
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
136
141
  w1 = bec_figure.plot()
137
142
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
138
143
  w1.change_gui_id("new_id")
@@ -141,7 +146,8 @@ def test_change_gui_id(bec_figure):
141
146
  assert c1.config.parent_id == "new_id"
142
147
 
143
148
 
144
- def test_getting_curve(bec_figure):
149
+ def test_getting_curve(qtbot, mocked_client):
150
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
145
151
  w1 = bec_figure.plot()
146
152
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
147
153
  c1_expected_config = CurveConfig(
@@ -173,7 +179,8 @@ def test_getting_curve(bec_figure):
173
179
  assert c1.get_config() == c1_expected_config.model_dump()
174
180
 
175
181
 
176
- def test_getting_curve_errors(bec_figure):
182
+ def test_getting_curve_errors(qtbot, mocked_client):
183
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
177
184
  w1 = bec_figure.plot()
178
185
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i", gui_id="test_curve")
179
186
 
@@ -190,7 +197,8 @@ def test_getting_curve_errors(bec_figure):
190
197
  )
191
198
 
192
199
 
193
- def test_add_curve(bec_figure):
200
+ def test_add_curve(qtbot, mocked_client):
201
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
194
202
  w1 = bec_figure.plot()
195
203
 
196
204
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -201,7 +209,8 @@ def test_add_curve(bec_figure):
201
209
  assert c1.config.source == "scan_segment"
202
210
 
203
211
 
204
- def test_change_legend_font_size(bec_figure):
212
+ def test_change_legend_font_size(qtbot, mocked_client):
213
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
205
214
  plot = bec_figure.plot()
206
215
 
207
216
  w1 = plot.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -213,7 +222,8 @@ def test_change_legend_font_size(bec_figure):
213
222
  assert mock_set_scale.call_args == mock.call(2)
214
223
 
215
224
 
216
- def test_remove_curve(bec_figure):
225
+ def test_remove_curve(qtbot, mocked_client):
226
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
217
227
  w1 = bec_figure.plot()
218
228
 
219
229
  w1.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -231,7 +241,8 @@ def test_remove_curve(bec_figure):
231
241
  )
232
242
 
233
243
 
234
- def test_change_curve_appearance_methods(bec_figure, qtbot):
244
+ def test_change_curve_appearance_methods(qtbot, mocked_client):
245
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
235
246
  w1 = bec_figure.plot()
236
247
 
237
248
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -260,7 +271,8 @@ def test_change_curve_appearance_methods(bec_figure, qtbot):
260
271
  }
261
272
 
262
273
 
263
- def test_change_curve_appearance_args(bec_figure):
274
+ def test_change_curve_appearance_args(qtbot, mocked_client):
275
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
264
276
  w1 = bec_figure.plot()
265
277
 
266
278
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -290,7 +302,8 @@ def test_change_curve_appearance_args(bec_figure):
290
302
  }
291
303
 
292
304
 
293
- def test_set_custom_curve_data(bec_figure, qtbot):
305
+ def test_set_custom_curve_data(qtbot, mocked_client):
306
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
294
307
  w1 = bec_figure.plot()
295
308
 
296
309
  c1 = w1.add_curve_custom(
@@ -326,7 +339,8 @@ def test_set_custom_curve_data(bec_figure, qtbot):
326
339
  assert np.array_equal(y_new, [7, 8, 9])
327
340
 
328
341
 
329
- def test_custom_data_2D_array(bec_figure, qtbot):
342
+ def test_custom_data_2D_array(qtbot, mocked_client):
343
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
330
344
 
331
345
  data = np.random.rand(10, 2)
332
346
 
@@ -338,7 +352,8 @@ def test_custom_data_2D_array(bec_figure, qtbot):
338
352
  assert np.array_equal(y, data[:, 1])
339
353
 
340
354
 
341
- def test_get_all_data(bec_figure):
355
+ def test_get_all_data(qtbot, mocked_client):
356
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
342
357
  w1 = bec_figure.plot()
343
358
 
344
359
  c1 = w1.add_curve_custom(
@@ -373,7 +388,8 @@ def test_get_all_data(bec_figure):
373
388
  }
374
389
 
375
390
 
376
- def test_curve_add_by_config(bec_figure):
391
+ def test_curve_add_by_config(qtbot, mocked_client):
392
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
377
393
  w1 = bec_figure.plot()
378
394
 
379
395
  c1_config_input = {
@@ -413,7 +429,8 @@ def test_curve_add_by_config(bec_figure):
413
429
  assert c1.get_config(False) == CurveConfig(**c1_config_input)
414
430
 
415
431
 
416
- def test_scan_update(bec_figure, qtbot):
432
+ def test_scan_update(qtbot, mocked_client):
433
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
417
434
  w1 = bec_figure.plot()
418
435
 
419
436
  c1 = w1.add_curve_bec(x_name="samx", y_name="bpm4i")
@@ -447,7 +464,8 @@ def test_scan_update(bec_figure, qtbot):
447
464
  assert c1.get_data() == ([10], [5])
448
465
 
449
466
 
450
- def test_scan_history_with_val_access(bec_figure, qtbot):
467
+ def test_scan_history_with_val_access(qtbot, mocked_client):
468
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
451
469
  w1 = bec_figure.plot()
452
470
 
453
471
  w1.plot(x_name="samx", y_name="bpm4i")
@@ -472,7 +490,8 @@ def test_scan_history_with_val_access(bec_figure, qtbot):
472
490
  assert np.array_equal(y_data, [4, 5, 6])
473
491
 
474
492
 
475
- def test_scatter_2d_update(bec_figure, qtbot):
493
+ def test_scatter_2d_update(qtbot, mocked_client):
494
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
476
495
  w1 = bec_figure.plot()
477
496
 
478
497
  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):
512
531
  assert colors == expected_z_colors
513
532
 
514
533
 
515
- def test_waveform_single_arg_inputs(bec_figure, qtbot):
534
+ def test_waveform_single_arg_inputs(qtbot, mocked_client):
535
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
516
536
  w1 = bec_figure.plot()
517
537
 
518
538
  w1.plot("bpm4i")
@@ -544,7 +564,8 @@ def test_waveform_single_arg_inputs(bec_figure, qtbot):
544
564
  assert np.array_equal(w1._curves_data["custom"]["np_ndarray 2D"].get_data(), data_array_2D.T)
545
565
 
546
566
 
547
- def test_waveform_set_x_sync(bec_figure, qtbot):
567
+ def test_waveform_set_x_sync(qtbot, mocked_client):
568
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
548
569
  w1 = bec_figure.plot()
549
570
  custom_label = "custom_label"
550
571
  w1.plot("bpm4i")
@@ -601,7 +622,8 @@ def test_waveform_set_x_sync(bec_figure, qtbot):
601
622
  assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [timestamp]"
602
623
 
603
624
 
604
- def test_waveform_async_data_update(bec_figure, qtbot):
625
+ def test_waveform_async_data_update(qtbot, mocked_client):
626
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
605
627
  w1 = bec_figure.plot("async_device")
606
628
  custom_label = "custom_label"
607
629
  w1.set_x_label(custom_label)
@@ -647,7 +669,8 @@ def test_waveform_async_data_update(bec_figure, qtbot):
647
669
  assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]"
648
670
 
649
671
 
650
- def test_waveform_set_x_async(bec_figure, qtbot):
672
+ def test_waveform_set_x_async(qtbot, mocked_client):
673
+ bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
651
674
  w1 = bec_figure.plot("async_device")
652
675
  custom_label = "custom_label"
653
676
  w1.set_x_label(custom_label)