|
11 | 11 | ANSI, |
12 | 12 | to_formatted_text, |
13 | 13 | ) |
| 14 | +from prompt_toolkit.output.color_depth import ColorDepth |
14 | 15 | from rich.table import Table |
15 | 16 |
|
16 | 17 | import cmd2 |
|
25 | 26 | from cmd2.pt_utils import ( |
26 | 27 | Cmd2Lexer, |
27 | 28 | pt_filter_style, |
| 29 | + pt_resolve_color_depth, |
28 | 30 | ) |
29 | 31 |
|
30 | 32 | from .conftest import with_ansi_style |
@@ -96,6 +98,34 @@ def test_pt_filter_style_never() -> None: |
96 | 98 | assert result == su.strip_style(styled) |
97 | 99 |
|
98 | 100 |
|
| 101 | +@with_ansi_style(ru.AllowStyle.ALWAYS) |
| 102 | +def test_pt_resolve_color_depth_always(monkeypatch) -> None: |
| 103 | + # Ensure any host NO_COLOR environment variable doesn't affect the test |
| 104 | + monkeypatch.delenv("NO_COLOR", raising=False) |
| 105 | + assert pt_resolve_color_depth() == ColorDepth.TRUE_COLOR |
| 106 | + |
| 107 | + |
| 108 | +@with_ansi_style(ru.AllowStyle.TERMINAL) |
| 109 | +def test_pt_resolve_color_depth_terminal(monkeypatch) -> None: |
| 110 | + # Ensure any host NO_COLOR environment variable doesn't affect the test |
| 111 | + monkeypatch.delenv("NO_COLOR", raising=False) |
| 112 | + assert pt_resolve_color_depth() == ColorDepth.TRUE_COLOR |
| 113 | + |
| 114 | + |
| 115 | +@with_ansi_style(ru.AllowStyle.NEVER) |
| 116 | +def test_pt_resolve_color_depth_never(monkeypatch) -> None: |
| 117 | + # Under NEVER, colors are suppressed regardless of NO_COLOR |
| 118 | + monkeypatch.delenv("NO_COLOR", raising=False) |
| 119 | + assert pt_resolve_color_depth() == ColorDepth.DEPTH_1_BIT |
| 120 | + |
| 121 | + |
| 122 | +@with_ansi_style(ru.AllowStyle.ALWAYS) |
| 123 | +def test_pt_resolve_color_depth_no_color(monkeypatch) -> None: |
| 124 | + # Mock NO_COLOR=1 to ensure colors are suppressed |
| 125 | + monkeypatch.setenv("NO_COLOR", "1") |
| 126 | + assert pt_resolve_color_depth() == ColorDepth.DEPTH_1_BIT |
| 127 | + |
| 128 | + |
99 | 129 | class TestCmd2Lexer: |
100 | 130 | @with_ansi_style(ru.AllowStyle.NEVER) |
101 | 131 | def test_lex_document_no_style(self, mock_cmd_app): |
|
0 commit comments