(self)
| 230 | |
| 231 | |
| 232 | def test_format_layoutlist(self): |
| 233 | def sample(indent=0, indent_size=2): |
| 234 | return ttk._format_layoutlist( |
| 235 | [('a', {'other': [1, 2, 3], 'children': |
| 236 | [('b', {'children': |
| 237 | [('c', {'children': |
| 238 | [('d', {'nice': 'opt'})], 'something': (1, 2) |
| 239 | })] |
| 240 | })] |
| 241 | })], indent=indent, indent_size=indent_size)[0] |
| 242 | |
| 243 | def sample_expected(indent=0, indent_size=2): |
| 244 | spaces = lambda amount=0: ' ' * (amount + indent) |
| 245 | return ( |
| 246 | "%sa -other {1 2 3} -children {\n" |
| 247 | "%sb -children {\n" |
| 248 | "%sc -something {1 2} -children {\n" |
| 249 | "%sd -nice opt\n" |
| 250 | "%s}\n" |
| 251 | "%s}\n" |
| 252 | "%s}" % (spaces(), spaces(indent_size), |
| 253 | spaces(2 * indent_size), spaces(3 * indent_size), |
| 254 | spaces(2 * indent_size), spaces(indent_size), spaces())) |
| 255 | |
| 256 | # empty layout |
| 257 | self.assertEqual(ttk._format_layoutlist([])[0], '') |
| 258 | |
| 259 | # _format_layoutlist always expects the second item (in every item) |
| 260 | # to act like a dict (except when the value evaluates to False). |
| 261 | self.assertRaises(AttributeError, |
| 262 | ttk._format_layoutlist, [('a', 'b')]) |
| 263 | |
| 264 | smallest = ttk._format_layoutlist([('a', None)], indent=0) |
| 265 | self.assertEqual(smallest, |
| 266 | ttk._format_layoutlist([('a', '')], indent=0)) |
| 267 | self.assertEqual(smallest[0], 'a') |
| 268 | |
| 269 | # testing indentation levels |
| 270 | self.assertEqual(sample(), sample_expected()) |
| 271 | for i in range(4): |
| 272 | self.assertEqual(sample(i), sample_expected(i)) |
| 273 | self.assertEqual(sample(i, i), sample_expected(i, i)) |
| 274 | |
| 275 | # invalid layout format, different kind of exceptions will be |
| 276 | # raised by internal functions |
| 277 | |
| 278 | # plain wrong format |
| 279 | self.assertRaises(ValueError, ttk._format_layoutlist, |
| 280 | ['bad', 'format']) |
| 281 | # will try to use iteritems in the 'bad' string |
| 282 | self.assertRaises(AttributeError, ttk._format_layoutlist, |
| 283 | [('name', 'bad')]) |
| 284 | # bad children formatting |
| 285 | self.assertRaises(ValueError, ttk._format_layoutlist, |
| 286 | [('name', {'children': {'a': None}})]) |
| 287 | |
| 288 | |
| 289 | def test_script_from_settings(self): |
nothing calls this directly
no test coverage detected