|
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | from sqlbuild.cli.commands._helpers.runtime import adapter_context, connection |
| 11 | +from sqlbuild.cli.commands._helpers.scope import command as scope_command |
11 | 12 | from sqlbuild.cli.commands._helpers.scope.command import run_scope_command |
12 | 13 | from sqlbuild.cli.commands.models import ScopeCommandRequest |
13 | 14 | from sqlbuild.compiler.scopes.models import ScopeCompleteness, ScopeIndex |
@@ -91,6 +92,28 @@ def test_given_verbose_flag_when_rendering_json_then_bytes_match_default_json( |
91 | 92 | assert "\x1b[" not in outputs[0] |
92 | 93 |
|
93 | 94 |
|
| 95 | +@pytest.mark.parametrize( |
| 96 | + "test_case", (ScopeCommandCase("no color flag", 0),), ids=lambda case: case.description |
| 97 | +) |
| 98 | +def test_given_no_color_flag_when_rendering_text_to_color_terminal_then_output_is_plain( |
| 99 | + monkeypatch: pytest.MonkeyPatch, |
| 100 | + capsys: pytest.CaptureFixture[str], |
| 101 | + test_case: ScopeCommandCase, |
| 102 | +) -> None: |
| 103 | + monkeypatch.setattr(scope_command, "supports_color", lambda: True) |
| 104 | + index: ScopeIndex = report_scope_lookup().index |
| 105 | + outputs: list[str] = [] |
| 106 | + for no_color in (False, True): |
| 107 | + exit_code: int = run_scope_command( |
| 108 | + request=ScopeCommandRequest(target="model:orders", no_color=no_color), |
| 109 | + load_scope_index=lambda **_kwargs: index, |
| 110 | + ) |
| 111 | + assert exit_code == test_case.expected_exit_code |
| 112 | + outputs.append(capsys.readouterr().out) |
| 113 | + assert "\x1b[" in outputs[0] |
| 114 | + assert "\x1b[" not in outputs[1] |
| 115 | + |
| 116 | + |
94 | 117 | @pytest.mark.parametrize( |
95 | 118 | "test_case", (ScopeCommandCase("partial", 1),), ids=lambda case: case.description |
96 | 119 | ) |
|
0 commit comments