-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathtest_menu_commands.py
131 lines (102 loc) · 3.23 KB
/
test_menu_commands.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
# 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 TestMenu(unittest.TestCase):
def setUp(self):
self.root = support.get_tk_root()
support.root_deiconify()
xmldata = "test_menu_commands.ui"
self.builder = builder = pygubu.Builder()
filepath = os.path.dirname(os.path.realpath(__file__))
builder.add_resource_path(filepath)
builder.add_from_file(xmldata)
self.widget = builder.get_object("mainmenu")
self.menu1 = builder.get_object("menu1")
self.root["menu"] = self.widget
def tearDown(self):
support.root_withdraw()
self.root["menu"] = None
def test_tearoff_command(self):
success = []
class AnObject:
def on_menu_tearoff(self, menu, tearoff):
success.append(1)
def on_menu_post(self):
pass
def button1_cb(self):
pass
def chkbutton_cb(self, widget_id):
pass
cbobj = AnObject()
self.builder.connect_callbacks(cbobj)
# Simulate user clicking on tearoff menu
self.menu1.invoke(0)
self.widget.update()
# validate test
self.assertTrue(success)
self.widget.destroy()
def test_post_command(self):
success = []
class AnObject:
def on_menu_tearoff(self, menu, tearoff):
pass
def on_menu_post(self):
success.append(1)
def button1_cb(self):
pass
def chkbutton_cb(self, widget_id):
pass
cbobj = AnObject()
self.builder.connect_callbacks(cbobj)
# Simulate user clicking on menu
self.menu1.post(0, 0)
self.widget.update()
# validate test
self.assertTrue(success)
self.widget.destroy()
def test_button_command(self):
success = []
class AnObject:
def on_menu_tearoff(self, menu, tearoff):
pass
def on_menu_post(self):
pass
def button1_cb(self):
success.append(1)
def chkbutton_cb(self, widget_id):
pass
cbobj = AnObject()
self.builder.connect_callbacks(cbobj)
# Simulate user clicking on menu item
self.menu1.invoke(1)
self.widget.update()
# validate test
self.assertTrue(success)
self.widget.destroy()
def test_button_command_with_widget_id(self):
success = []
class AnObject:
def on_menu_tearoff(self, menu, tearoff):
pass
def on_menu_post(self):
pass
def button1_cb(self):
pass
def chkbutton_cb(self, widget_id):
success.append(widget_id)
cbobj = AnObject()
self.builder.connect_callbacks(cbobj)
# Simulate user clicking on menu item
self.menu1.invoke(2)
self.widget.update()
# validate test
self.assertTrue(success)
wid = success[0]
self.assertEqual(wid, "mchb1")
self.widget.destroy()