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

Method test_colors

Lib/test/test_json/test_tool.py:253–319  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

251
252 @force_colorized
253 def test_colors(self):
254 infile = os_helper.TESTFN
255 self.addCleanup(os.remove, infile)
256
257 t = get_theme().syntax
258 ob = "{"
259 cb = "}"
260
261 cases = (
262 ('{}', '{}'),
263 ('[]', '[]'),
264 ('null', f'{t.keyword}null{t.reset}'),
265 ('true', f'{t.keyword}true{t.reset}'),
266 ('false', f'{t.keyword}false{t.reset}'),
267 ('NaN', f'{t.number}NaN{t.reset}'),
268 ('Infinity', f'{t.number}Infinity{t.reset}'),
269 ('-Infinity', f'{t.number}-Infinity{t.reset}'),
270 ('"foo"', f'{t.string}"foo"{t.reset}'),
271 (r'" \"foo\" "', f'{t.string}" \\"foo\\" "{t.reset}'),
272 ('"α"', f'{t.string}"\\u03b1"{t.reset}'),
273 ('123', f'{t.number}123{t.reset}'),
274 ('-1.25e+23', f'{t.number}-1.25e+23{t.reset}'),
275 (r'{"\\": ""}',
276 f'''\
277{ob}
278 {t.definition}"\\\\"{t.reset}: {t.string}""{t.reset}
279{cb}'''),
280 (r'{"\\\\": ""}',
281 f'''\
282{ob}
283 {t.definition}"\\\\\\\\"{t.reset}: {t.string}""{t.reset}
284{cb}'''),
285 ('''\
286{
287 "foo": "bar",
288 "baz": 1234,
289 "qux": [true, false, null],
290 "xyz": [NaN, -Infinity, Infinity]
291}''',
292 f'''\
293{ob}
294 {t.definition}"foo"{t.reset}: {t.string}"bar"{t.reset},
295 {t.definition}"baz"{t.reset}: {t.number}1234{t.reset},
296 {t.definition}"qux"{t.reset}: [
297 {t.keyword}true{t.reset},
298 {t.keyword}false{t.reset},
299 {t.keyword}null{t.reset}
300 ],
301 {t.definition}"xyz"{t.reset}: [
302 {t.number}NaN{t.reset},
303 {t.number}-Infinity{t.reset},
304 {t.number}Infinity{t.reset}
305 ]
306{cb}'''),
307 )
308
309 for input_, expected in cases:
310 with self.subTest(input=input_):

Callers

nothing calls this directly

Calls 10

get_themeFunction · 0.90
assert_python_okFunction · 0.90
addCleanupMethod · 0.80
openFunction · 0.50
subTestMethod · 0.45
writeMethod · 0.45
decodeMethod · 0.45
replaceMethod · 0.45
stripMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected