bec-widgets 0.72.0__py3-none-any.whl → 0.72.2__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.
- CHANGELOG.md +16 -14
- PKG-INFO +1 -1
- bec_widgets/cli/client.py +21 -21
- bec_widgets/examples/jupyter_console/jupyter_console_window.py +1 -1
- bec_widgets/utils/bec_designer.py +50 -1
- bec_widgets/widgets/__init__.py +1 -5
- bec_widgets/widgets/bec_status_box/bec_status_box.py +6 -2
- bec_widgets/widgets/ring_progress_bar/__init__.py +1 -0
- bec_widgets/widgets/{spiral_progress_bar → ring_progress_bar}/ring.py +16 -6
- bec_widgets/widgets/{spiral_progress_bar/spiral_progress_bar.py → ring_progress_bar/ring_progress_bar.py} +10 -8
- {bec_widgets-0.72.0.dist-info → bec_widgets-0.72.2.dist-info}/METADATA +1 -1
- {bec_widgets-0.72.0.dist-info → bec_widgets-0.72.2.dist-info}/RECORD +23 -23
- docs/user/getting_started/quick_start.md +2 -2
- docs/user/widgets/{spiral_progress_bar.md → ring_progress_bar.md} +9 -9
- docs/user/widgets/widgets.md +1 -1
- pyproject.toml +1 -1
- tests/end-2-end/test_bec_dock_rpc_e2e.py +5 -5
- tests/unit_tests/test_bec_status_box.py +121 -152
- tests/unit_tests/test_ring_progress_bar.py +338 -0
- tests/unit_tests/test_rpc_widget_handler.py +1 -1
- bec_widgets/widgets/spiral_progress_bar/__init__.py +0 -1
- tests/unit_tests/test_spiral_progress_bar.py +0 -338
- {bec_widgets-0.72.0.dist-info → bec_widgets-0.72.2.dist-info}/WHEEL +0 -0
- {bec_widgets-0.72.0.dist-info → bec_widgets-0.72.2.dist-info}/entry_points.txt +0 -0
- {bec_widgets-0.72.0.dist-info → bec_widgets-0.72.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,152 +1,121 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# status_box = BECStatusBox(parent=None, service_name=name, client=mocked_client)
|
123
|
-
# qtbot.addWidget(status_box)
|
124
|
-
# qtbot.waitExposed(status_box)
|
125
|
-
# status_box.CORE_SERVICES = ["test_service"]
|
126
|
-
# name = "test_service"
|
127
|
-
# status = BECStatus.RUNNING
|
128
|
-
# info = {"test": "test"}
|
129
|
-
# metrics = {"metric": "test_metric"}
|
130
|
-
# services_status = {name: StatusMessage(name=name, status=status, info=info)}
|
131
|
-
# services_metrics = {name: ServiceMetricMessage(name=name, metrics=metrics)}
|
132
|
-
#
|
133
|
-
# status_box.update_core_services(services_status, services_metrics)
|
134
|
-
# assert mock_update.call_args == mock.call(status.name)
|
135
|
-
#
|
136
|
-
# status = BECStatus.IDLE
|
137
|
-
# services_status = {name: StatusMessage(name=name, status=status, info=info)}
|
138
|
-
# services_metrics = {name: ServiceMetricMessage(name=name, metrics=metrics)}
|
139
|
-
# status_box.update_core_services(services_status, services_metrics)
|
140
|
-
# assert mock_update.call_args == mock.call("ERROR")
|
141
|
-
#
|
142
|
-
#
|
143
|
-
# def test_double_click_item(status_box):
|
144
|
-
# name = "test_service"
|
145
|
-
# status = BECStatus.IDLE
|
146
|
-
# info = {"test": "test"}
|
147
|
-
# metrics = {"MyData": "This should be shown nicely"}
|
148
|
-
# status_box.add_tree_item(name, status, info, metrics)
|
149
|
-
# item, status_item = status_box.tree_items[name]
|
150
|
-
# with mock.patch.object(status_item, "show_popup") as mock_show_popup:
|
151
|
-
# status_box.itemDoubleClicked.emit(item, 0)
|
152
|
-
# assert mock_show_popup.call_count == 1
|
1
|
+
from unittest import mock
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
from bec_lib.messages import BECStatus, ServiceMetricMessage, StatusMessage
|
5
|
+
|
6
|
+
from bec_widgets.widgets.bec_status_box.bec_status_box import BECServiceInfoContainer, BECStatusBox
|
7
|
+
|
8
|
+
from .client_mocks import mocked_client
|
9
|
+
|
10
|
+
|
11
|
+
@pytest.fixture
|
12
|
+
def service_status_fixture():
|
13
|
+
yield mock.MagicMock()
|
14
|
+
|
15
|
+
|
16
|
+
@pytest.fixture
|
17
|
+
def status_box(qtbot, mocked_client, service_status_fixture):
|
18
|
+
widget = BECStatusBox(
|
19
|
+
client=mocked_client, service_name="test", bec_service_status_mixin=service_status_fixture
|
20
|
+
)
|
21
|
+
qtbot.addWidget(widget)
|
22
|
+
qtbot.waitExposed(widget)
|
23
|
+
yield widget
|
24
|
+
|
25
|
+
|
26
|
+
def test_update_top_item(status_box):
|
27
|
+
assert status_box.children()[0].children()[0].config.status == "IDLE"
|
28
|
+
status_box.update_top_item_status(status="RUNNING")
|
29
|
+
assert status_box.bec_service_info_container["test"].status == "RUNNING"
|
30
|
+
assert status_box.children()[0].children()[0].config.status == "RUNNING"
|
31
|
+
|
32
|
+
|
33
|
+
def test_create_status_widget(status_box):
|
34
|
+
name = "test_service"
|
35
|
+
status = BECStatus.IDLE
|
36
|
+
info = {"test": "test"}
|
37
|
+
metrics = {"metric": "test_metric"}
|
38
|
+
item = status_box._create_status_widget(name, status, info, metrics)
|
39
|
+
assert item.config.service_name == name
|
40
|
+
assert item.config.status == status.name
|
41
|
+
assert item.config.info == info
|
42
|
+
assert item.config.metrics == metrics
|
43
|
+
|
44
|
+
|
45
|
+
def test_bec_service_container(status_box):
|
46
|
+
name = "test_service"
|
47
|
+
status = BECStatus.IDLE
|
48
|
+
info = {"test": "test"}
|
49
|
+
metrics = {"metric": "test_metric"}
|
50
|
+
expected_return = BECServiceInfoContainer(
|
51
|
+
service_name=name, status=status, info=info, metrics=metrics
|
52
|
+
)
|
53
|
+
assert status_box.service_name in status_box.bec_service_info_container
|
54
|
+
assert len(status_box.bec_service_info_container) == 1
|
55
|
+
status_box._update_bec_service_container(name, status, info, metrics)
|
56
|
+
assert len(status_box.bec_service_info_container) == 2
|
57
|
+
assert status_box.bec_service_info_container[name] == expected_return
|
58
|
+
|
59
|
+
|
60
|
+
def test_add_tree_item(status_box):
|
61
|
+
name = "test_service"
|
62
|
+
status = BECStatus.IDLE
|
63
|
+
info = {"test": "test"}
|
64
|
+
metrics = {"metric": "test_metric"}
|
65
|
+
assert len(status_box.children()[0].children()) == 1
|
66
|
+
status_box.add_tree_item(name, status, info, metrics)
|
67
|
+
assert len(status_box.children()[0].children()) == 2
|
68
|
+
assert name in status_box.tree_items
|
69
|
+
|
70
|
+
|
71
|
+
def test_update_service_status(status_box):
|
72
|
+
"""Also checks check redundant tree items"""
|
73
|
+
name = "test_service"
|
74
|
+
status = BECStatus.IDLE
|
75
|
+
info = {"test": "test"}
|
76
|
+
metrics = {"metric": "test_metric"}
|
77
|
+
status_box.add_tree_item(name, status, info, {})
|
78
|
+
not_connected_name = "invalid_service"
|
79
|
+
status_box.add_tree_item(not_connected_name, status, info, metrics)
|
80
|
+
|
81
|
+
services_status = {name: StatusMessage(name=name, status=status, info=info)}
|
82
|
+
services_metrics = {name: ServiceMetricMessage(name=name, metrics=metrics)}
|
83
|
+
|
84
|
+
with mock.patch.object(status_box, "update_core_services", return_value=services_status):
|
85
|
+
assert not_connected_name in status_box.tree_items
|
86
|
+
status_box.update_service_status(services_status, services_metrics)
|
87
|
+
assert status_box.tree_items[name][1].config.metrics == metrics
|
88
|
+
assert not_connected_name not in status_box.tree_items
|
89
|
+
|
90
|
+
|
91
|
+
def test_update_core_services(status_box):
|
92
|
+
status_box.CORE_SERVICES = ["test_service"]
|
93
|
+
name = "test_service"
|
94
|
+
status = BECStatus.RUNNING
|
95
|
+
info = {"test": "test"}
|
96
|
+
metrics = {"metric": "test_metric"}
|
97
|
+
services_status = {name: StatusMessage(name=name, status=status, info=info)}
|
98
|
+
services_metrics = {name: ServiceMetricMessage(name=name, metrics=metrics)}
|
99
|
+
|
100
|
+
status_box.update_core_services(services_status, services_metrics)
|
101
|
+
assert status_box.children()[0].children()[0].config.status == "RUNNING"
|
102
|
+
assert status_box.tree_items[name][1].config.metrics == metrics
|
103
|
+
|
104
|
+
status = BECStatus.IDLE
|
105
|
+
services_status = {name: StatusMessage(name=name, status=status, info=info)}
|
106
|
+
services_metrics = {name: ServiceMetricMessage(name=name, metrics=metrics)}
|
107
|
+
status_box.update_core_services(services_status, services_metrics)
|
108
|
+
assert status_box.children()[0].children()[0].config.status == "ERROR"
|
109
|
+
assert status_box.tree_items[name][1].config.metrics == metrics
|
110
|
+
|
111
|
+
|
112
|
+
def test_double_click_item(status_box):
|
113
|
+
name = "test_service"
|
114
|
+
status = BECStatus.IDLE
|
115
|
+
info = {"test": "test"}
|
116
|
+
metrics = {"MyData": "This should be shown nicely"}
|
117
|
+
status_box.add_tree_item(name, status, info, metrics)
|
118
|
+
item, status_item = status_box.tree_items[name]
|
119
|
+
with mock.patch.object(status_item, "show_popup") as mock_show_popup:
|
120
|
+
status_box.itemDoubleClicked.emit(item, 0)
|
121
|
+
assert mock_show_popup.call_count == 1
|
@@ -0,0 +1,338 @@
|
|
1
|
+
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
from bec_lib.endpoints import MessageEndpoints
|
5
|
+
from pydantic import ValidationError
|
6
|
+
|
7
|
+
from bec_widgets.utils import Colors
|
8
|
+
from bec_widgets.widgets.ring_progress_bar import RingProgressBar
|
9
|
+
from bec_widgets.widgets.ring_progress_bar.ring import ProgressbarConnections, RingConfig
|
10
|
+
from bec_widgets.widgets.ring_progress_bar.ring_progress_bar import RingProgressBarConfig
|
11
|
+
|
12
|
+
from .client_mocks import mocked_client
|
13
|
+
|
14
|
+
|
15
|
+
@pytest.fixture
|
16
|
+
def ring_progress_bar(qtbot, mocked_client):
|
17
|
+
widget = RingProgressBar(client=mocked_client)
|
18
|
+
qtbot.addWidget(widget)
|
19
|
+
qtbot.waitExposed(widget)
|
20
|
+
yield widget
|
21
|
+
widget.close()
|
22
|
+
|
23
|
+
|
24
|
+
def test_bar_init(ring_progress_bar):
|
25
|
+
assert ring_progress_bar is not None
|
26
|
+
assert ring_progress_bar.client is not None
|
27
|
+
assert isinstance(ring_progress_bar, RingProgressBar)
|
28
|
+
assert ring_progress_bar.config.widget_class == "RingProgressBar"
|
29
|
+
assert ring_progress_bar.config.gui_id is not None
|
30
|
+
assert ring_progress_bar.gui_id == ring_progress_bar.config.gui_id
|
31
|
+
|
32
|
+
|
33
|
+
def test_config_validation_num_of_bars():
|
34
|
+
config = RingProgressBarConfig(num_bars=100, min_num_bars=1, max_num_bars=10)
|
35
|
+
|
36
|
+
assert config.num_bars == 10
|
37
|
+
|
38
|
+
|
39
|
+
def test_config_validation_num_of_ring_error():
|
40
|
+
ring_config_0 = RingConfig(index=0)
|
41
|
+
ring_config_1 = RingConfig(index=1)
|
42
|
+
|
43
|
+
with pytest.raises(ValidationError) as excinfo:
|
44
|
+
RingProgressBarConfig(rings=[ring_config_0, ring_config_1], num_bars=1)
|
45
|
+
errors = excinfo.value.errors()
|
46
|
+
assert len(errors) == 1
|
47
|
+
assert errors[0]["type"] == "different number of configs"
|
48
|
+
assert "Length of rings configuration (2) does not match the number of bars (1)." in str(
|
49
|
+
excinfo.value
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
def test_config_validation_ring_indices_wrong_order():
|
54
|
+
ring_config_0 = RingConfig(index=2)
|
55
|
+
ring_config_1 = RingConfig(index=5)
|
56
|
+
|
57
|
+
with pytest.raises(ValidationError) as excinfo:
|
58
|
+
RingProgressBarConfig(rings=[ring_config_0, ring_config_1], num_bars=2)
|
59
|
+
errors = excinfo.value.errors()
|
60
|
+
assert len(errors) == 1
|
61
|
+
assert errors[0]["type"] == "wrong indices"
|
62
|
+
assert (
|
63
|
+
"Indices of ring configurations must be unique and in order from 0 to num_bars 2."
|
64
|
+
in str(excinfo.value)
|
65
|
+
)
|
66
|
+
|
67
|
+
|
68
|
+
def test_config_validation_ring_same_indices():
|
69
|
+
ring_config_0 = RingConfig(index=0)
|
70
|
+
ring_config_1 = RingConfig(index=0)
|
71
|
+
|
72
|
+
with pytest.raises(ValidationError) as excinfo:
|
73
|
+
RingProgressBarConfig(rings=[ring_config_0, ring_config_1], num_bars=2)
|
74
|
+
errors = excinfo.value.errors()
|
75
|
+
assert len(errors) == 1
|
76
|
+
assert errors[0]["type"] == "wrong indices"
|
77
|
+
assert (
|
78
|
+
"Indices of ring configurations must be unique and in order from 0 to num_bars 2."
|
79
|
+
in str(excinfo.value)
|
80
|
+
)
|
81
|
+
|
82
|
+
|
83
|
+
def test_config_validation_invalid_colormap():
|
84
|
+
with pytest.raises(ValueError) as excinfo:
|
85
|
+
RingProgressBarConfig(color_map="crazy_colors")
|
86
|
+
errors = excinfo.value.errors()
|
87
|
+
assert len(errors) == 1
|
88
|
+
assert errors[0]["type"] == "unsupported colormap"
|
89
|
+
assert "Colormap 'crazy_colors' not found in the current installation of pyqtgraph" in str(
|
90
|
+
excinfo.value
|
91
|
+
)
|
92
|
+
|
93
|
+
|
94
|
+
def test_ring_connection_endpoint_validation():
|
95
|
+
with pytest.raises(ValueError) as excinfo:
|
96
|
+
ProgressbarConnections(slot="on_scan_progress", endpoint="non_existing")
|
97
|
+
errors = excinfo.value.errors()
|
98
|
+
assert len(errors) == 1
|
99
|
+
assert errors[0]["type"] == "unsupported endpoint"
|
100
|
+
assert (
|
101
|
+
"For slot 'on_scan_progress', endpoint must be MessageEndpoint.scan_progress or 'scans/scan_progress'."
|
102
|
+
in str(excinfo.value)
|
103
|
+
)
|
104
|
+
|
105
|
+
with pytest.raises(ValueError) as excinfo:
|
106
|
+
ProgressbarConnections(slot="on_device_readback", endpoint="non_existing")
|
107
|
+
errors = excinfo.value.errors()
|
108
|
+
assert len(errors) == 1
|
109
|
+
assert errors[0]["type"] == "unsupported endpoint"
|
110
|
+
assert (
|
111
|
+
"For slot 'on_device_readback', endpoint must be MessageEndpoint.device_readback(device) or 'internal/devices/readback/{device}'."
|
112
|
+
in str(excinfo.value)
|
113
|
+
)
|
114
|
+
|
115
|
+
|
116
|
+
def test_bar_add_number_of_bars(ring_progress_bar):
|
117
|
+
assert ring_progress_bar.config.num_bars == 1
|
118
|
+
|
119
|
+
ring_progress_bar.set_number_of_bars(5)
|
120
|
+
assert ring_progress_bar.config.num_bars == 5
|
121
|
+
|
122
|
+
ring_progress_bar.set_number_of_bars(2)
|
123
|
+
assert ring_progress_bar.config.num_bars == 2
|
124
|
+
|
125
|
+
|
126
|
+
def test_add_remove_bars_individually(ring_progress_bar):
|
127
|
+
ring_progress_bar.add_ring()
|
128
|
+
ring_progress_bar.add_ring()
|
129
|
+
|
130
|
+
assert ring_progress_bar.config.num_bars == 3
|
131
|
+
assert len(ring_progress_bar.config.rings) == 3
|
132
|
+
|
133
|
+
ring_progress_bar.remove_ring(1)
|
134
|
+
assert ring_progress_bar.config.num_bars == 2
|
135
|
+
assert len(ring_progress_bar.config.rings) == 2
|
136
|
+
assert ring_progress_bar.rings[0].config.index == 0
|
137
|
+
assert ring_progress_bar.rings[1].config.index == 1
|
138
|
+
|
139
|
+
|
140
|
+
def test_bar_set_value(ring_progress_bar):
|
141
|
+
ring_progress_bar.set_number_of_bars(5)
|
142
|
+
|
143
|
+
assert ring_progress_bar.config.num_bars == 5
|
144
|
+
assert len(ring_progress_bar.config.rings) == 5
|
145
|
+
assert len(ring_progress_bar.rings) == 5
|
146
|
+
|
147
|
+
ring_progress_bar.set_value([10, 20, 30, 40, 50])
|
148
|
+
ring_values = [ring.config.value for ring in ring_progress_bar.rings]
|
149
|
+
assert ring_values == [10, 20, 30, 40, 50]
|
150
|
+
|
151
|
+
# update just one bar
|
152
|
+
ring_progress_bar.set_value(90, 1)
|
153
|
+
ring_values = [ring.config.value for ring in ring_progress_bar.rings]
|
154
|
+
assert ring_values == [10, 90, 30, 40, 50]
|
155
|
+
|
156
|
+
|
157
|
+
def test_bar_set_precision(ring_progress_bar):
|
158
|
+
ring_progress_bar.set_number_of_bars(3)
|
159
|
+
|
160
|
+
assert ring_progress_bar.config.num_bars == 3
|
161
|
+
assert len(ring_progress_bar.config.rings) == 3
|
162
|
+
assert len(ring_progress_bar.rings) == 3
|
163
|
+
|
164
|
+
ring_progress_bar.set_precision(2)
|
165
|
+
ring_precision = [ring.config.precision for ring in ring_progress_bar.rings]
|
166
|
+
assert ring_precision == [2, 2, 2]
|
167
|
+
|
168
|
+
ring_progress_bar.set_value([10.1234, 20.1234, 30.1234])
|
169
|
+
ring_values = [ring.config.value for ring in ring_progress_bar.rings]
|
170
|
+
assert ring_values == [10.12, 20.12, 30.12]
|
171
|
+
|
172
|
+
ring_progress_bar.set_precision(4, 1)
|
173
|
+
ring_precision = [ring.config.precision for ring in ring_progress_bar.rings]
|
174
|
+
assert ring_precision == [2, 4, 2]
|
175
|
+
|
176
|
+
ring_progress_bar.set_value([10.1234, 20.1234, 30.1234])
|
177
|
+
ring_values = [ring.config.value for ring in ring_progress_bar.rings]
|
178
|
+
assert ring_values == [10.12, 20.1234, 30.12]
|
179
|
+
|
180
|
+
|
181
|
+
def test_set_min_max_value(ring_progress_bar):
|
182
|
+
ring_progress_bar.set_number_of_bars(2)
|
183
|
+
|
184
|
+
ring_progress_bar.set_min_max_values(0, 10)
|
185
|
+
ring_min_values = [ring.config.min_value for ring in ring_progress_bar.rings]
|
186
|
+
ring_max_values = [ring.config.max_value for ring in ring_progress_bar.rings]
|
187
|
+
|
188
|
+
assert ring_min_values == [0, 0]
|
189
|
+
assert ring_max_values == [10, 10]
|
190
|
+
|
191
|
+
ring_progress_bar.set_value([5, 15])
|
192
|
+
ring_values = [ring.config.value for ring in ring_progress_bar.rings]
|
193
|
+
assert ring_values == [5, 10]
|
194
|
+
|
195
|
+
|
196
|
+
def test_setup_colors_from_colormap(ring_progress_bar):
|
197
|
+
ring_progress_bar.set_number_of_bars(5)
|
198
|
+
ring_progress_bar.set_colors_from_map("viridis", "RGB")
|
199
|
+
|
200
|
+
expected_colors = Colors.golden_angle_color("viridis", 5, "RGB")
|
201
|
+
converted_colors = [ring.color.getRgb() for ring in ring_progress_bar.rings]
|
202
|
+
ring_config_colors = [ring.config.color for ring in ring_progress_bar.rings]
|
203
|
+
|
204
|
+
assert expected_colors == converted_colors
|
205
|
+
assert ring_config_colors == expected_colors
|
206
|
+
|
207
|
+
|
208
|
+
def get_colors_from_rings(rings):
|
209
|
+
converted_colors = [ring.color.getRgb() for ring in rings]
|
210
|
+
ring_config_colors = [ring.config.color for ring in rings]
|
211
|
+
return converted_colors, ring_config_colors
|
212
|
+
|
213
|
+
|
214
|
+
def test_set_colors_from_colormap_and_change_num_of_bars(ring_progress_bar):
|
215
|
+
ring_progress_bar.set_number_of_bars(2)
|
216
|
+
ring_progress_bar.set_colors_from_map("viridis", "RGB")
|
217
|
+
|
218
|
+
expected_colors = Colors.golden_angle_color("viridis", 2, "RGB")
|
219
|
+
converted_colors, ring_config_colors = get_colors_from_rings(ring_progress_bar.rings)
|
220
|
+
|
221
|
+
assert expected_colors == converted_colors
|
222
|
+
assert ring_config_colors == expected_colors
|
223
|
+
|
224
|
+
# increase the number of bars to 6
|
225
|
+
ring_progress_bar.set_number_of_bars(6)
|
226
|
+
expected_colors = Colors.golden_angle_color("viridis", 6, "RGB")
|
227
|
+
converted_colors, ring_config_colors = get_colors_from_rings(ring_progress_bar.rings)
|
228
|
+
|
229
|
+
assert expected_colors == converted_colors
|
230
|
+
assert ring_config_colors == expected_colors
|
231
|
+
|
232
|
+
# decrease the number of bars to 3
|
233
|
+
ring_progress_bar.set_number_of_bars(3)
|
234
|
+
expected_colors = Colors.golden_angle_color("viridis", 3, "RGB")
|
235
|
+
converted_colors, ring_config_colors = get_colors_from_rings(ring_progress_bar.rings)
|
236
|
+
|
237
|
+
assert expected_colors == converted_colors
|
238
|
+
assert ring_config_colors == expected_colors
|
239
|
+
|
240
|
+
|
241
|
+
def test_set_colors_directly(ring_progress_bar):
|
242
|
+
ring_progress_bar.set_number_of_bars(3)
|
243
|
+
|
244
|
+
# setting as a list of rgb tuples
|
245
|
+
colors = [(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255)]
|
246
|
+
ring_progress_bar.set_colors_directly(colors)
|
247
|
+
converted_colors = get_colors_from_rings(ring_progress_bar.rings)[0]
|
248
|
+
|
249
|
+
assert colors == converted_colors
|
250
|
+
|
251
|
+
ring_progress_bar.set_colors_directly((255, 0, 0, 255), 1)
|
252
|
+
converted_colors = get_colors_from_rings(ring_progress_bar.rings)[0]
|
253
|
+
|
254
|
+
assert converted_colors == [(255, 0, 0, 255), (255, 0, 0, 255), (0, 0, 255, 255)]
|
255
|
+
|
256
|
+
|
257
|
+
def test_set_line_width(ring_progress_bar):
|
258
|
+
ring_progress_bar.set_number_of_bars(3)
|
259
|
+
|
260
|
+
ring_progress_bar.set_line_widths(5)
|
261
|
+
line_widths = [ring.config.line_width for ring in ring_progress_bar.rings]
|
262
|
+
|
263
|
+
assert line_widths == [5, 5, 5]
|
264
|
+
|
265
|
+
ring_progress_bar.set_line_widths([10, 20, 30])
|
266
|
+
line_widths = [ring.config.line_width for ring in ring_progress_bar.rings]
|
267
|
+
|
268
|
+
assert line_widths == [10, 20, 30]
|
269
|
+
|
270
|
+
ring_progress_bar.set_line_widths(15, 1)
|
271
|
+
line_widths = [ring.config.line_width for ring in ring_progress_bar.rings]
|
272
|
+
|
273
|
+
assert line_widths == [10, 15, 30]
|
274
|
+
|
275
|
+
|
276
|
+
def test_set_gap(ring_progress_bar):
|
277
|
+
ring_progress_bar.set_number_of_bars(3)
|
278
|
+
ring_progress_bar.set_gap(20)
|
279
|
+
|
280
|
+
assert ring_progress_bar.config.gap == 20
|
281
|
+
|
282
|
+
|
283
|
+
def test_auto_update(ring_progress_bar):
|
284
|
+
ring_progress_bar.enable_auto_updates(True)
|
285
|
+
|
286
|
+
scan_queue_status_scan_progress = {
|
287
|
+
"queue": {
|
288
|
+
"primary": {
|
289
|
+
"info": [{"active_request_block": {"report_instructions": [{"scan_progress": 10}]}}]
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
meta = {}
|
294
|
+
|
295
|
+
ring_progress_bar.on_scan_queue_status(scan_queue_status_scan_progress, meta)
|
296
|
+
|
297
|
+
assert ring_progress_bar._auto_updates is True
|
298
|
+
assert len(ring_progress_bar._rings) == 1
|
299
|
+
assert ring_progress_bar._rings[0].config.connections == ProgressbarConnections(
|
300
|
+
slot="on_scan_progress", endpoint=MessageEndpoints.scan_progress()
|
301
|
+
)
|
302
|
+
|
303
|
+
scan_queue_status_device_readback = {
|
304
|
+
"queue": {
|
305
|
+
"primary": {
|
306
|
+
"info": [
|
307
|
+
{
|
308
|
+
"active_request_block": {
|
309
|
+
"report_instructions": [
|
310
|
+
{
|
311
|
+
"readback": {
|
312
|
+
"devices": ["samx", "samy"],
|
313
|
+
"start": [1, 2],
|
314
|
+
"end": [10, 20],
|
315
|
+
}
|
316
|
+
}
|
317
|
+
]
|
318
|
+
}
|
319
|
+
}
|
320
|
+
]
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
ring_progress_bar.on_scan_queue_status(scan_queue_status_device_readback, meta)
|
325
|
+
|
326
|
+
assert ring_progress_bar._auto_updates is True
|
327
|
+
assert len(ring_progress_bar._rings) == 2
|
328
|
+
assert ring_progress_bar._rings[0].config.connections == ProgressbarConnections(
|
329
|
+
slot="on_device_readback", endpoint=MessageEndpoints.device_readback("samx")
|
330
|
+
)
|
331
|
+
assert ring_progress_bar._rings[1].config.connections == ProgressbarConnections(
|
332
|
+
slot="on_device_readback", endpoint=MessageEndpoints.device_readback("samy")
|
333
|
+
)
|
334
|
+
|
335
|
+
assert ring_progress_bar._rings[0].config.min_value == 1
|
336
|
+
assert ring_progress_bar._rings[0].config.max_value == 10
|
337
|
+
assert ring_progress_bar._rings[1].config.min_value == 2
|
338
|
+
assert ring_progress_bar._rings[1].config.max_value == 20
|
@@ -4,4 +4,4 @@ from bec_widgets.cli.rpc_wigdet_handler import RPCWidgetHandler
|
|
4
4
|
def test_rpc_widget_handler():
|
5
5
|
handler = RPCWidgetHandler()
|
6
6
|
assert "BECFigure" in handler.widget_classes
|
7
|
-
assert "
|
7
|
+
assert "RingProgressBar" in handler.widget_classes
|
@@ -1 +0,0 @@
|
|
1
|
-
from .spiral_progress_bar import SpiralProgressBar
|