Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Libraries/PyKotor/tests/resource/formats/test_tlk.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def test_xml_io(self):
tlk = read_tlk(data)
self.validate_io(tlk)

def test_xml_reader_self_closing_string_has_empty_text(self):
"""Empty ``<string/>`` must load as empty dialogue text (not raise)."""
xml_doc = (
'<?xml version="1.0" encoding="utf-8"?>'
'<tlk language="0">'
'<string id="0"/>'
"</tlk>"
)
tlk = TLKXMLReader(xml_doc.encode("utf-8")).load()
self.assertEqual(tlk[0].text, "")
self.assertEqual(str(tlk[0].voiceover), "")

def test_json_io(self):
self.assertEqual(detect_tlk(JSON_TEST_DATA.encode("utf-8")), ResourceType.TLK_JSON)

Expand Down
49 changes: 49 additions & 0 deletions Libraries/PyKotor/tests/test_resource_json_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Regression tests for JSON export progress reporting (CI vs TTY)."""

from __future__ import annotations

from io import StringIO

import pytest

from pykotor.tools.resource_json import _supports_live_progress


class _FakeTTYStream:
"""Minimal stream that reports as a TTY (like stderr under ``script``)."""

def isatty(self) -> bool:
return True


def test_supports_live_progress_true_when_tty_and_not_ci(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
assert _supports_live_progress(_FakeTTYStream()) is True


@pytest.mark.parametrize(
("env_name", "env_value"),
[
("CI", "true"),
("CI", "1"),
("CI", "yes"),
("GITHUB_ACTIONS", "true"),
("GITHUB_ACTIONS", "1"),
],
)
def test_supports_live_progress_false_in_ci_even_if_stream_is_tty(
monkeypatch: pytest.MonkeyPatch,
env_name: str,
env_value: str,
) -> None:
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.setenv(env_name, env_value)
assert _supports_live_progress(_FakeTTYStream()) is False


def test_supports_live_progress_false_when_not_tty(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
assert _supports_live_progress(StringIO()) is False
Loading