FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-133346: add tests for `_colorize.Theme` by picnixz · Pull Request #139687 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
37 changes: 37 additions & 0 deletions Lib/test/test__colorize.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import dataclasses
import io
import sys
import unittest
Expand All @@ -21,6 +22,42 @@ def supports_virtual_terminal():
return contextlib.nullcontext()


class TestTheme(unittest.TestCase):

def test_attributes(self):
# only theme configurations attributes by default
for field in dataclasses.fields(_colorize.Theme):
with self.subTest(field.name):
self.assertIsSubclass(field.type, _colorize.ThemeSection)
self.assertIsNotNone(field.default_factory)

def test_copy_with(self):
theme = _colorize.Theme()

copy = theme.copy_with()
self.assertEqual(theme, copy)

unittest_no_colors = _colorize.Unittest.no_colors()
copy = theme.copy_with(unittest=unittest_no_colors)
self.assertEqual(copy.argparse, theme.argparse)
self.assertEqual(copy.difflib, theme.difflib)
self.assertEqual(copy.syntax, theme.syntax)
self.assertEqual(copy.traceback, theme.traceback)
self.assertEqual(copy.unittest, unittest_no_colors)

def test_no_colors(self):
# idempotence test
theme_no_colors = _colorize.Theme().no_colors()
theme_no_colors_no_colors = theme_no_colors.no_colors()
self.assertEqual(theme_no_colors, theme_no_colors_no_colors)

# attributes check
for section in dataclasses.fields(_colorize.Theme):
with self.subTest(section.name):
section_theme = getattr(theme_no_colors, section.name)
self.assertEqual(section_theme, section.type.no_colors())


class TestColorizeFunction(unittest.TestCase):
def test_colorized_detection_checks_for_environment_variables(self):
def check(env, fallback, expected):
Expand Down
Loading

Back | FazBrowse Home | New Git URL