| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import contextlib | |
| 2 | + import dataclasses | ||
| 2 | 3 | import io | |
| 3 | 4 | import sys | |
| 4 | 5 | import unittest | |
@@ -21,6 +22,42 @@ def supports_virtual_terminal(): | |||
| 21 | 22 | return contextlib.nullcontext() | |
| 22 | 23 | ||
| 23 | 24 | ||
| 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 | + | ||
| 24 | 61 | class TestColorizeFunction(unittest.TestCase): | |
| 25 | 62 | def test_colorized_detection_checks_for_environment_variables(self): | |
| 26 | 63 | def check(env, fallback, expected): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments