Skip to content

Commit fd1c64a

Browse files
cursoragentBoden
andcommitted
test(resource-json): cover ci and tty live progress selection
Co-authored-by: Boden <th3w1zard1@users.noreply.github.com>
1 parent 160a6ca commit fd1c64a

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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(StringIO):
13+
"""Stream that claims to be a TTY (some CI runners attach a pseudo-TTY to stderr)."""
14+
15+
def isatty(self) -> bool:
16+
"""Always True: simulates stderr on a pseudo-TTY."""
17+
return True
18+
19+
20+
class _FakeNonTtyStream(StringIO):
21+
def isatty(self) -> bool:
22+
"""Always False: simulates captured or redirected output."""
23+
return False
24+
25+
26+
@pytest.mark.parametrize("ci_value", ("true", "1", "yes", "TRUE", " Yes "))
27+
def test_supports_live_progress_false_when_ci_set(
28+
monkeypatch: pytest.MonkeyPatch,
29+
ci_value: str,
30+
) -> None:
31+
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
32+
monkeypatch.setenv("CI", ci_value)
33+
assert _supports_live_progress(_FakeTtyStream()) is False
34+
35+
36+
@pytest.mark.parametrize("gha_value", ("true", "1", "yes"))
37+
def test_supports_live_progress_false_when_github_actions_set(
38+
monkeypatch: pytest.MonkeyPatch,
39+
gha_value: str,
40+
) -> None:
41+
monkeypatch.delenv("CI", raising=False)
42+
monkeypatch.setenv("GITHUB_ACTIONS", gha_value)
43+
assert _supports_live_progress(_FakeTtyStream()) is False
44+
45+
46+
def test_supports_live_progress_uses_isatty_when_no_automation_env(
47+
monkeypatch: pytest.MonkeyPatch,
48+
) -> None:
49+
monkeypatch.delenv("CI", raising=False)
50+
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
51+
assert _supports_live_progress(_FakeTtyStream()) is True
52+
assert _supports_live_progress(_FakeNonTtyStream()) is False
53+
54+
55+
def test_supports_live_progress_false_without_isatty(monkeypatch: pytest.MonkeyPatch) -> None:
56+
monkeypatch.delenv("CI", raising=False)
57+
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
58+
stream = StringIO()
59+
assert _supports_live_progress(stream) is False

0 commit comments

Comments
 (0)