|
4 | 4 | Note: test_regrtest cannot be run twice in parallel. |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import _colorize |
7 | 8 | import contextlib |
8 | 9 | import dataclasses |
9 | 10 | import glob |
|
21 | 22 | import tempfile |
22 | 23 | import textwrap |
23 | 24 | import unittest |
| 25 | +import unittest.mock |
24 | 26 | from xml.etree import ElementTree |
25 | 27 |
|
26 | 28 | from test import support |
@@ -2487,5 +2489,49 @@ def test_sanitize_xml(self): |
2487 | 2489 | 'valid t\xe9xt \u20ac') |
2488 | 2490 |
|
2489 | 2491 |
|
| 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 | + |
2490 | 2536 | if __name__ == '__main__': |
2491 | 2537 | unittest.main() |
0 commit comments