bec-ipython-client 3.35.6__py3-none-any.whl → 3.84.0__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.

Potentially problematic release.


This version of bec-ipython-client might be problematic. Click here for more details.

@@ -4,6 +4,7 @@ import time
4
4
  from contextlib import redirect_stdout
5
5
  from io import StringIO
6
6
  from unittest import mock
7
+ from uuid import uuid4
7
8
 
8
9
  import numpy as np
9
10
  import pytest
@@ -12,6 +13,36 @@ from bec_ipython_client.callbacks.live_table import LiveUpdatesTable, sort_devic
12
13
  from bec_ipython_client.callbacks.utils import ScanRequestMixin
13
14
  from bec_lib import messages
14
15
  from bec_lib.queue_items import QueueItem
16
+ from bec_lib.scan_items import ScanItem
17
+ from bec_lib.scan_manager import ScanManager
18
+ from bec_lib.tests.utils import ConnectorMock
19
+
20
+ # pylint: disable=missing-function-docstring
21
+
22
+
23
+ class ScanItemMock:
24
+ def __init__(self, live_data):
25
+ self.live_data = live_data
26
+ self.start_time = time.time()
27
+ self.metadata = {}
28
+ self.scan_number = 0
29
+ self.scan_id = uuid4()
30
+
31
+ @property
32
+ def end_time(self):
33
+ return time.time()
34
+
35
+
36
+ @pytest.fixture
37
+ def scan_item():
38
+ scan_manager = ScanManager(ConnectorMock(""))
39
+ return ScanItem(
40
+ scan_manager=scan_manager,
41
+ queue_id="queue_id",
42
+ scan_number=[1],
43
+ scan_id=["scan_id"],
44
+ status="status",
45
+ )
15
46
 
16
47
 
17
48
  @pytest.fixture
@@ -26,254 +57,367 @@ def client_with_grid_scan(bec_client_mock):
26
57
  yield client, request_msg
27
58
 
28
59
 
29
- @pytest.mark.timeout(20)
30
- def test_scan_request_mixin(client_with_grid_scan):
31
- client, request_msg = client_with_grid_scan
32
- response_msg = messages.RequestResponseMessage(
33
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
34
- )
35
- request_mixin = ScanRequestMixin(client, "something")
60
+ @mock.patch("bec_ipython_client.callbacks.live_table.time.sleep", mock.MagicMock())
61
+ class TestLiveTable:
62
+ @pytest.mark.timeout(20)
63
+ def test_scan_request_mixin(self, client_with_grid_scan):
64
+ client, request_msg = client_with_grid_scan
65
+ response_msg = messages.RequestResponseMessage(
66
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
67
+ )
68
+ request_mixin = ScanRequestMixin(client, "something")
36
69
 
37
- def update_with_response(request_msg):
38
- time.sleep(1)
39
- client.queue.request_storage.update_with_response(response_msg)
40
-
41
- client.queue.request_storage.update_with_request(request_msg)
42
- update_thread = threading.Thread(target=update_with_response, args=(response_msg,))
43
- update_thread.start()
44
- with mock.patch.object(client.queue.queue_storage, "find_queue_item_by_requestID"):
45
- request_mixin.wait()
46
- update_thread.join()
70
+ def update_with_response(request_msg):
71
+ time.sleep(1)
72
+ client.queue.request_storage.update_with_response(response_msg)
47
73
 
74
+ client.queue.request_storage.update_with_request(request_msg)
75
+ update_thread = threading.Thread(target=update_with_response, args=(response_msg,))
76
+ update_thread.start()
77
+ with mock.patch.object(client.queue.queue_storage, "find_queue_item_by_requestID"):
78
+ request_mixin.wait()
79
+ update_thread.join()
48
80
 
49
- def test_sort_devices():
50
- devices = sort_devices(["samx", "bpm4i", "samy", "bpm4s"], ["samx", "samy"])
51
- assert devices == ["samx", "samy", "bpm4i", "bpm4s"]
81
+ def test_sort_devices(self):
82
+ devices = sort_devices(["samx", "bpm4i", "samy", "bpm4s"], ["samx", "samy"])
83
+ assert devices == ["samx", "samy", "bpm4i", "bpm4s"]
52
84
 
53
-
54
- @pytest.mark.parametrize(
55
- "request_msg,scan_report_devices",
56
- [
57
- (
58
- messages.ScanQueueMessage(
59
- scan_type="grid_scan",
60
- parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
61
- queue="primary",
62
- metadata={"RID": "something"},
85
+ @pytest.mark.parametrize(
86
+ "request_msg,scan_report_devices",
87
+ [
88
+ (
89
+ messages.ScanQueueMessage(
90
+ scan_type="grid_scan",
91
+ parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
92
+ queue="primary",
93
+ metadata={"RID": "something"},
94
+ ),
95
+ ["samx"],
63
96
  ),
64
- ["samx"],
65
- ),
66
- (
67
- messages.ScanQueueMessage(
68
- scan_type="round_scan",
69
- parameter={"args": {"samx": ["samy", 0, 25, 5, 3]}},
70
- queue="primary",
71
- metadata={"RID": "something"},
97
+ (
98
+ messages.ScanQueueMessage(
99
+ scan_type="round_scan",
100
+ parameter={"args": {"samx": ["samy", 0, 25, 5, 3]}},
101
+ queue="primary",
102
+ metadata={"RID": "something"},
103
+ ),
104
+ ["samx", "samy"],
72
105
  ),
73
- ["samx", "samy"],
74
- ),
75
- ],
76
- )
77
- def test_get_devices_from_scan_data(bec_client_mock, request_msg, scan_report_devices):
78
- client = bec_client_mock
79
- client.start()
80
- data = messages.ScanMessage(
81
- point_id=0, scan_id="", data={}, metadata={"scan_report_devices": scan_report_devices}
82
- )
83
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
84
- devices = live_update.get_devices_from_scan_data(data)
85
- assert devices[0 : len(scan_report_devices)] == scan_report_devices
86
-
87
-
88
- @pytest.mark.timeout(20)
89
- def test_wait_for_request_acceptance(client_with_grid_scan):
90
- client, request_msg = client_with_grid_scan
91
- response_msg = messages.RequestResponseMessage(
92
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
106
+ ],
93
107
  )
94
- client.queue.request_storage.update_with_request(request_msg)
95
- client.queue.request_storage.update_with_response(response_msg)
96
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
97
- with mock.patch.object(client.queue.queue_storage, "find_queue_item_by_requestID"):
98
- live_update.wait_for_request_acceptance()
108
+ def test_get_devices_from_scan_data(self, bec_client_mock, request_msg, scan_report_devices):
109
+ client = bec_client_mock
110
+ data = messages.ScanMessage(
111
+ point_id=0, scan_id="", data={}, metadata={"scan_report_devices": scan_report_devices}
112
+ )
113
+ live_update = LiveUpdatesTable(
114
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
115
+ )
116
+ devices = live_update.get_devices_from_scan_data(data)
117
+ assert devices[0 : len(scan_report_devices)] == scan_report_devices
99
118
 
119
+ @pytest.mark.timeout(20)
120
+ def test_wait_for_request_acceptance(self, client_with_grid_scan):
121
+ client, request_msg = client_with_grid_scan
122
+ response_msg = messages.RequestResponseMessage(
123
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
124
+ )
125
+ client.queue.request_storage.update_with_request(request_msg)
126
+ client.queue.request_storage.update_with_response(response_msg)
127
+ live_update = LiveUpdatesTable(
128
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
129
+ )
130
+ with mock.patch.object(client.queue.queue_storage, "find_queue_item_by_requestID"):
131
+ live_update.wait_for_request_acceptance()
100
132
 
101
- class ScanItemMock:
102
- def __init__(self, live_data):
103
- self.live_data = live_data
104
- self.metadata = {}
133
+ @pytest.mark.timeout(20)
134
+ def test_run_update(self, bec_client_mock, scan_item):
135
+ request_msg = messages.ScanQueueMessage(
136
+ scan_type="grid_scan",
137
+ parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
138
+ queue="primary",
139
+ metadata={"RID": "something"},
140
+ )
141
+ client = bec_client_mock
142
+ client.start()
143
+ data = messages.ScanMessage(point_id=0, scan_id="", data={}, metadata={})
144
+ live_update = LiveUpdatesTable(
145
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
146
+ )
147
+ live_update.scan_item = scan_item
148
+ scan_item.num_points = 2
149
+ scan_item.live_data = {0: data}
150
+ with mock.patch.object(live_update, "print_table_data") as mock_print_table_data:
151
+ live_update._run_update(1)
152
+ assert mock_print_table_data.called
153
+ scan_item.num_points = 2
154
+ scan_item.live_data = {0: data, 1: data}
155
+ scan_item.status = "closed"
156
+ with mock.patch.object(live_update, "print_table_data") as mock_print_table_data:
157
+ live_update._run_update(2)
158
+ assert mock_print_table_data.called
105
159
 
160
+ @pytest.mark.timeout(20)
161
+ def test_run_update_without_monitored_devices(self, bec_client_mock, scan_item):
162
+ request_msg = messages.ScanQueueMessage(
163
+ scan_type="grid_scan",
164
+ parameter={"args": {"samx": (-5, 5, 3)}, "kwargs": {}},
165
+ queue="primary",
166
+ metadata={"RID": "something"},
167
+ )
168
+ client = bec_client_mock
169
+ client.start()
170
+ data = messages.ScanMessage(point_id=0, scan_id="", data={}, metadata={})
171
+ live_update = LiveUpdatesTable(
172
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
173
+ )
174
+ live_update.scan_item = scan_item
175
+ scan_item.num_points = 2
176
+ scan_item.live_data = {0: data}
177
+ with mock.patch.object(live_update, "print_table_data") as mock_print_table_data:
178
+ live_update._run_update(1)
179
+ assert mock_print_table_data.called
180
+ scan_item.num_points = 2
181
+ scan_item.live_data = {}
182
+ scan_item.status_message = messages.ScanStatusMessage(
183
+ readout_priority={"monitored": [], "baseline": ["samx"]},
184
+ scan_id="scan_id",
185
+ scan_number=1,
186
+ scan_type="step",
187
+ scan_report_devices=[],
188
+ status="closed",
189
+ info={},
190
+ )
191
+ scan_item.status = "closed"
192
+ with mock.patch.object(live_update, "print_table_data") as mock_print_table_data:
193
+ live_update._run_update(2)
194
+ assert not mock_print_table_data.called
106
195
 
107
- def test_print_table_data(client_with_grid_scan):
108
- client, request_msg = client_with_grid_scan
109
- response_msg = messages.RequestResponseMessage(
110
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
111
- )
112
- client.queue.request_storage.update_with_request(request_msg)
113
- client.queue.request_storage.update_with_response(response_msg)
114
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
115
- live_update.point_data = messages.ScanMessage(
116
- point_id=0,
117
- scan_id="",
118
- data={"samx": {"samx": {"value": 0}}},
119
- metadata={"scan_report_devices": ["samx"], "scan_type": "step"},
120
- )
121
- live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
122
- with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
123
- live_update.print_table_data()
124
- assert mock_client_msgs.called
196
+ def test_print_table_data(self, client_with_grid_scan):
197
+ client, request_msg = client_with_grid_scan
198
+ response_msg = messages.RequestResponseMessage(
199
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
200
+ )
201
+ client.queue.request_storage.update_with_request(request_msg)
202
+ client.queue.request_storage.update_with_response(response_msg)
203
+ live_update = LiveUpdatesTable(
204
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
205
+ )
206
+ live_update.point_data = messages.ScanMessage(
207
+ point_id=0,
208
+ scan_id="",
209
+ data={"samx": {"samx": {"value": 0}}},
210
+ metadata={"scan_report_devices": ["samx"], "scan_type": "step"},
211
+ )
212
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
213
+ with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
214
+ live_update.print_table_data()
215
+ assert mock_client_msgs.called
125
216
 
217
+ def test_print_table_data_lamni_flyer(self, client_with_grid_scan):
218
+ client, request_msg = client_with_grid_scan
219
+ response_msg = messages.RequestResponseMessage(
220
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
221
+ )
222
+ client.queue.request_storage.update_with_request(request_msg)
223
+ client.queue.request_storage.update_with_response(response_msg)
224
+ live_update = LiveUpdatesTable(
225
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
226
+ )
227
+ live_update.point_data = messages.ScanMessage(
228
+ point_id=0,
229
+ scan_id="",
230
+ data={"lamni_flyer_1": {"value": 0}},
231
+ metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
232
+ )
233
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
234
+ with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
235
+ live_update.print_table_data()
236
+ assert mock_client_msgs.called
126
237
 
127
- def test_print_table_data_lamni_flyer(client_with_grid_scan):
128
- client, request_msg = client_with_grid_scan
129
- response_msg = messages.RequestResponseMessage(
130
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
131
- )
132
- client.queue.request_storage.update_with_request(request_msg)
133
- client.queue.request_storage.update_with_response(response_msg)
134
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
135
- live_update.point_data = messages.ScanMessage(
136
- point_id=0,
137
- scan_id="",
138
- data={"lamni_flyer_1": {"value": 0}},
139
- metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
140
- )
141
- live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
142
- with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
143
- live_update.print_table_data()
144
- assert mock_client_msgs.called
238
+ def test_print_table_data_hinted_value(self, client_with_grid_scan):
239
+ client, request_msg = client_with_grid_scan
240
+ response_msg = messages.RequestResponseMessage(
241
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
242
+ )
243
+ client.queue.request_storage.update_with_request(request_msg)
244
+ client.queue.request_storage.update_with_response(response_msg)
245
+ live_update = LiveUpdatesTable(
246
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
247
+ )
248
+ client.device_manager.devices["samx"]._info["hints"] = {"fields": ["samx_hint"]}
249
+ client.device_manager.devices["samx"].precision = 3
250
+ live_update.point_data = messages.ScanMessage(
251
+ point_id=0,
252
+ scan_id="",
253
+ data={"samx": {"samx_hint": {"value": 0}}},
254
+ metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
255
+ )
256
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
145
257
 
258
+ with (
259
+ mock.patch.object(live_update, "table") as mocked_table,
260
+ mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs,
261
+ ):
262
+ live_update.dev_values = (len(live_update._get_header()) - 1) * [0]
263
+ live_update.print_table_data()
264
+ mocked_table.get_row.assert_called_with("0", "0.000")
265
+ assert mock_client_msgs.called
146
266
 
147
- def test_print_table_data_hinted_value(client_with_grid_scan):
148
- client, request_msg = client_with_grid_scan
149
- response_msg = messages.RequestResponseMessage(
150
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
151
- )
152
- client.queue.request_storage.update_with_request(request_msg)
153
- client.queue.request_storage.update_with_response(response_msg)
154
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
155
- client.device_manager.devices["samx"]._info["hints"] = {"fields": ["samx_hint"]}
156
- client.device_manager.devices["samx"].precision = 3
157
- live_update.point_data = messages.ScanMessage(
158
- point_id=0,
159
- scan_id="",
160
- data={"samx": {"samx_hint": {"value": 0}}},
161
- metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
267
+ @pytest.mark.parametrize(
268
+ ["prec", "expected_prec"], [(2, 2), (3, 3), (4, 4), (-1, -1), (0, 0), ("precision", 2)]
162
269
  )
163
- live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
164
-
165
- with (
166
- mock.patch.object(live_update, "table") as mocked_table,
167
- mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs,
270
+ def test_print_table_data_hinted_value_with_precision(
271
+ self, client_with_grid_scan, prec, expected_prec
168
272
  ):
169
- live_update.dev_values = (len(live_update._get_header()) - 1) * [0]
170
- live_update.print_table_data()
171
- mocked_table.get_row.assert_called_with("0", "0.000")
172
- assert mock_client_msgs.called
273
+ client, request_msg = client_with_grid_scan
274
+ response_msg = messages.RequestResponseMessage(
275
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
276
+ )
277
+ client.queue.request_storage.update_with_request(request_msg)
278
+ client.queue.request_storage.update_with_response(response_msg)
279
+ live_update = LiveUpdatesTable(
280
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
281
+ )
282
+ client.device_manager.devices["samx"]._info["hints"] = {"fields": ["samx_hint"]}
283
+ client.device_manager.devices["samx"].precision = prec
284
+ live_update.point_data = messages.ScanMessage(
285
+ point_id=0,
286
+ scan_id="",
287
+ data={"samx": {"samx_hint": {"value": 0}}},
288
+ metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
289
+ )
290
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
173
291
 
292
+ with (
293
+ mock.patch.object(live_update, "table") as mocked_table,
294
+ mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs,
295
+ ):
296
+ live_update.dev_values = (len(live_update._get_header()) - 1) * [0]
297
+ live_update.print_table_data()
298
+ if expected_prec < 0:
299
+ mocked_table.get_row.assert_called_with("0", f"{0:.{-expected_prec}g}")
300
+ else:
301
+ mocked_table.get_row.assert_called_with("0", f"{0:.{expected_prec}f}")
174
302
 
175
- def test_print_table_data_hinted_value_with_precision(client_with_grid_scan):
176
- client, request_msg = client_with_grid_scan
177
- response_msg = messages.RequestResponseMessage(
178
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
303
+ @pytest.mark.parametrize(
304
+ "value,expected",
305
+ [
306
+ (np.int32(1), "1.00"),
307
+ (np.float64(1.00000), "1.00"),
308
+ (0, "0.00"),
309
+ (1, "1.00"),
310
+ (0.000, "0.00"),
311
+ (True, "1.00"),
312
+ (False, "0.00"),
313
+ ("True", "True"),
314
+ ("False", "False"),
315
+ ("0", "0"),
316
+ ("1", "1"),
317
+ ((0, 1), "(0, 1)"),
318
+ ({"value": 0}, "{'value': 0}"),
319
+ (np.array([0, 1]), "[0 1]"),
320
+ ({1, 2}, "{1, 2}"),
321
+ ],
179
322
  )
180
- client.queue.request_storage.update_with_request(request_msg)
181
- client.queue.request_storage.update_with_response(response_msg)
182
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
183
- client.device_manager.devices["samx"]._info["hints"] = {"fields": ["samx_hint"]}
184
- client.device_manager.devices["samx"].precision = 2
185
- live_update.point_data = messages.ScanMessage(
186
- point_id=0,
187
- scan_id="",
188
- data={"samx": {"samx_hint": {"value": 0}}},
189
- metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
190
- )
191
- live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
323
+ def test_print_table_data_variants(self, client_with_grid_scan, value, expected):
324
+ client, request_msg = client_with_grid_scan
325
+ response_msg = messages.RequestResponseMessage(
326
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
327
+ )
328
+ client.queue.request_storage.update_with_request(request_msg)
329
+ client.queue.request_storage.update_with_response(response_msg)
330
+ live_update = LiveUpdatesTable(
331
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
332
+ )
333
+ live_update.point_data = messages.ScanMessage(
334
+ point_id=0,
335
+ scan_id="",
336
+ data={"lamni_flyer_1": {"value": value}},
337
+ metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
338
+ )
339
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
192
340
 
193
- with (
194
- mock.patch.object(live_update, "table") as mocked_table,
195
- mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs,
196
- ):
197
- live_update.dev_values = (len(live_update._get_header()) - 1) * [0]
198
- live_update.print_table_data()
199
- mocked_table.get_row.assert_called_with("0", f"{0:.2f}")
341
+ with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
342
+ live_update.print_table_data()
343
+ with mock.patch.object(live_update, "table") as mocked_table:
344
+ live_update.dev_values = (len(live_update._get_header()) - 1) * [value]
345
+ live_update.print_table_data()
346
+ mocked_table.get_row.assert_called_with("0", expected)
200
347
 
348
+ def test_print_client_msgs(self, client_with_grid_scan):
349
+ client, request_msg = client_with_grid_scan
350
+ response_msg = messages.RequestResponseMessage(
351
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
352
+ )
353
+ client.queue.request_storage.update_with_request(request_msg)
354
+ client.queue.request_storage.update_with_response(response_msg)
355
+ client_msg = messages.ClientInfoMessage(
356
+ message="message", RID="something", show_asap=True, source="scan_server"
357
+ )
358
+ client_msg2 = messages.ClientInfoMessage(
359
+ message="message2", RID="something", show_asap=False
360
+ )
361
+ mock_queue_item = QueueItem(
362
+ client.queue.request_storage.scan_manager,
363
+ queue_id="something",
364
+ request_blocks=[],
365
+ status="running",
366
+ active_request_block={},
367
+ scan_id="test",
368
+ client_messages=[client_msg, client_msg2],
369
+ )
370
+ with mock.patch.object(
371
+ client.queue.request_storage.scan_manager.queue_storage,
372
+ "find_queue_item_by_requestID",
373
+ return_value=mock_queue_item,
374
+ ):
375
+ live_update = LiveUpdatesTable(
376
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
377
+ )
378
+ live_update.wait_for_request_acceptance()
379
+ result = StringIO()
380
+ with redirect_stdout(result):
381
+ live_update._print_client_msgs_asap()
382
+ rtr1 = "Client info (scan_server) : message" + "\n"
383
+ assert result.getvalue() == rtr1
384
+ # second time should not add anything
385
+ rtr1 += "------------------------\nSummary of client messages\n------------------------\nClient info () : message2\n------------------------\n"
386
+ live_update._print_client_msgs_all()
387
+ assert result.getvalue() == rtr1
201
388
 
202
- @pytest.mark.parametrize(
203
- "value,expected",
204
- [
205
- (0, "0.00"),
206
- (1, "1.00"),
207
- (0.000, "0.00"),
208
- (True, "1.00"),
209
- (False, "0.00"),
210
- ("True", "True"),
211
- ("False", "False"),
212
- ("0", "0"),
213
- ("1", "1"),
214
- ((0, 1), "(0, 1)"),
215
- ({"value": 0}, "{'value': 0}"),
216
- (np.array([0, 1]), "[0 1]"),
217
- ({1, 2}, "{1, 2}"),
218
- ],
219
- )
220
- def test_print_table_data_variants(client_with_grid_scan, value, expected):
221
- client, request_msg = client_with_grid_scan
222
- response_msg = messages.RequestResponseMessage(
223
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
224
- )
225
- client.queue.request_storage.update_with_request(request_msg)
226
- client.queue.request_storage.update_with_response(response_msg)
227
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
228
- live_update.point_data = messages.ScanMessage(
229
- point_id=0,
230
- scan_id="",
231
- data={"lamni_flyer_1": {"value": value}},
232
- metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
233
- )
234
- live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
389
+ @pytest.mark.parametrize(["prec", "warn"], [(2, False), (3, False), ("wrong_prec", True)])
390
+ @mock.patch("bec_ipython_client.callbacks.live_table.logger")
391
+ def test_close_table_prints_warning_at_end(self, logger, client_with_grid_scan, prec, warn):
392
+ client, request_msg = client_with_grid_scan
393
+ response_msg = messages.RequestResponseMessage(
394
+ accepted=True, message={"msg": ""}, metadata={"RID": "something"}
395
+ )
396
+ client.queue.request_storage.update_with_request(request_msg)
397
+ client.queue.request_storage.update_with_response(response_msg)
398
+ live_update = LiveUpdatesTable(
399
+ client, {"scan_progress": {"points": 10, "show_table": True}}, request_msg
400
+ )
401
+ client.device_manager.devices["samx"]._info["hints"] = {"fields": ["samx_hint"]}
402
+ client.device_manager.devices["samx"].precision = prec
403
+ live_update.point_data = messages.ScanMessage(
404
+ point_id=0,
405
+ scan_id="",
406
+ data={"samx": {"samx_hint": {"value": 0}}},
407
+ metadata={"scan_report_devices": ["samx"], "scan_type": "fly"},
408
+ )
409
+ live_update.scan_item = ScanItemMock(live_data=[live_update.point_data])
235
410
 
236
- with mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs:
237
- live_update.print_table_data()
238
- with mock.patch.object(live_update, "table") as mocked_table:
239
- live_update.dev_values = (len(live_update._get_header()) - 1) * [value]
411
+ with (
412
+ mock.patch.object(live_update, "table") as mocked_table,
413
+ mock.patch.object(live_update, "_print_client_msgs_asap") as mock_client_msgs,
414
+ ):
415
+ live_update.dev_values = (len(live_update._get_header()) - 1) * [0]
240
416
  live_update.print_table_data()
241
- mocked_table.get_row.assert_called_with("0", expected)
242
-
417
+ logger.warning.assert_not_called()
418
+ live_update.close_table()
243
419
 
244
- def test_print_client_msgs(client_with_grid_scan):
245
- client, request_msg = client_with_grid_scan
246
- response_msg = messages.RequestResponseMessage(
247
- accepted=True, message={"msg": ""}, metadata={"RID": "something"}
248
- )
249
- client.queue.request_storage.update_with_request(request_msg)
250
- client.queue.request_storage.update_with_response(response_msg)
251
- client_msg = messages.ClientInfoMessage(
252
- message="message", RID="something", show_asap=True, source="scan_server"
253
- )
254
- client_msg2 = messages.ClientInfoMessage(message="message2", RID="something", show_asap=False)
255
- mock_queue_item = QueueItem(
256
- client.queue.request_storage.scan_manager,
257
- queue_id="something",
258
- request_blocks=[],
259
- status="running",
260
- active_request_block={},
261
- scan_id="test",
262
- client_messages=[client_msg, client_msg2],
263
- )
264
- with mock.patch.object(
265
- client.queue.request_storage.scan_manager.queue_storage,
266
- "find_queue_item_by_requestID",
267
- return_value=mock_queue_item,
268
- ):
269
- live_update = LiveUpdatesTable(client, {"scan_progress": 10}, request_msg)
270
- live_update.wait_for_request_acceptance()
271
- result = StringIO()
272
- with redirect_stdout(result):
273
- live_update._print_client_msgs_asap()
274
- rtr1 = "Client info (scan_server) : message" + "\n"
275
- assert result.getvalue() == rtr1
276
- # second time should not add anything
277
- rtr1 += "------------------------\nSummary of client messages\n------------------------\nClient info () : message2\n------------------------\n"
278
- live_update._print_client_msgs_all()
279
- assert result.getvalue() == rtr1
420
+ if warn:
421
+ logger.warning.assert_called()
422
+ else:
423
+ logger.warning.assert_not_called()