-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathtest_frame.py
160 lines (125 loc) · 4.11 KB
/
test_frame.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
# encoding: utf-8
import os
import sys
import unittest
import tkinter as tk
import tkinter.ttk as ttk
import fixpath
import pygubu
import support
class TestFrame(unittest.TestCase):
def setUp(self):
support.root_deiconify()
xmldata = "test_frame.ui"
self.builder = builder = pygubu.Builder()
builder.add_from_file(xmldata)
self.widget = builder.get_object("mainwindow")
def tearDown(self):
support.root_withdraw()
def test_class(self):
self.assertIsInstance(self.widget, ttk.Frame)
self.widget.destroy()
def test_padding(self):
tclobj = self.widget.cget("padding")[0]
padding = str(tclobj)
self.assertEqual("10", padding)
self.widget.destroy()
def test_width(self):
tclobj = self.widget.cget("width")
width = str(tclobj)
self.assertEqual("250", width)
self.widget.destroy()
def test_class_(self):
tclobj = self.widget.cget("class")
class_ = str(tclobj)
self.assertEqual("MyCustomFrame", class_)
self.widget.destroy()
def test_relief(self):
tclobj = self.widget.cget("relief")
relief = str(tclobj)
self.assertEqual(tk.SUNKEN, relief)
self.widget.destroy()
def test_style(self):
tclobj = self.widget.cget("style")
style = str(tclobj)
self.assertEqual("MyFrameStyle.TFrame", style)
self.widget.destroy()
def test_takefocus(self):
tclobj = self.widget.cget("takefocus")
takefocus = str(tclobj)
self.assertEqual("1", takefocus)
self.widget.destroy()
def test_cursor(self):
tclobj = self.widget.cget("cursor")
cursor = str(tclobj)
self.assertEqual("cross", cursor)
self.widget.destroy()
def test_layout(self):
ginfo = self.widget.grid_info()
expected = [
("row", "0"),
("column", "0"),
("sticky", "nesw"),
("pady", "10"),
("padx", "5"),
("ipadx", "2"),
("ipady", "4"),
("rowspan", "1"),
("columnspan", "2"),
]
for k, ev in expected:
value = str(ginfo[k])
self.assertEqual(value, ev)
# FIX TEST: since interface v1.1 propagate is applied to parent? NO!
propagate = self.widget.grid_propagate()
self.assertEqual(None, propagate)
self.widget.destroy()
def test_child_count(self):
count = len(self.widget.children)
self.assertEqual(1, count)
self.widget.destroy()
def test_binding_dict(self):
success = []
def on_button_click(event):
success.append(1)
def on_button_click2(event):
success.append(1)
cbdic = {
"on_button_click": on_button_click,
"on_button_click2": on_button_click2,
}
self.builder.connect_callbacks(cbdic)
support.simulate_mouse_click(self.widget, 5, 5)
self.widget.update_idletasks()
self.assertTrue(success)
self.widget.destroy()
def test_binding_object(self):
success = []
class AnObject:
def on_button_click(self, event):
success.append(1)
def on_button_click2(self, event):
success.append(1)
cbobj = AnObject()
self.builder.connect_callbacks(cbobj)
support.simulate_mouse_click(self.widget, 5, 5)
self.widget.update_idletasks()
self.assertTrue(success)
self.widget.destroy()
def test_binding_add(self):
success = []
def on_button_click(event):
success.append(1)
def on_button_click2(event):
success.append(1)
cbdic = {
"on_button_click": on_button_click,
"on_button_click2": on_button_click2,
}
self.builder.connect_callbacks(cbdic)
support.simulate_mouse_click(self.widget, 5, 5)
self.widget.update_idletasks()
self.assertTrue(len(success) == 2)
self.widget.destroy()
if __name__ == "__main__":
unittest.main()