bec-widgets 0.57.1__py3-none-any.whl → 0.57.3__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.
@@ -5,9 +5,8 @@ from bec_lib.endpoints import MessageEndpoints
5
5
  from bec_widgets.cli.client import BECFigure, BECImageShow, BECMotorMap, BECWaveform
6
6
 
7
7
 
8
- def test_rpc_waveform1d_custom_curve(rpc_server_figure, qtbot):
9
- fig = BECFigure(rpc_server_figure.gui_id)
10
- fig_server = rpc_server_figure.gui
8
+ def test_rpc_waveform1d_custom_curve(rpc_server_figure):
9
+ fig = BECFigure(rpc_server_figure)
11
10
 
12
11
  ax = fig.add_plot()
13
12
  curve = ax.add_curve_custom([1, 2, 3], [1, 2, 3])
@@ -15,13 +14,12 @@ def test_rpc_waveform1d_custom_curve(rpc_server_figure, qtbot):
15
14
  curve = ax.curves[0]
16
15
  curve.set_color("blue")
17
16
 
18
- assert len(fig_server.widgets) == 1
19
- assert len(fig_server.widgets[ax.rpc_id].curves) == 1
17
+ assert len(fig.widgets) == 1
18
+ assert len(fig.widgets[ax.rpc_id].curves) == 1
20
19
 
21
20
 
22
21
  def test_rpc_plotting_shortcuts_init_configs(rpc_server_figure, qtbot):
23
- fig = BECFigure(rpc_server_figure.gui_id)
24
- fig_server = rpc_server_figure.gui
22
+ fig = BECFigure(rpc_server_figure)
25
23
 
26
24
  plt = fig.plot(x_name="samx", y_name="bpm4i")
27
25
  im = fig.image("eiger")
@@ -29,7 +27,7 @@ def test_rpc_plotting_shortcuts_init_configs(rpc_server_figure, qtbot):
29
27
  plt_z = fig.add_plot("samx", "samy", "bpm4i")
30
28
 
31
29
  # Checking if classes are correctly initialised
32
- assert len(fig_server.widgets) == 4
30
+ assert len(fig.widgets) == 4
33
31
  assert plt.__class__.__name__ == "BECWaveform"
34
32
  assert plt.__class__ == BECWaveform
35
33
  assert im.__class__.__name__ == "BECImageShow"
@@ -75,24 +73,21 @@ def test_rpc_plotting_shortcuts_init_configs(rpc_server_figure, qtbot):
75
73
  }
76
74
 
77
75
 
78
- def test_rpc_waveform_scan(rpc_server_figure, qtbot):
79
- fig = BECFigure(rpc_server_figure.gui_id)
76
+ def test_rpc_waveform_scan(rpc_server_figure, bec_client_lib):
77
+ fig = BECFigure(rpc_server_figure)
80
78
 
81
79
  # add 3 different curves to track
82
80
  plt = fig.plot(x_name="samx", y_name="bpm4i")
83
81
  fig.plot(x_name="samx", y_name="bpm3a")
84
82
  fig.plot(x_name="samx", y_name="bpm4d")
85
83
 
86
- client = rpc_server_figure.client
84
+ client = bec_client_lib
87
85
  dev = client.device_manager.devices
88
86
  scans = client.scans
89
87
  queue = client.queue
90
88
 
91
89
  status = scans.line_scan(dev.samx, -5, 5, steps=10, exp_time=0.05, relative=False)
92
-
93
- # wait for scan to finish
94
- while not status.status == "COMPLETED":
95
- qtbot.wait(200)
90
+ status.wait()
96
91
 
97
92
  last_scan_data = queue.scan_storage.storage[-1].data
98
93
 
@@ -108,38 +103,33 @@ def test_rpc_waveform_scan(rpc_server_figure, qtbot):
108
103
  assert plt_data["bpm4d-bpm4d"]["y"] == last_scan_data["bpm4d"]["bpm4d"].val
109
104
 
110
105
 
111
- def test_rpc_image(rpc_server_figure, qtbot):
112
- fig = BECFigure(rpc_server_figure.gui_id)
106
+ def test_rpc_image(rpc_server_figure, bec_client_lib):
107
+ fig = BECFigure(rpc_server_figure)
113
108
 
114
109
  im = fig.image("eiger")
115
110
 
116
- client = rpc_server_figure.client
111
+ client = bec_client_lib
117
112
  dev = client.device_manager.devices
118
113
  scans = client.scans
119
114
 
120
115
  status = scans.line_scan(dev.samx, -5, 5, steps=10, exp_time=0.05, relative=False)
121
-
122
- # wait for scan to finish
123
- while not status.status == "COMPLETED":
124
- qtbot.wait(200)
116
+ status.wait()
125
117
 
126
118
  last_image_device = client.connector.get_last(MessageEndpoints.device_monitor("eiger"))[
127
119
  "data"
128
120
  ].data
129
- qtbot.wait(500)
130
121
  last_image_plot = im.images[0].get_data()
131
122
 
132
123
  # check plotted data
133
124
  np.testing.assert_equal(last_image_device, last_image_plot)
134
125
 
135
126
 
136
- def test_rpc_motor_map(rpc_server_figure, qtbot):
137
- fig = BECFigure(rpc_server_figure.gui_id)
138
- fig_server = rpc_server_figure.gui
127
+ def test_rpc_motor_map(rpc_server_figure, bec_client_lib):
128
+ fig = BECFigure(rpc_server_figure)
139
129
 
140
130
  motor_map = fig.motor_map("samx", "samy")
141
131
 
142
- client = rpc_server_figure.client
132
+ client = bec_client_lib
143
133
  dev = client.device_manager.devices
144
134
  scans = client.scans
145
135
 
@@ -147,10 +137,8 @@ def test_rpc_motor_map(rpc_server_figure, qtbot):
147
137
  initial_pos_y = dev.samy.read()["samy"]["value"]
148
138
 
149
139
  status = scans.mv(dev.samx, 1, dev.samy, 2, relative=True)
140
+ status.wait()
150
141
 
151
- # wait for scan to finish
152
- while not status.status == "COMPLETED":
153
- qtbot.wait(200)
154
142
  final_pos_x = dev.samx.read()["samx"]["value"]
155
143
  final_pos_y = dev.samy.read()["samy"]["value"]
156
144
 
@@ -3,40 +3,30 @@ import pytest
3
3
  from bec_widgets.cli.client import BECFigure, BECImageShow, BECMotorMap, BECWaveform
4
4
 
5
5
 
6
- def find_deepest_value(d: dict):
7
- """
8
- Recursively find the deepest value in a dictionary
9
- Args:
10
- d(dict): Dictionary to search
11
-
12
- Returns:
13
- The deepest value in the dictionary.
14
- """
15
- if isinstance(d, dict):
16
- if d:
17
- return find_deepest_value(next(iter(d.values())))
18
- return d
19
-
20
-
21
- def test_rpc_register_list_connections(rpc_server_figure, rpc_register, qtbot):
22
- fig = BECFigure(rpc_server_figure.gui_id)
23
- fig_server = rpc_server_figure.gui
6
+ def test_rpc_register_list_connections(rpc_server_figure):
7
+ fig = BECFigure(rpc_server_figure)
24
8
 
25
9
  plt = fig.plot(x_name="samx", y_name="bpm4i")
26
10
  im = fig.image("eiger")
27
11
  motor_map = fig.motor_map("samx", "samy")
28
12
  plt_z = fig.add_plot("samx", "samy", "bpm4i")
29
13
 
30
- all_connections = rpc_register.list_all_connections()
14
+ # keep only class names from objects, since objects on server and client are different
15
+ # so the best we can do is to compare types (rpc register is unit-tested elsewhere)
16
+ all_connections = {obj_id: type(obj).__name__ for obj_id, obj in fig.get_all_rpc().items()}
31
17
 
32
- # Construct dict of all rpc items manually
33
- all_subwidgets_expected = dict(fig_server.widgets)
34
- curve_1D = find_deepest_value(fig_server.widgets[plt.rpc_id]._curves_data)
35
- curve_2D = find_deepest_value(fig_server.widgets[plt_z.rpc_id]._curves_data)
36
- curves_expected = {curve_1D.rpc_id: curve_1D, curve_2D.rpc_id: curve_2D}
37
- fig_expected = {fig.rpc_id: fig_server}
18
+ all_subwidgets_expected = {wid: type(widget).__name__ for wid, widget in fig.widgets.items()}
19
+ curve_1D = fig.widgets[plt.rpc_id]
20
+ curve_2D = fig.widgets[plt_z.rpc_id]
21
+ curves_expected = {
22
+ curve_1D.rpc_id: type(curve_1D).__name__,
23
+ curve_2D.rpc_id: type(curve_2D).__name__,
24
+ }
25
+ curves_expected.update({curve._gui_id: type(curve).__name__ for curve in curve_1D.curves})
26
+ curves_expected.update({curve._gui_id: type(curve).__name__ for curve in curve_2D.curves})
27
+ fig_expected = {fig.rpc_id: type(fig).__name__}
38
28
  image_item_expected = {
39
- fig_server.widgets[im.rpc_id].images[0].rpc_id: fig_server.widgets[im.rpc_id].images[0]
29
+ fig.widgets[im.rpc_id].images[0].rpc_id: type(fig.widgets[im.rpc_id].images[0]).__name__
40
30
  }
41
31
 
42
32
  all_connections_expected = {