diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2017-02-04 09:18:42 +0300 |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2017-02-04 09:18:42 +0300 |
commit | 678487eb345f9f9dea3d3818ecad7d39145bdc65 (patch) | |
tree | 35c1a98d1ceadc6b67bf7119031d2a89f27f1cb1 /Lib/tkinter/test | |
parent | 50a3761c130e9be725bacb5b99d624012c40414a (diff) | |
parent | 19d8ebcbbd396ec603ed03bc79add9b049c31919 (diff) | |
download | cpython-678487eb345f9f9dea3d3818ecad7d39145bdc65.tar.gz |
Issue #29198: Merge from 3.5
Diffstat (limited to 'Lib/tkinter/test')
-rw-r--r-- | Lib/tkinter/test/runtktests.py | 2 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_misc.py | 8 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_variables.py | 52 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_widgets.py | 7 | ||||
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_functions.py | 1 | ||||
-rw-r--r-- | Lib/tkinter/test/test_ttk/test_widgets.py | 49 |
6 files changed, 108 insertions, 11 deletions
diff --git a/Lib/tkinter/test/runtktests.py b/Lib/tkinter/test/runtktests.py index dbe5e88c14..33dc54a137 100644 --- a/Lib/tkinter/test/runtktests.py +++ b/Lib/tkinter/test/runtktests.py @@ -7,8 +7,6 @@ Extensions also should live in packages following the same rule as above. """ import os -import sys -import unittest import importlib import test.support diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index 85ee2c70b1..9dc1e37547 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -12,6 +12,14 @@ class MiscTest(AbstractTkTest, unittest.TestCase): f = tkinter.Frame(t, name='child') self.assertEqual(repr(f), '<tkinter.Frame object .top.child>') + def test_generated_names(self): + t = tkinter.Toplevel(self.root) + f = tkinter.Frame(t) + f2 = tkinter.Frame(t) + b = tkinter.Button(f2) + for name in str(b).split('.'): + self.assertFalse(name.isidentifier(), msg=repr(name)) + def test_tk_setPalette(self): root = self.root root.tk_setPalette('black') diff --git a/Lib/tkinter/test/test_tkinter/test_variables.py b/Lib/tkinter/test/test_tkinter/test_variables.py index d8ba9cea74..2eb1e12671 100644 --- a/Lib/tkinter/test/test_tkinter/test_variables.py +++ b/Lib/tkinter/test/test_tkinter/test_variables.py @@ -87,7 +87,8 @@ class TestVariable(TestBase): v.set("value") self.assertTrue(v.side_effect) - def test_trace(self): + def test_trace_old(self): + # Old interface v = Variable(self.root) vname = str(v) trace = [] @@ -136,6 +137,55 @@ class TestVariable(TestBase): gc.collect() self.assertEqual(trace, [('write', vname, '', 'u')]) + def test_trace(self): + v = Variable(self.root) + vname = str(v) + trace = [] + def read_tracer(*args): + trace.append(('read',) + args) + def write_tracer(*args): + trace.append(('write',) + args) + tr1 = v.trace_add('read', read_tracer) + tr2 = v.trace_add(['write', 'unset'], write_tracer) + self.assertEqual(sorted(v.trace_info()), [ + (('read',), tr1), + (('write', 'unset'), tr2)]) + self.assertEqual(trace, []) + + v.set('spam') + self.assertEqual(trace, [('write', vname, '', 'write')]) + + trace = [] + v.get() + self.assertEqual(trace, [('read', vname, '', 'read')]) + + trace = [] + info = sorted(v.trace_info()) + v.trace_remove('write', tr1) # Wrong mode + self.assertEqual(sorted(v.trace_info()), info) + with self.assertRaises(TclError): + v.trace_remove('read', 'spam') # Wrong command name + self.assertEqual(sorted(v.trace_info()), info) + v.get() + self.assertEqual(trace, [('read', vname, '', 'read')]) + + trace = [] + v.trace_remove('read', tr1) + self.assertEqual(v.trace_info(), [(('write', 'unset'), tr2)]) + v.get() + self.assertEqual(trace, []) + + trace = [] + del write_tracer + gc.collect() + v.set('eggs') + self.assertEqual(trace, [('write', vname, '', 'write')]) + + trace = [] + del v + gc.collect() + self.assertEqual(trace, [('write', vname, '', 'unset')]) + class TestStringVar(TestBase): diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py index c924d55937..81b52eafea 100644 --- a/Lib/tkinter/test/test_tkinter/test_widgets.py +++ b/Lib/tkinter/test/test_tkinter/test_widgets.py @@ -91,9 +91,10 @@ class ToplevelTest(AbstractToplevelTest, unittest.TestCase): widget = self.create() self.assertEqual(widget['use'], '') parent = self.create(container=True) - wid = parent.winfo_id() - widget2 = self.create(use=wid) - self.assertEqual(int(widget2['use']), wid) + wid = hex(parent.winfo_id()) + with self.subTest(wid=wid): + widget2 = self.create(use=wid) + self.assertEqual(widget2['use'], wid) @add_standard_options(StandardOptionsTests) diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py index c68a650559..a1b7cdfcd1 100644 --- a/Lib/tkinter/test/test_ttk/test_functions.py +++ b/Lib/tkinter/test/test_ttk/test_functions.py @@ -1,6 +1,5 @@ # -*- encoding: utf-8 -*- import unittest -import tkinter from tkinter import ttk class MockTkApp: diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py index 8bd22d03e5..26766a8a1f 100644 --- a/Lib/tkinter/test/test_ttk/test_widgets.py +++ b/Lib/tkinter/test/test_ttk/test_widgets.py @@ -1487,6 +1487,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): def test_selection(self): + self.assertRaises(TypeError, self.tv.selection, 'spam') # item 'none' doesn't exist self.assertRaises(tkinter.TclError, self.tv.selection_set, 'none') self.assertRaises(tkinter.TclError, self.tv.selection_add, 'none') @@ -1500,25 +1501,31 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): c3 = self.tv.insert(item1, 'end') self.assertEqual(self.tv.selection(), ()) - self.tv.selection_set((c1, item2)) + self.tv.selection_set(c1, item2) self.assertEqual(self.tv.selection(), (c1, item2)) self.tv.selection_set(c2) self.assertEqual(self.tv.selection(), (c2,)) - self.tv.selection_add((c1, item2)) + self.tv.selection_add(c1, item2) self.assertEqual(self.tv.selection(), (c1, c2, item2)) self.tv.selection_add(item1) self.assertEqual(self.tv.selection(), (item1, c1, c2, item2)) + self.tv.selection_add() + self.assertEqual(self.tv.selection(), (item1, c1, c2, item2)) - self.tv.selection_remove((item1, c3)) + self.tv.selection_remove(item1, c3) self.assertEqual(self.tv.selection(), (c1, c2, item2)) self.tv.selection_remove(c2) self.assertEqual(self.tv.selection(), (c1, item2)) + self.tv.selection_remove() + self.assertEqual(self.tv.selection(), (c1, item2)) - self.tv.selection_toggle((c1, c3)) + self.tv.selection_toggle(c1, c3) self.assertEqual(self.tv.selection(), (c3, item2)) self.tv.selection_toggle(item2) self.assertEqual(self.tv.selection(), (c3,)) + self.tv.selection_toggle() + self.assertEqual(self.tv.selection(), (c3,)) self.tv.insert('', 'end', id='with spaces') self.tv.selection_set('with spaces') @@ -1536,6 +1543,40 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase): self.tv.selection_set(b'bytes\xe2\x82\xac') self.assertEqual(self.tv.selection(), ('bytes\xe2\x82\xac',)) + self.tv.selection_set() + self.assertEqual(self.tv.selection(), ()) + + # Old interface + self.tv.selection_set((c1, item2)) + self.assertEqual(self.tv.selection(), (c1, item2)) + self.tv.selection_add((c1, item1)) + self.assertEqual(self.tv.selection(), (item1, c1, item2)) + self.tv.selection_remove((item1, c3)) + self.assertEqual(self.tv.selection(), (c1, item2)) + self.tv.selection_toggle((c1, c3)) + self.assertEqual(self.tv.selection(), (c3, item2)) + + if sys.version_info >= (3, 7): + import warnings + warnings.warn( + 'Deprecated API of Treeview.selection() should be removed') + self.tv.selection_set() + self.assertEqual(self.tv.selection(), ()) + with self.assertWarns(DeprecationWarning): + self.tv.selection('set', (c1, item2)) + self.assertEqual(self.tv.selection(), (c1, item2)) + with self.assertWarns(DeprecationWarning): + self.tv.selection('add', (c1, item1)) + self.assertEqual(self.tv.selection(), (item1, c1, item2)) + with self.assertWarns(DeprecationWarning): + self.tv.selection('remove', (item1, c3)) + self.assertEqual(self.tv.selection(), (c1, item2)) + with self.assertWarns(DeprecationWarning): + self.tv.selection('toggle', (c1, c3)) + self.assertEqual(self.tv.selection(), (c3, item2)) + with self.assertWarns(DeprecationWarning): + selection = self.tv.selection(None) + self.assertEqual(selection, (c3, item2)) def test_set(self): self.tv['columns'] = ['A', 'B'] |