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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Regression tests for GFF JSON toolset format (GFFJSONWriter / read_gff JSON path)."""

from __future__ import annotations

import json

from pykotor.resource.formats.gff import GFF, bytes_gff, read_gff
from pykotor.resource.formats.gff.gff_data import GFFFieldType
from pykotor.resource.type import ToolsetFormat


def test_write_gff_json_roundtrips_through_read_gff() -> None:
"""write_gff(..., GFF_JSON) must stay aligned with read_gff auto-detect for `{` documents."""
gff = GFF()
gff.root.set_uint32("SomeField", 0xDEADBEEF)

raw_json = bytes_gff(gff, ToolsetFormat.GFF_JSON)
assert raw_json.lstrip().startswith(b"{")
parsed = json.loads(raw_json.decode("utf-8"))
assert parsed["fields"]["SomeField"]["type"] == GFFFieldType.UInt32.value
assert parsed["fields"]["SomeField"]["value"] == 0xDEADBEEF

loaded = read_gff(raw_json)
assert loaded.root.get_uint32("SomeField") == 0xDEADBEEF
41 changes: 41 additions & 0 deletions Libraries/PyKotor/tests/test_resource_json_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Regression tests for JSON export progress reporting under automation."""

from __future__ import annotations

import pytest

from pykotor.tools.resource_json import _supports_live_progress


class _FakeTTYStream:
"""Stream that claims to be a TTY (some CI runners attach a pseudo-TTY to stderr)."""

def isatty(self) -> bool:
return True


class _FakeNonTTYStream:
def isatty(self) -> bool:
return False


def test_supports_live_progress_honors_ci_env(monkeypatch: pytest.MonkeyPatch) -> None:
"""When CI is set, disable carriage-return live updates so logger-based progress is visible."""
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
assert _supports_live_progress(_FakeTTYStream()) is True

for ci_value in ("true", "True", "1", "yes", " YES "):
monkeypatch.setenv("CI", ci_value)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
assert _supports_live_progress(_FakeTTYStream()) is False

monkeypatch.delenv("CI", raising=False)
monkeypatch.setenv("GITHUB_ACTIONS", "1")
assert _supports_live_progress(_FakeTTYStream()) is False


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