MCPcopy Index your code
hub / github.com/python/cpython / test_format_mapdict

Method test_format_mapdict

Lib/test/test_ttk_textonly.py:131–168  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

129
130
131 def test_format_mapdict(self):
132 opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
133 result = ttk._format_mapdict(opts)
134 self.assertEqual(len(result), len(list(opts.keys())) * 2)
135 self.assertEqual(result, ('-a', '{b c} val d otherval {} single'))
136 self.assertEqual(ttk._format_mapdict(opts, script=True),
137 ('-a', '{{b c} val d otherval {} single}'))
138
139 self.assertEqual(ttk._format_mapdict({2: []}), ('-2', ''))
140
141 opts = {'üñíćódè': [('á', 'vãl')]}
142 result = ttk._format_mapdict(opts)
143 self.assertEqual(result, ('-üñíćódè', 'á vãl'))
144
145 self.assertEqual(ttk._format_mapdict({'opt': [('value',)]}),
146 ('-opt', '{} value'))
147
148 # empty states
149 valid = {'opt': [('', '', 'hi')]}
150 self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))
151
152 # when passing multiple states, they all must be strings
153 invalid = {'opt': [(1, 2, 'valid val')]}
154 self.assertRaises(TypeError, ttk._format_mapdict, invalid)
155 invalid = {'opt': [([1], '2', 'valid val')]}
156 self.assertRaises(TypeError, ttk._format_mapdict, invalid)
157 # but when passing a single state, it can be anything
158 valid = {'opt': [[1, 'value']]}
159 self.assertEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
160 # special attention to single states which evaluate to False
161 for stateval in (None, 0, False, '', set()): # just some samples
162 valid = {'opt': [(stateval, 'value')]}
163 self.assertEqual(ttk._format_mapdict(valid),
164 ('-opt', '{} value'))
165
166 # values must be iterable
167 opts = {'a': None}
168 self.assertRaises(TypeError, ttk._format_mapdict, opts)
169
170
171 def test_format_elemcreate(self):

Callers

nothing calls this directly

Calls 5

listClass · 0.85
setFunction · 0.85
assertEqualMethod · 0.45
keysMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected