summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-28 15:42:05 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-28 15:42:05 (GMT)
commit24604d5b4ed0c3b4829cc11b3f43ff79babca4c6 (patch)
tree41f5204844a327ee1d3ee5f7ed93cb0a328823c4 /Lib/tkinter/test
parentaf984de9233db44ecb57597a05c68a837ba10882 (diff)
parentb49eff25b7af3398b44f1b5e8b29748948c22b69 (diff)
downloadcpython-24604d5b4ed0c3b4829cc11b3f43ff79babca4c6.zip
cpython-24604d5b4ed0c3b4829cc11b3f43ff79babca4c6.tar.gz
cpython-24604d5b4ed0c3b4829cc11b3f43ff79babca4c6.tar.bz2
Issue #21402: tkinter.ttk now works when default root window is not set.
Diffstat (limited to 'Lib/tkinter/test')
-rw-r--r--Lib/tkinter/test/test_ttk/test_functions.py56
1 files changed, 39 insertions, 17 deletions
diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py
index 1986e66..8dd8753 100644
--- a/Lib/tkinter/test/test_ttk/test_functions.py
+++ b/Lib/tkinter/test/test_ttk/test_functions.py
@@ -1,7 +1,19 @@
# -*- encoding: utf-8 -*-
import unittest
+import tkinter
from tkinter import ttk
+class MockTkApp:
+
+ def splitlist(self, arg):
+ if isinstance(arg, tuple):
+ return arg
+ return arg.split(':')
+
+ def wantobjects(self):
+ return True
+
+
class MockTclObj(object):
typename = 'test'
@@ -352,20 +364,22 @@ class InternalFunctionsTest(unittest.TestCase):
def test_list_from_layouttuple(self):
+ tk = MockTkApp()
+
# empty layout tuple
- self.assertFalse(ttk._list_from_layouttuple(()))
+ self.assertFalse(ttk._list_from_layouttuple(tk, ()))
# shortest layout tuple
- self.assertEqual(ttk._list_from_layouttuple(('name', )),
+ self.assertEqual(ttk._list_from_layouttuple(tk, ('name', )),
[('name', {})])
# not so interesting ltuple
sample_ltuple = ('name', '-option', 'value')
- self.assertEqual(ttk._list_from_layouttuple(sample_ltuple),
+ self.assertEqual(ttk._list_from_layouttuple(tk, sample_ltuple),
[('name', {'option': 'value'})])
# empty children
- self.assertEqual(ttk._list_from_layouttuple(
+ self.assertEqual(ttk._list_from_layouttuple(tk,
('something', '-children', ())),
[('something', {'children': []})]
)
@@ -378,7 +392,7 @@ class InternalFunctionsTest(unittest.TestCase):
)
)
)
- self.assertEqual(ttk._list_from_layouttuple(ltuple),
+ self.assertEqual(ttk._list_from_layouttuple(tk, ltuple),
[('name', {'option': 'niceone', 'children':
[('otherone', {'otheropt': 'othervalue', 'children':
[('child', {})]
@@ -387,29 +401,37 @@ class InternalFunctionsTest(unittest.TestCase):
)
# bad tuples
- self.assertRaises(ValueError, ttk._list_from_layouttuple,
+ self.assertRaises(ValueError, ttk._list_from_layouttuple, tk,
('name', 'no_minus'))
- self.assertRaises(ValueError, ttk._list_from_layouttuple,
+ self.assertRaises(ValueError, ttk._list_from_layouttuple, tk,
('name', 'no_minus', 'value'))
- self.assertRaises(ValueError, ttk._list_from_layouttuple,
+ self.assertRaises(ValueError, ttk._list_from_layouttuple, tk,
('something', '-children')) # no 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
+ self.assertRaises(ValueError, ttk._list_from_layouttuple, tk,
+ ('something', '-children', 'value')) # invalid children
def test_val_or_dict(self):
- def func(opt, val=None):
+ def func(res, opt=None, val=None):
+ if opt is None:
+ return res
if val is None:
return "test val"
return (opt, val)
- options = {'test': None}
- self.assertEqual(ttk._val_or_dict(options, func), "test val")
+ tk = MockTkApp()
+ tk.call = func
+
+ self.assertEqual(ttk._val_or_dict(tk, {}, '-test:3'),
+ {'test': '3'})
+ self.assertEqual(ttk._val_or_dict(tk, {}, ('-test', 3)),
+ {'test': 3})
+
+ self.assertEqual(ttk._val_or_dict(tk, {'test': None}, 'x:y'),
+ 'test val')
- options = {'test': 3}
- self.assertEqual(ttk._val_or_dict(options, func), options)
+ self.assertEqual(ttk._val_or_dict(tk, {'test': 3}, 'x:y'),
+ {'test': 3})
def test_convert_stringval(self):