Skip to content

Commit fea1c51

Browse files
committed
Add tests for regrtest with colour
1 parent 7169f54 commit fea1c51

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Lib/test/test_regrtest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Note: test_regrtest cannot be run twice in parallel.
55
"""
66

7+
import _colorize
78
import contextlib
89
import dataclasses
910
import glob
@@ -21,6 +22,7 @@
2122
import tempfile
2223
import textwrap
2324
import unittest
25+
import unittest.mock
2426
from xml.etree import ElementTree
2527

2628
from test import support
@@ -2487,5 +2489,49 @@ def test_sanitize_xml(self):
24872489
'valid t\xe9xt \u20ac')
24882490

24892491

2492+
from test.libregrtest.results import TestResults
2493+
2494+
2495+
class TestColorized(unittest.TestCase):
2496+
def test_test_result_get_state(self):
2497+
# Arrange
2498+
green = _colorize.ANSIColors.GREEN
2499+
red = _colorize.ANSIColors.BOLD_RED
2500+
reset = _colorize.ANSIColors.RESET
2501+
yellow = _colorize.ANSIColors.YELLOW
2502+
2503+
good_results = TestResults()
2504+
good_results.good = ["good1", "good2"]
2505+
bad_results = TestResults()
2506+
bad_results.bad = ["bad1", "bad2"]
2507+
no_results = TestResults()
2508+
no_results.bad = []
2509+
interrupted_results = TestResults()
2510+
interrupted_results.interrupted = True
2511+
interrupted_worker_bug = TestResults()
2512+
interrupted_worker_bug.interrupted = True
2513+
interrupted_worker_bug.worker_bug = True
2514+
2515+
for results, expected in (
2516+
(good_results, f"{green}SUCCESS{reset}"),
2517+
(bad_results, f"{red}FAILURE{reset}"),
2518+
(no_results, f"{yellow}NO TESTS RAN{reset}"),
2519+
(interrupted_results, f"{yellow}INTERRUPTED{reset}"),
2520+
(
2521+
interrupted_worker_bug,
2522+
f"{yellow}INTERRUPTED{reset}, {red}WORKER BUG{reset}",
2523+
),
2524+
):
2525+
with self.subTest(results=results, expected=expected):
2526+
# Act
2527+
with unittest.mock.patch(
2528+
"_colorize.can_colorize", return_value=True
2529+
):
2530+
result = results.get_state(fail_env_changed=False)
2531+
2532+
# Assert
2533+
self.assertEqual(result, expected)
2534+
2535+
24902536
if __name__ == '__main__':
24912537
unittest.main()

0 commit comments

Comments
 (0)