11import contextlib
2+ import dataclasses
23import io
34import sys
45import 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+
2461class TestColorizeFunction (unittest .TestCase ):
2562 def test_colorized_detection_checks_for_environment_variables (self ):
2663 def check (env , fallback , expected ):
0 commit comments