diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-07 17:27:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-07 17:27:42 (GMT) |
commit | a21acb5d95841e7d2c8491f40189a853cb7b5df4 (patch) | |
tree | 10b5b71cb87b5edb5eefc48b08b3abc912b6a5ed /Lib/tkinter/test/test_ttk | |
parent | 0455c3fd28256940ad02ac39335816c1bdab0af9 (diff) | |
download | cpython-a21acb5d95841e7d2c8491f40189a853cb7b5df4.zip cpython-a21acb5d95841e7d2c8491f40189a853cb7b5df4.tar.gz cpython-a21acb5d95841e7d2c8491f40189a853cb7b5df4.tar.bz2 |
Issue #20072: Fixed multiple errors in tkinter with wantobjects is False.
* Misc.image_names(), Misc.image_types(), Wm.wm_colormapwindows(), and
LabelFrame.panes() now always return a tuple.
* Fixed error of comparing str and int in tt.LabeledScale._adjust().
* ttk.Notebook.index() now always returns int.
* ttk.Notebook.tabs() now always returns a tuple.
* ttk.Entry.bbox() now always returns a tuple of ints.
* ttk.Entry.validate() now always correctly works.
* ttk.Combobox.current() now always returns int.
* ttk.Panedwindow.sashpos() now always returns int.
* ttk.Treeview.bbox() now always returns a tuple of ints.
* ttk.Treeview.get_children() now always returns a tuple.
* ttk.Treeview.exists() now always correctly works.
* ttk.Treeview.index() now always returns int.
* ttk.Treeview.tag_has() now always returns 0 or 1.
* And numerous other errors in methods which returns a tuple, list or dict.
* Fixed ttk tests for wantobjects is False.
Diffstat (limited to 'Lib/tkinter/test/test_ttk')
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_extensions.py | 22 | ||||
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_functions.py | 6 | ||||
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_style.py | 3 | ||||
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_widgets.py | 113 |
4 files changed, 99 insertions, 45 deletions
diff --git a/Lib/tkinter/test/test_ttk/test_extensions.py b/Lib/tkinter/test/test_ttk/test_extensions.py index 0bd8c92..d699546 100644 --- a/Lib/tkinter/test/test_ttk/test_extensions.py +++ b/Lib/tkinter/test/test_ttk/test_extensions.py @@ -29,7 +29,10 @@ class LabeledScaleTest(unittest.TestCase): name = myvar._name x = ttk.LabeledScale(variable=myvar) x.destroy() - self.assertEqual(x.tk.globalgetvar(name), myvar.get()) + if x.tk.wantobjects(): + self.assertEqual(x.tk.globalgetvar(name), myvar.get()) + else: + self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get()) del myvar self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name) @@ -59,8 +62,10 @@ class LabeledScaleTest(unittest.TestCase): x.destroy() # variable initialization/passing - passed_expected = ((2.5, 2), ('0', 0), (0, 0), (10, 10), + passed_expected = (('0', 0), (0, 0), (10, 10), (-1, -1), (sys.maxsize + 1, sys.maxsize + 1)) + if x.tk.wantobjects(): + passed_expected += ((2.5, 2),) for pair in passed_expected: x = ttk.LabeledScale(from_=pair[0]) self.assertEqual(x.value, pair[1]) @@ -123,7 +128,7 @@ class LabeledScaleTest(unittest.TestCase): self.assertNotEqual(prev_xcoord, curr_xcoord) # the label widget should have been repositioned too linfo_2 = lscale.label.place_info() - self.assertEqual(lscale.label['text'], 0) + self.assertEqual(lscale.label['text'], 0 if lscale.tk.wantobjects() else '0') self.assertEqual(curr_xcoord, int(linfo_2['x'])) # change the range back lscale.scale.configure(from_=0, to=10) @@ -145,15 +150,20 @@ class LabeledScaleTest(unittest.TestCase): # The following update is needed since the test doesn't use mainloop, # at the same time this shouldn't affect test outcome x.update() - self.assertEqual(x.label['text'], newval) + self.assertEqual(x.label['text'], + newval if x.tk.wantobjects() else str(newval)) self.assertGreater(x.scale.coords()[0], curr_xcoord) self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x'])) # value outside range - x.value = x.scale['to'] + 1 # no changes shouldn't happen + if x.tk.wantobjects(): + conv = lambda x: x + else: + conv = int + x.value = conv(x.scale['to']) + 1 # no changes shouldn't happen x.update() - self.assertEqual(x.label['text'], newval) + self.assertEqual(conv(x.label['text']), newval) self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x'])) diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py index 0d8df16..1986e66 100644 --- a/Lib/tkinter/test/test_ttk/test_functions.py +++ b/Lib/tkinter/test/test_ttk/test_functions.py @@ -393,8 +393,10 @@ class InternalFunctionsTest(unittest.TestCase): ('name', 'no_minus', 'value')) self.assertRaises(ValueError, ttk._list_from_layouttuple, ('something', '-children')) # no children - self.assertRaises(ValueError, ttk._list_from_layouttuple, - ('something', '-children', 'value')) # invalid children + import tkinter + if not tkinter._default_root or tkinter._default_root.wantobjects(): + self.assertRaises(ValueError, ttk._list_from_layouttuple, + ('something', '-children', 'value')) # invalid children def test_val_or_dict(self): diff --git a/Lib/tkinter/test/test_ttk/test_style.py b/Lib/tkinter/test/test_ttk/test_style.py index 2466c73..0da0e5d 100644 --- a/Lib/tkinter/test/test_ttk/test_style.py +++ b/Lib/tkinter/test/test_ttk/test_style.py @@ -25,7 +25,8 @@ class StyleTest(unittest.TestCase): style = self.style style.map('TButton', background=[('active', 'background', 'blue')]) self.assertEqual(style.map('TButton', 'background'), - [('active', 'background', 'blue')]) + [('active', 'background', 'blue')] if style.tk.wantobjects() else + [('active background', 'blue')]) self.assertIsInstance(style.map('TButton'), dict) diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py index 0035214..492e7ad 100644 --- a/Lib/tkinter/test/test_ttk/test_widgets.py +++ b/Lib/tkinter/test/test_ttk/test_widgets.py @@ -382,15 +382,21 @@ class ComboboxTest(AbstractWidgetTest, unittest.TestCase): # testing values with empty string set through configure self.combo.configure(values=[1, '', 2]) - self.assertEqual(self.combo['values'], ('1', '', '2')) + self.assertEqual(self.combo['values'], + ('1', '', '2') if self.wantobjects else + '1 {} 2') # testing values with spaces self.combo['values'] = ['a b', 'a\tb', 'a\nb'] - self.assertEqual(self.combo['values'], ('a b', 'a\tb', 'a\nb')) + self.assertEqual(self.combo['values'], + ('a b', 'a\tb', 'a\nb') if self.wantobjects else + '{a b} {a\tb} {a\nb}') # testing values with special characters self.combo['values'] = [r'a\tb', '"a"', '} {'] - self.assertEqual(self.combo['values'], (r'a\tb', '"a"', '} {')) + self.assertEqual(self.combo['values'], + (r'a\tb', '"a"', '} {') if self.wantobjects else + r'a\\tb {"a"} \}\ \{') # out of range self.assertRaises(tkinter.TclError, self.combo.current, @@ -400,7 +406,8 @@ class ComboboxTest(AbstractWidgetTest, unittest.TestCase): # testing creating combobox with empty string in values combo2 = ttk.Combobox(values=[1, 2, '']) - self.assertEqual(combo2['values'], ('1', '2', '')) + self.assertEqual(combo2['values'], + ('1', '2', '') if self.wantobjects else '1 2 {}') combo2.destroy() @@ -654,9 +661,11 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase): child = ttk.Label() self.paned.add(child) self.assertIsInstance(self.paned.pane(0), dict) - self.assertEqual(self.paned.pane(0, weight=None), 0) + self.assertEqual(self.paned.pane(0, weight=None), + 0 if self.wantobjects else '0') # newer form for querying a single option - self.assertEqual(self.paned.pane(0, 'weight'), 0) + self.assertEqual(self.paned.pane(0, 'weight'), + 0 if self.wantobjects else '0') self.assertEqual(self.paned.pane(0), self.paned.pane(str(child))) self.assertRaises(tkinter.TclError, self.paned.pane, 0, @@ -711,20 +720,25 @@ class RadiobuttonTest(AbstractLabelTest, unittest.TestCase): cbtn = ttk.Radiobutton(command=cb_test, variable=myvar, value=0) cbtn2 = ttk.Radiobutton(command=cb_test, variable=myvar, value=1) + if self.wantobjects: + conv = lambda x: x + else: + conv = int + res = cbtn.invoke() self.assertEqual(res, "cb test called") - self.assertEqual(cbtn['value'], myvar.get()) + self.assertEqual(conv(cbtn['value']), myvar.get()) self.assertEqual(myvar.get(), - cbtn.tk.globalgetvar(cbtn['variable'])) + conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertTrue(success) cbtn2['command'] = '' res = cbtn2.invoke() self.assertEqual(str(res), '') self.assertLessEqual(len(success), 1) - self.assertEqual(cbtn2['value'], myvar.get()) + self.assertEqual(conv(cbtn2['value']), myvar.get()) self.assertEqual(myvar.get(), - cbtn.tk.globalgetvar(cbtn['variable'])) + conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertEqual(str(cbtn['variable']), str(cbtn2['variable'])) @@ -812,10 +826,15 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase): def test_get(self): + if self.wantobjects: + conv = lambda x: x + else: + conv = float + scale_width = self.scale.winfo_width() self.assertEqual(self.scale.get(scale_width, 0), self.scale['to']) - self.assertEqual(self.scale.get(0, 0), self.scale['from']) + self.assertEqual(conv(self.scale.get(0, 0)), conv(self.scale['from'])) self.assertEqual(self.scale.get(), self.scale['value']) self.scale['value'] = 30 self.assertEqual(self.scale.get(), self.scale['value']) @@ -825,32 +844,37 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase): def test_set(self): + if self.wantobjects: + conv = lambda x: x + else: + conv = float + # set restricts the max/min values according to the current range - max = self.scale['to'] + max = conv(self.scale['to']) new_max = max + 10 self.scale.set(new_max) - self.assertEqual(self.scale.get(), max) - min = self.scale['from'] + self.assertEqual(conv(self.scale.get()), max) + min = conv(self.scale['from']) self.scale.set(min - 1) - self.assertEqual(self.scale.get(), min) + self.assertEqual(conv(self.scale.get()), min) # changing directly the variable doesn't impose this limitation tho var = tkinter.DoubleVar() self.scale['variable'] = var var.set(max + 5) - self.assertEqual(self.scale.get(), var.get()) - self.assertEqual(self.scale.get(), max + 5) + self.assertEqual(conv(self.scale.get()), var.get()) + self.assertEqual(conv(self.scale.get()), max + 5) del var # the same happens with the value option self.scale['value'] = max + 10 - self.assertEqual(self.scale.get(), max + 10) - self.assertEqual(self.scale.get(), self.scale['value']) + self.assertEqual(conv(self.scale.get()), max + 10) + self.assertEqual(conv(self.scale.get()), conv(self.scale['value'])) # nevertheless, note that the max/min values we can get specifying # x, y coords are the ones according to the current range - self.assertEqual(self.scale.get(0, 0), min) - self.assertEqual(self.scale.get(self.scale.winfo_width(), 0), max) + self.assertEqual(conv(self.scale.get(0, 0)), min) + self.assertEqual(conv(self.scale.get(self.scale.winfo_width(), 0)), max) self.assertRaises(tkinter.TclError, self.scale.set, None) @@ -1204,6 +1228,8 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): self.tv.column('test', width=50) bbox_column0 = self.tv.bbox(children[0], 0) root_width = self.tv.column('#0', width=None) + if not self.wantobjects: + root_width = int(root_width) self.assertEqual(bbox_column0[0], bbox[0] + root_width) # verify that bbox of a closed item is the empty string @@ -1243,12 +1269,15 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): # return a dict with all options/values self.assertIsInstance(self.tv.column('#0'), dict) # return a single value of the given option - self.assertIsInstance(self.tv.column('#0', width=None), int) + if self.wantobjects: + self.assertIsInstance(self.tv.column('#0', width=None), int) # set a new value for an option self.tv.column('#0', width=10) # testing new way to get option value - self.assertEqual(self.tv.column('#0', 'width'), 10) - self.assertEqual(self.tv.column('#0', width=None), 10) + self.assertEqual(self.tv.column('#0', 'width'), + 10 if self.wantobjects else '10') + self.assertEqual(self.tv.column('#0', width=None), + 10 if self.wantobjects else '10') # check read-only option self.assertRaises(tkinter.TclError, self.tv.column, '#0', id='X') @@ -1461,11 +1490,14 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): # unicode values value = '\xe1ba' item = self.tv.insert('', 'end', values=(value, )) - self.assertEqual(self.tv.item(item, 'values'), (value, )) - self.assertEqual(self.tv.item(item, values=None), (value, )) + self.assertEqual(self.tv.item(item, 'values'), + (value,) if self.wantobjects else value) + self.assertEqual(self.tv.item(item, values=None), + (value,) if self.wantobjects else value) - self.tv.item(item, values=list(self.tv.item(item, values=None))) - self.assertEqual(self.tv.item(item, values=None), (value, )) + self.tv.item(item, values=self.root.splitlist(self.tv.item(item, values=None))) + self.assertEqual(self.tv.item(item, values=None), + (value,) if self.wantobjects else value) self.assertIsInstance(self.tv.item(item), dict) @@ -1475,17 +1507,21 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): # item tags item = self.tv.insert('', 'end', tags=[1, 2, value]) - self.assertEqual(self.tv.item(item, tags=None), ('1', '2', value)) + self.assertEqual(self.tv.item(item, tags=None), + ('1', '2', value) if self.wantobjects else + '1 2 %s' % value) self.tv.item(item, tags=[]) self.assertFalse(self.tv.item(item, tags=None)) self.tv.item(item, tags=(1, 2)) - self.assertEqual(self.tv.item(item, tags=None), ('1', '2')) + self.assertEqual(self.tv.item(item, tags=None), + ('1', '2') if self.wantobjects else '1 2') # values with spaces item = self.tv.insert('', 'end', values=('a b c', '%s %s' % (value, value))) self.assertEqual(self.tv.item(item, values=None), - ('a b c', '%s %s' % (value, value))) + ('a b c', '%s %s' % (value, value)) if self.wantobjects else + '{a b c} {%s %s}' % (value, value)) # text self.assertEqual(self.tv.item( @@ -1502,19 +1538,24 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): self.assertEqual(self.tv.set(item), {'A': 'a', 'B': 'b'}) self.tv.set(item, 'B', 'a') - self.assertEqual(self.tv.item(item, values=None), ('a', 'a')) + self.assertEqual(self.tv.item(item, values=None), + ('a', 'a') if self.wantobjects else 'a a') self.tv['columns'] = ['B'] self.assertEqual(self.tv.set(item), {'B': 'a'}) self.tv.set(item, 'B', 'b') self.assertEqual(self.tv.set(item, column='B'), 'b') - self.assertEqual(self.tv.item(item, values=None), ('b', 'a')) + self.assertEqual(self.tv.item(item, values=None), + ('b', 'a') if self.wantobjects else 'b a') self.tv.set(item, 'B', 123) - self.assertEqual(self.tv.set(item, 'B'), 123) - self.assertEqual(self.tv.item(item, values=None), (123, 'a')) - self.assertEqual(self.tv.set(item), {'B': 123}) + self.assertEqual(self.tv.set(item, 'B'), + 123 if self.wantobjects else '123') + self.assertEqual(self.tv.item(item, values=None), + (123, 'a') if self.wantobjects else '123 a') + self.assertEqual(self.tv.set(item), + {'B': 123} if self.wantobjects else {'B': '123'}) # inexistent column self.assertRaises(tkinter.TclError, self.tv.set, item, 'A') |