11import contextlib
2+ import dataclasses
23import io
34import sys
45import unittest
@@ -21,6 +22,41 @@ 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 .syntax , theme .syntax )
44+ self .assertEqual (copy .traceback , theme .traceback )
45+ self .assertEqual (copy .unittest , unittest_no_colors )
46+
47+ def test_no_colors (self ):
48+ # idempotence test
49+ theme_no_colors = _colorize .Theme ().no_colors ()
50+ theme_no_colors_no_colors = theme_no_colors .no_colors ()
51+ self .assertEqual (theme_no_colors , theme_no_colors_no_colors )
52+
53+ # attributes check
54+ for section in dataclasses .fields (_colorize .Theme ):
55+ with self .subTest (section .name ):
56+ section_theme = getattr (theme_no_colors , section .name )
57+ self .assertEqual (section_theme , section .type .no_colors ())
58+
59+
2460class TestColorizeFunction (unittest .TestCase ):
2561 def test_colorized_detection_checks_for_environment_variables (self ):
2662 def check (env , fallback , expected ):
0 commit comments