Skip to content

Commit c115c09

Browse files
picnixzmiss-islington
authored andcommitted
pythongh-133346: add tests for _colorize.Theme (pythonGH-139687)
(cherry picked from commit 37827c1) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent d664102 commit c115c09

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Lib/test/test__colorize.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import dataclasses
23
import io
34
import sys
45
import unittest
@@ -21,6 +22,42 @@ def supports_virtual_terminal():
2122
return contextlib.nullcontext()
2223

2324

25+
class TestTheme(unittest.TestCase):
26+
27+
def test_attributes(self):
28+
# only theme configurations attributes by default
29+
for field in dataclasses.fields(_colorize.Theme):
30+
with self.subTest(field.name):
31+
self.assertIsSubclass(field.type, _colorize.ThemeSection)
32+
self.assertIsNotNone(field.default_factory)
33+
34+
def test_copy_with(self):
35+
theme = _colorize.Theme()
36+
37+
copy = theme.copy_with()
38+
self.assertEqual(theme, copy)
39+
40+
unittest_no_colors = _colorize.Unittest.no_colors()
41+
copy = theme.copy_with(unittest=unittest_no_colors)
42+
self.assertEqual(copy.argparse, theme.argparse)
43+
self.assertEqual(copy.difflib, theme.difflib)
44+
self.assertEqual(copy.syntax, theme.syntax)
45+
self.assertEqual(copy.traceback, theme.traceback)
46+
self.assertEqual(copy.unittest, unittest_no_colors)
47+
48+
def test_no_colors(self):
49+
# idempotence test
50+
theme_no_colors = _colorize.Theme().no_colors()
51+
theme_no_colors_no_colors = theme_no_colors.no_colors()
52+
self.assertEqual(theme_no_colors, theme_no_colors_no_colors)
53+
54+
# attributes check
55+
for section in dataclasses.fields(_colorize.Theme):
56+
with self.subTest(section.name):
57+
section_theme = getattr(theme_no_colors, section.name)
58+
self.assertEqual(section_theme, section.type.no_colors())
59+
60+
2461
class TestColorizeFunction(unittest.TestCase):
2562
def test_colorized_detection_checks_for_environment_variables(self):
2663
def check(env, fallback, expected):

0 commit comments

Comments
 (0)