Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
tkinter.test.test_ttk.test_extensions.OptionMenuTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_widget_destroy
def test_initialization
def test_menu

Public Attributes

 textvar

Detailed Description

Definition at line 183 of file test_extensions.py.


Member Function Documentation

Definition at line 185 of file test_extensions.py.

00185 
00186     def setUp(self):
00187         support.root_deiconify()
00188         self.textvar = tkinter.StringVar()

Here is the caller graph for this function:

Definition at line 189 of file test_extensions.py.

00189 
00190     def tearDown(self):
00191         del self.textvar
00192         support.root_withdraw()
00193 

Here is the caller graph for this function:

Definition at line 205 of file test_extensions.py.

00205 
00206     def test_initialization(self):
00207         self.assertRaises(tkinter.TclError,
00208             ttk.OptionMenu, None, self.textvar, invalid='thing')
00209 
00210         optmenu = ttk.OptionMenu(None, self.textvar, 'b', 'a', 'b')
00211         self.assertEqual(optmenu._variable.get(), 'b')
00212 
00213         self.assertTrue(optmenu['menu'])
00214         self.assertTrue(optmenu['textvariable'])
00215 
00216         optmenu.destroy()
00217 

Here is the call graph for this function:

Definition at line 218 of file test_extensions.py.

00218 
00219     def test_menu(self):
00220         items = ('a', 'b', 'c')
00221         default = 'a'
00222         optmenu = ttk.OptionMenu(None, self.textvar, default, *items)
00223         found_default = False
00224         for i in range(len(items)):
00225             value = optmenu['menu'].entrycget(i, 'value')
00226             self.assertEqual(value, items[i])
00227             if value == default:
00228                 found_default = True
00229         self.assertTrue(found_default)
00230         optmenu.destroy()
00231 
00232         # default shouldn't be in menu if it is not part of values
00233         default = 'd'
00234         optmenu = ttk.OptionMenu(None, self.textvar, default, *items)
00235         curr = None
00236         i = 0
00237         while True:
00238             last, curr = curr, optmenu['menu'].entryconfigure(i, 'value')
00239             if last == curr:
00240                 # no more menu entries
00241                 break
00242             self.assertFalse(curr == default)
00243             i += 1
00244         self.assertEqual(i, len(items))
00245 
00246         # check that variable is updated correctly
00247         optmenu.pack()
00248         optmenu.wait_visibility()
00249         optmenu['menu'].invoke(0)
00250         self.assertEqual(optmenu._variable.get(), items[0])
00251 
00252         # changing to an invalid index shouldn't change the variable
00253         self.assertRaises(tkinter.TclError, optmenu['menu'].invoke, -1)
00254         self.assertEqual(optmenu._variable.get(), items[0])
00255 
00256         optmenu.destroy()
00257 
00258         # specifying a callback
00259         success = []
00260         def cb_test(item):
00261             self.assertEqual(item, items[1])
00262             success.append(True)
00263         optmenu = ttk.OptionMenu(None, self.textvar, 'a', command=cb_test,
00264             *items)
00265         optmenu['menu'].invoke(1)
00266         if not success:
00267             self.fail("Menu callback not invoked")
00268 
00269         optmenu.destroy()
00270 

Here is the call graph for this function:

Definition at line 194 of file test_extensions.py.

00194 
00195     def test_widget_destroy(self):
00196         var = tkinter.StringVar()
00197         optmenu = ttk.OptionMenu(None, var)
00198         name = var._name
00199         optmenu.update_idletasks()
00200         optmenu.destroy()
00201         self.assertEqual(optmenu.tk.globalgetvar(name), var.get())
00202         del var
00203         self.assertRaises(tkinter.TclError, optmenu.tk.globalgetvar, name)
00204 

Here is the call graph for this function:


Member Data Documentation

Definition at line 187 of file test_extensions.py.


The documentation for this class was generated from the following file: