Issue #15861: tkinter now correctly works with lists and tuples containing

strings with whitespaces, backslashes or unbalanced braces.
This commit is contained in:
Serhiy Storchaka 2013-01-15 17:58:14 +02:00
commit 1e2b7ee3e8
5 changed files with 123 additions and 81 deletions

View file

@ -49,13 +49,17 @@ class InternalFunctionsTest(unittest.TestCase):
ttk._format_optdict({'test': {'left': 'as is'}}),
{'-test': {'left': 'as is'}})
# check script formatting and untouched value(s)
# check script formatting
check_against(
ttk._format_optdict(
{'test': [1, -1, '', '2m', 0], 'nochange1': 3,
'nochange2': 'abc def'}, script=True),
{'-test': '{1 -1 {} 2m 0}', '-nochange1': 3,
'-nochange2': 'abc def' })
{'test': [1, -1, '', '2m', 0], 'test2': 3,
'test3': '', 'test4': 'abc def',
'test5': '"abc"', 'test6': '{}',
'test7': '} -spam {'}, script=True),
{'-test': '{1 -1 {} 2m 0}', '-test2': '3',
'-test3': '{}', '-test4': '{abc def}',
'-test5': '{"abc"}', '-test6': r'\{\}',
'-test7': r'\}\ -spam\ \{'})
opts = {'αβγ': True, 'á': False}
orig_opts = opts.copy()
@ -69,6 +73,32 @@ class InternalFunctionsTest(unittest.TestCase):
ttk._format_optdict(
{'option': ('one two', 'three')}),
{'-option': '{one two} three'})
check_against(
ttk._format_optdict(
{'option': ('one\ttwo', 'three')}),
{'-option': '{one\ttwo} three'})
# passing empty strings inside a tuple/list
check_against(
ttk._format_optdict(
{'option': ('', 'one')}),
{'-option': '{} one'})
# passing values with braces inside a tuple/list
check_against(
ttk._format_optdict(
{'option': ('one} {two', 'three')}),
{'-option': r'one\}\ \{two three'})
# passing quoted strings inside a tuple/list
check_against(
ttk._format_optdict(
{'option': ('"one"', 'two')}),
{'-option': '{"one"} two'})
check_against(
ttk._format_optdict(
{'option': ('{one}', 'two')}),
{'-option': r'\{one\} two'})
# ignore an option
amount_opts = len(ttk._format_optdict(opts, ignore=('á'))) / 2

View file

@ -189,6 +189,14 @@ class ComboboxTest(unittest.TestCase):
self.combo.configure(values=[1, '', 2])
self.assertEqual(self.combo['values'], ('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'))
# testing values with special characters
self.combo['values'] = [r'a\tb', '"a"', '} {']
self.assertEqual(self.combo['values'], (r'a\tb', '"a"', '} {'))
# out of range
self.assertRaises(tkinter.TclError, self.combo.current,
len(self.combo['values']))