|
| 1 | +"""Regression tests for JSON export progress reporting (CI vs TTY).""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from io import StringIO |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from pykotor.tools.resource_json import _supports_live_progress |
| 10 | + |
| 11 | + |
| 12 | +class _FakeTTYStream: |
| 13 | + """Minimal stream that reports as a TTY (like stderr under ``script``).""" |
| 14 | + |
| 15 | + def isatty(self) -> bool: |
| 16 | + return True |
| 17 | + |
| 18 | + |
| 19 | +def test_supports_live_progress_true_when_tty_and_not_ci(monkeypatch: pytest.MonkeyPatch) -> None: |
| 20 | + monkeypatch.delenv("CI", raising=False) |
| 21 | + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) |
| 22 | + assert _supports_live_progress(_FakeTTYStream()) is True |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.parametrize( |
| 26 | + ("env_name", "env_value"), |
| 27 | + [ |
| 28 | + ("CI", "true"), |
| 29 | + ("CI", "1"), |
| 30 | + ("CI", "yes"), |
| 31 | + ("GITHUB_ACTIONS", "true"), |
| 32 | + ("GITHUB_ACTIONS", "1"), |
| 33 | + ], |
| 34 | +) |
| 35 | +def test_supports_live_progress_false_in_ci_even_if_stream_is_tty( |
| 36 | + monkeypatch: pytest.MonkeyPatch, |
| 37 | + env_name: str, |
| 38 | + env_value: str, |
| 39 | +) -> None: |
| 40 | + monkeypatch.delenv("CI", raising=False) |
| 41 | + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) |
| 42 | + monkeypatch.setenv(env_name, env_value) |
| 43 | + assert _supports_live_progress(_FakeTTYStream()) is False |
| 44 | + |
| 45 | + |
| 46 | +def test_supports_live_progress_false_when_not_tty(monkeypatch: pytest.MonkeyPatch) -> None: |
| 47 | + monkeypatch.delenv("CI", raising=False) |
| 48 | + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) |
| 49 | + assert _supports_live_progress(StringIO()) is False |
0 commit comments