File: test_checkbox.py

package info (click to toggle)
python-guizero 1.1.1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,676 kB
  • sloc: python: 6,286; makefile: 28; sh: 17
file content (226 lines) | stat: -rw-r--r-- 4,282 bytes parent folder | download | duplicates (3)
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
from threading import Event
from guizero import App, CheckBox
from common_test import (
    schedule_after_test,
    schedule_repeat_test,
    destroy_test,
    enable_test,
    display_test,
    text_test,
    color_test,
    size_text_test,
    size_fill_test,
    events_test,
    cascaded_properties_test,
    inherited_properties_test,
    grid_layout_test,
    auto_layout_test
    )

def test_default_values():
    a = App()
    c = CheckBox(a, "foo")
    assert c.master == a
    assert c.text == "foo"
    assert c.grid == None
    assert c.align == None
    assert a.description > ""
    a.destroy()

def test_alt_values():
    a = App(layout = "grid")
    c = CheckBox(
        a,
        text = "foo",
        grid = [0,1],
        align = "top",
        width = 10,
        height = 11)

    assert c.text == "foo"
    assert c.grid[0] == 0
    assert c.grid[1] == 1
    assert c.align == "top"
    assert c.width == 10
    assert c.height == 11
    a.destroy()

def test_getters_setters():
    a = App()
    c = CheckBox(a, "foo")

    assert c.text == "foo"
    c.text = "bar"
    assert c.text == "bar"

    assert not c.value
    c.value = True
    assert c.value

    a.destroy()

def test_command():
    a = App()

    callback_event = Event()
    def callback():
        callback_event.set()

    c = CheckBox(a, "foo", command = callback)
    assert not callback_event.is_set()
    c.tk.invoke()
    assert callback_event.is_set()

    a.destroy()

def test_command_with_args():
    a = App()

    callback_event = Event()
    def callback(value):
        assert value == "foo"
        callback_event.set()

    c = CheckBox(a, "foo", command = callback, args = ["foo"])

    c.tk.invoke()
    assert callback_event.is_set()

    a.destroy()

def test_update_command():
    a = App()

    callback_event = Event()
    def callback():
        callback_event.set()

    c = CheckBox(a, "foo")

    c.tk.invoke()
    assert not callback_event.is_set()

    c.update_command(callback)
    c.tk.invoke()
    assert callback_event.is_set()
    callback_event.clear()

    c.update_command(None)
    c.tk.invoke()
    assert not callback_event.is_set()

    a.destroy()

def test_update_command_with_args():
    a = App()

    callback_event = Event()
    def callback(value):
        assert value == "foo"
        callback_event.set()

    c = CheckBox(a, "foo")

    c.update_command(callback, ["foo"])
    c.tk.invoke()
    assert callback_event.is_set()

    a.destroy()

def test_toggle():
    a = App()
    c = CheckBox(a, "foo")

    assert not c.value
    c.toggle()
    assert c.value
    c.toggle()
    assert not c.value

    a.destroy()

def test_after_schedule():
    a = App()
    c = CheckBox(a, "foo")
    schedule_after_test(a, c)
    a.destroy()

def test_repeat_schedule():
    a = App()
    c = CheckBox(a, "foo")
    schedule_repeat_test(a, c)
    a.destroy()

def test_destroy():
    a = App()
    c = CheckBox(a, "foo")
    destroy_test(c)
    a.destroy()

def test_enable():
    a = App()
    c = CheckBox(a, "foo")
    enable_test(c)
    a.destroy()

def test_display():
    a = App()
    c = CheckBox(a, "foo")
    display_test(c)
    a.destroy()

def test_text():
    a = App()
    c = CheckBox(a, "foo")
    text_test(c)
    a.destroy()

def test_color():
    a = App()
    c = CheckBox(a, "foo")
    color_test(c)
    a.destroy()

def test_size():
    a = App()
    c = CheckBox(a, "foo")
    size_text_test(c)
    size_fill_test(c)
    a.destroy()

def test_events():
    a = App()
    c = CheckBox(a, "foo")
    events_test(c)
    a.destroy()

def test_cascaded_properties():
    a = App()
    c = CheckBox(a, "foo")
    cascaded_properties_test(a, c, True)
    a.destroy()

def test_inherited_properties():
    a = App()
    inherited_properties_test(a, lambda: CheckBox(a, "foo"), True)
    a.destroy()

def test_auto_layout():
    a = App()
    w = CheckBox(a)
    auto_layout_test(w, None)
    a.destroy()

def test_grid_layout():
    a = App(layout="grid")
    
    w = CheckBox(a, grid=[1,2])
    grid_layout_test(w, 1, 2, 1, 1, None)
    
    ws = CheckBox(a, grid=[1,2,3,4])
    grid_layout_test(ws, 1, 2, 3, 4, None)

    wa = CheckBox(a, grid=[1,2], align="top")
    grid_layout_test(wa, 1, 2, 1, 1, "top")
    
    a.destroy()