def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail("result still got elements: %s" % result) # passing an empty dict should return an empty object (tuple here) self.assertFalse(ttk._format_optdict({})) # check list formatting check_against( ttk._format_optdict({'fg': 'blue', 'padding': [1, 2, 3, 4]}), {'-fg': 'blue', '-padding': '1 2 3 4'}) # check tuple formatting (same as list) check_against( ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) # check untouched values check_against( ttk._format_optdict({'test': {'left': 'as is'}}), {'-test': {'left': 'as is'}}) # check script formatting and untouched value(s) 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' }) opts = {text('αβγ'): True, text('á'): False} orig_opts = opts.copy() # check if giving unicode keys is fine check_against(ttk._format_optdict(opts), {text('-αβγ'): True, text('-á'): False}) # opts should remain unchanged self.assertEqual(opts, orig_opts) # passing values with spaces inside a tuple/list check_against( ttk._format_optdict( {'option': ('one two', 'three')}), {'-option': '{one two} three'}) # ignore an option amount_opts = len(ttk._format_optdict(opts, ignore=(text('á')))) / 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore non-existing options amount_opts = len(ttk._format_optdict(opts, ignore=(text('á'), 'b'))) / 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore every option self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.failUnlessEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail("result still got elements: %s" % result) # passing an empty dict should return an empty object (tuple here) self.failIf(ttk._format_optdict({})) # check list formatting check_against( ttk._format_optdict({'fg': 'blue', 'padding': [1, 2, 3, 4]}), {'-fg': 'blue', '-padding': '1 2 3 4'}) # check tuple formatting (same as list) check_against( ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) # check untouched values check_against( ttk._format_optdict({'test': {'left': 'as is'}}), {'-test': {'left': 'as is'}}) # check script formatting and untouched value(s) 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' }) opts = {u'αβγ': True, u'á': False} orig_opts = opts.copy() # check if giving unicode keys is fine check_against(ttk._format_optdict(opts), {u'-αβγ': True, u'-á': False}) # opts should remain unchanged self.failUnlessEqual(opts, orig_opts) # passing values with spaces inside a tuple/list check_against( ttk._format_optdict( {'option': ('one two', 'three')}), {'-option': '{one two} three'}) # ignore an option amount_opts = len(ttk._format_optdict(opts, ignore=(u'á'))) / 2 self.failUnlessEqual(amount_opts, len(opts) - 1) # ignore non-existing options amount_opts = len(ttk._format_optdict(opts, ignore=(u'á', 'b'))) / 2 self.failUnlessEqual(amount_opts, len(opts) - 1) # ignore every option self.failIf(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail("result still got elements: %s" % result) # passing an empty dict should return an empty object (tuple here) self.assertFalse(ttk._format_optdict({})) # check list formatting check_against( ttk._format_optdict({ 'fg': 'blue', 'padding': [1, 2, 3, 4] }), { '-fg': 'blue', '-padding': '1 2 3 4' }) # check tuple formatting (same as list) check_against(ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) # check untouched values check_against(ttk._format_optdict({'test': { 'left': 'as is' }}), {'-test': { 'left': 'as is' }}) # check script formatting check_against( ttk._format_optdict( { '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 = {u'αβγ': True, u'á': False} orig_opts = opts.copy() # check if giving unicode keys is fine check_against(ttk._format_optdict(opts), {u'-αβγ': True, u'-á': False}) # opts should remain unchanged self.assertEqual(opts, orig_opts) # passing values with spaces inside a tuple/list check_against(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=(u'á'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore non-existing options amount_opts = len(ttk._format_optdict(opts, ignore=(u'á', 'b'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore every option self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail("result still got elements: %s" % result) # passing an empty dict should return an empty object (tuple here) self.assertFalse(ttk._format_optdict({})) # check list formatting check_against( ttk._format_optdict({'fg': 'blue', 'padding': [1, 2, 3, 4]}), {'-fg': 'blue', '-padding': '1 2 3 4'}) # check tuple formatting (same as list) check_against( ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) # check untouched values check_against( ttk._format_optdict({'test': {'left': 'as is'}}), {'-test': {'left': 'as is'}}) # check script formatting check_against( ttk._format_optdict( {'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 = {u'αβγ': True, u'á': False} orig_opts = opts.copy() # check if giving unicode keys is fine check_against(ttk._format_optdict(opts), {u'-αβγ': True, u'-á': False}) # opts should remain unchanged self.assertEqual(opts, orig_opts) # passing values with spaces inside a tuple/list check_against( 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=(u'á'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore non-existing options amount_opts = len(ttk._format_optdict(opts, ignore=(u'á', 'b'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore every option self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail('result still got elements: %s' % result) self.assertFalse(ttk._format_optdict({})) check_against( ttk._format_optdict({ 'fg': 'blue', 'padding': [1, 2, 3, 4] }), { '-fg': 'blue', '-padding': '1 2 3 4' }) check_against(ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) check_against(ttk._format_optdict({'test': { 'left': 'as is' }}), {'-test': { 'left': 'as is' }}) check_against( ttk._format_optdict( { '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': '\\{\\}', '-test7': '\\}\\ -spam\\ \\{' }) opts = {u'\u03b1\u03b2\u03b3': True, u'\xe1': False} orig_opts = opts.copy() check_against(ttk._format_optdict(opts), { u'-\u03b1\u03b2\u03b3': True, u'-\xe1': False }) self.assertEqual(opts, orig_opts) check_against(ttk._format_optdict({'option': ('one two', 'three')}), {'-option': '{one two} three'}) check_against(ttk._format_optdict({'option': ('one\ttwo', 'three')}), {'-option': '{one\ttwo} three'}) check_against(ttk._format_optdict({'option': ('', 'one')}), {'-option': '{} one'}) check_against(ttk._format_optdict({'option': ('one} {two', 'three')}), {'-option': 'one\\}\\ \\{two three'}) check_against(ttk._format_optdict({'option': ('"one"', 'two')}), {'-option': '{"one"} two'}) check_against(ttk._format_optdict({'option': ('{one}', 'two')}), {'-option': '\\{one\\} two'}) amount_opts = len(ttk._format_optdict(opts, ignore=u'\xe1')) // 2 self.assertEqual(amount_opts, len(opts) - 1) amount_opts = len(ttk._format_optdict(opts, ignore=(u'\xe1', 'b'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail('result still got elements: %s' % result) self.assertFalse(ttk._format_optdict({})) check_against(ttk._format_optdict({'fg': 'blue', 'padding': [1, 2, 3, 4]}), {'-fg': 'blue', '-padding': '1 2 3 4'}) check_against(ttk._format_optdict({'test': (1, 2, '', 0)}), {'-test': '1 2 {} 0'}) check_against(ttk._format_optdict({'test': {'left': 'as is'}}), {'-test': {'left': 'as is'}}) check_against(ttk._format_optdict({'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': '\\{\\}', '-test7': '\\}\\ -spam\\ \\{'}) opts = {u'\u03b1\u03b2\u03b3': True, u'\xe1': False} orig_opts = opts.copy() check_against(ttk._format_optdict(opts), {u'-\u03b1\u03b2\u03b3': True, u'-\xe1': False}) self.assertEqual(opts, orig_opts) check_against(ttk._format_optdict({'option': ('one two', 'three')}), {'-option': '{one two} three'}) check_against(ttk._format_optdict({'option': ('one\ttwo', 'three')}), {'-option': '{one\ttwo} three'}) check_against(ttk._format_optdict({'option': ('', 'one')}), {'-option': '{} one'}) check_against(ttk._format_optdict({'option': ('one} {two', 'three')}), {'-option': 'one\\}\\ \\{two three'}) check_against(ttk._format_optdict({'option': ('"one"', 'two')}), {'-option': '{"one"} two'}) check_against(ttk._format_optdict({'option': ('{one}', 'two')}), {'-option': '\\{one\\} two'}) amount_opts = len(ttk._format_optdict(opts, ignore=u'\xe1')) // 2 self.assertEqual(amount_opts, len(opts) - 1) amount_opts = len(ttk._format_optdict(opts, ignore=(u'\xe1', 'b'))) // 2 self.assertEqual(amount_opts, len(opts) - 1) self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))
def test_format_optdict(self): def check_against(fmt_opts, result): for i in range(0, len(fmt_opts), 2): self.assertEqual(result.pop(fmt_opts[i]), fmt_opts[i + 1]) if result: self.fail("result still got elements: %s" % result) # passing an empty dict should return an empty object (tuple here) self.assertFalse(ttk._format_optdict({})) # check list formatting check_against( ttk._format_optdict({"fg": "blue", "padding": [1, 2, 3, 4]}), {"-fg": "blue", "-padding": "1 2 3 4"} ) # check tuple formatting (same as list) check_against(ttk._format_optdict({"test": (1, 2, "", 0)}), {"-test": "1 2 {} 0"}) # check untouched values check_against(ttk._format_optdict({"test": {"left": "as is"}}), {"-test": {"left": "as is"}}) # check script formatting check_against( ttk._format_optdict( { "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 = {u"αβγ": True, u"á": False} orig_opts = opts.copy() # check if giving unicode keys is fine check_against(ttk._format_optdict(opts), {u"-αβγ": True, u"-á": False}) # opts should remain unchanged self.assertEqual(opts, orig_opts) # passing values with spaces inside a tuple/list check_against(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=(u"á"))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore non-existing options amount_opts = len(ttk._format_optdict(opts, ignore=(u"á", "b"))) // 2 self.assertEqual(amount_opts, len(opts) - 1) # ignore every option self.assertFalse(ttk._format_optdict(opts, ignore=opts.keys()))