forked from epic-open-source/seismometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_selection.py
264 lines (235 loc) · 9.78 KB
/
test_selection.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import pytest
import seismometer.controls.selection as undertest
class TestSelectionListWidget:
def test_init(self):
widget = undertest.SelectionListWidget(options=["a", "b", "c"], value=["a", "b"], title="title")
assert widget.title_label.value == "title"
assert widget.value == (
"a",
"b",
)
def test_init_no_value(self):
widget = undertest.SelectionListWidget(options=["a", "b", "c"])
assert widget.title_label is None
assert widget.value == ()
def test_value_propagation(self):
widget = undertest.SelectionListWidget(options=["a", "b", "c"])
widget.value = (
"a",
"b",
)
assert widget.button_from_option["a"].value is True
assert widget.button_from_option["b"].value is True
assert widget.button_from_option["c"].value is False
def test_display_text(self):
widget = undertest.SelectionListWidget(options=["a", "b", "c"], title="test_title")
widget.value = (
"a",
"b",
)
assert widget.get_selection_text() == "test_title: a, b"
def test_disabled(self):
widget = undertest.SelectionListWidget(options=["a", "b", "c"])
assert not widget.disabled
widget.disabled = True
assert widget.disabled
assert widget.button_from_option["a"].disabled
assert widget.button_from_option["b"].disabled
assert widget.button_from_option["c"].disabled
widget.disabled = False
assert not widget.disabled
assert not widget.button_from_option["a"].disabled
assert not widget.button_from_option["b"].disabled
assert not widget.button_from_option["c"].disabled
@pytest.mark.parametrize("show_all", [True, False])
class TestMultiSelectionListWidget:
def test_init(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"]},
values={"a": ["a", "b"], "b": ["c"]},
title="title",
border=True,
show_all=show_all,
)
assert widget.title == "title"
assert widget.value == {"a": ("a", "b"), "b": ("c",)}
def test_init_no_value(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"]},
show_all=show_all,
)
assert widget.value == {}
def test_value_propagation(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"], "d": ["a", "b", "c"]},
show_all=show_all,
)
assert widget.value == {}
widget.value = {"a": ("a", "b"), "b": ("c",)}
assert widget.selection_widgets["a"].value == ("a", "b")
assert widget.selection_widgets["b"].value == ("c",)
assert widget.selection_widgets["d"].value == ()
def test_on_subselection_changed(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"], "d": ["a", "b", "c"]},
show_all=show_all,
)
assert widget.value == {}
widget.selection_widgets["a"].value = ("a", "b")
assert widget.value == {"a": ("a", "b")}
assert widget.selection_widgets["b"].value == ()
assert widget.selection_widgets["d"].value == ()
def test_display_text(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"], "d": ["a", "b", "c"]},
show_all=show_all,
)
assert widget.value == {}
assert widget.get_selection_text() == ""
widget.value = {"a": ("a", "b"), "b": ("c",)}
assert widget.get_selection_text() == "a: a, b\nb: c"
def test_disabled(self, show_all):
widget = undertest.MultiSelectionListWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"], "d": ["a", "b", "c"]},
show_all=show_all,
)
assert not widget.disabled
widget.disabled = True
assert widget.disabled
assert widget.selection_widgets["a"].disabled
assert widget.selection_widgets["b"].disabled
assert widget.selection_widgets["d"].disabled
widget.disabled = False
assert not widget.disabled
assert not widget.selection_widgets["a"].disabled
assert not widget.selection_widgets["b"].disabled
assert not widget.selection_widgets["d"].disabled
class TestDisjointSelectionListsWidget:
def test_init(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"]},
value=("a", ["a", "b"]),
title="title",
)
assert widget.title == "title"
assert widget.value == ("a", ("a", "b"))
assert len(widget.selection_widgets) == 2
assert widget.selection_widgets["a"].value == ("a", "b")
assert widget.selection_widgets["b"].value == (
"a",
"c",
)
def test_init_no_value(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"]},
title="title",
)
assert widget.title == "title"
assert widget.value == ("a", ("a", "b", "c"))
assert len(widget.selection_widgets) == 2
assert widget.selection_widgets["a"].value == ("a", "b", "c")
assert widget.selection_widgets["b"].value == (
"a",
"c",
)
def test_value_change(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a", "b", "c"], "b": ["a", "c"]},
value=("a", ["a", "b"]),
title="title",
)
assert widget.value == ("a", ("a", "b"))
widget.value = ("b", ("c",))
assert widget.selection_widgets["a"].value == ("a", "b")
assert widget.selection_widgets["b"].value == ("c",)
assert widget.value == ("b", ("c",))
def test_display_text(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a1", "a2", "a3"], "b": ["b1", "b2"]},
value=("a", ["a1", "a3"]),
title="title",
)
assert widget.get_selection_text() == "a: a1, a3"
def test_disabled(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a1", "a2", "a3"], "b": ["b1", "b2"]},
value=("a", ["a1", "a3"]),
title="title",
)
assert not widget.disabled
widget.disabled = True
assert widget.disabled
assert widget.dropdown.disabled
assert widget.selection_widgets["a"].disabled
assert widget.selection_widgets["b"].disabled
widget.disabled = False
assert not widget.disabled
assert not widget.dropdown.disabled
assert not widget.selection_widgets["a"].disabled
assert not widget.selection_widgets["b"].disabled
def test_disable_dropdown_only_one_group(self):
widget = undertest.DisjointSelectionListsWidget(
options={"a": ["a1", "a2", "a3"]},
value=("a", ["a1", "a2"]),
title="title",
)
assert not widget.disabled
widget.disabled = True
assert widget.disabled
assert widget.dropdown.disabled
assert widget.selection_widgets["a"].disabled
widget.disabled = False
assert not widget.disabled
assert widget.dropdown.disabled
assert not widget.selection_widgets["a"].disabled
class TestMultiselectDropdownWidget:
def test_init(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"], value=["a", "b"], title="title")
assert widget.title == "title"
assert widget.value == ("a", "b")
assert widget.get_selection_text() == "title: a, b"
def test_init_no_value(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"])
assert widget.title is None
assert widget.value == ()
assert widget.get_selection_text() == ""
def test_add_all(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"])
widget.dropdown.value = -1
assert widget.value == ("a", "b", "c")
assert widget.dropdown.value == -2 # reset to default
def test_value_propagation(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"])
widget.value = ("a", "b")
assert len(widget.selection_options.children) == 2
assert widget.selection_options.children[0].description == "a"
assert widget.selection_options.children[1].description == "b"
def test_value_propagation_remove_option(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"], value=["a", "b"], title="title")
assert widget.title == "title"
widget.selection_options.children[0].click()
assert widget.value == ("b",)
def test_dropdown_changes_value(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"])
widget.dropdown.value = 1 # index of b
assert widget.value == ("b",)
widget.dropdown.value = 2 # index of c
assert widget.value == (
"b",
"c",
)
widget.dropdown.value = 0 # index of a
assert widget.value == (
"a",
"b",
"c",
)
def test_disabled(self):
widget = undertest.MultiselectDropdownWidget(options=["a", "b", "c"])
assert not widget.disabled
widget.disabled = True
assert widget.disabled
assert widget.dropdown.disabled
widget.disabled = False
assert not widget.disabled
assert not widget.dropdown.disabled