diff --git a/Libraries/PyKotor/tests/diff_tool/test_cli_utils.py b/Libraries/PyKotor/tests/diff_tool/test_cli_utils.py new file mode 100644 index 000000000..9229b4f5c --- /dev/null +++ b/Libraries/PyKotor/tests/diff_tool/test_cli_utils.py @@ -0,0 +1,56 @@ +"""Regression tests for diff_tool CLI path normalization and install detection.""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path + +import pytest + +from pykotor.diff_tool.cli_utils import is_kotor_install_dir, normalize_path_arg + + +@pytest.mark.parametrize( + ("raw", "expected"), + [ + (None, None), + ("", None), + (" ", None), + ('"C:\\Games\\KOTOR"', r"C:\Games\KOTOR"), + ("'C:/Games/KOTOR'", "C:/Games/KOTOR"), + (r'C:\Program Files\Steam" C:\other', r"C:\Program Files\Steam"), + (r'C:\Program Files\folder\\', r"C:\Program Files\folder"), + ("C:/folder/", "C:/folder"), + ], +) +def test_normalize_path_arg(raw: str | None, expected: str | None) -> None: + assert normalize_path_arg(raw) == expected + + +def test_is_kotor_install_dir_false_when_not_directory(tmp_path: Path) -> None: + key_file = tmp_path / "chitin.key" + key_file.write_bytes(b"") + assert is_kotor_install_dir(key_file) is False + + +def test_is_kotor_install_dir_false_without_chitin(tmp_path: Path) -> None: + assert is_kotor_install_dir(tmp_path) is False + + +def test_is_kotor_install_dir_true_with_chitin_key(tmp_path: Path) -> None: + (tmp_path / "chitin.key").write_bytes(b"") + assert is_kotor_install_dir(tmp_path) is True + + +@pytest.mark.skipif( + sys.platform == "win32", + reason="Case-mismatch path semantics differ on Windows filesystems.", +) +def test_is_kotor_install_dir_case_mismatched_chitin_key(tmp_path: Path) -> None: + install_dir = tmp_path / "GameRoot" + install_dir.mkdir() + (install_dir / "chitin.key").write_bytes(b"") + + mismatched = tmp_path / "gameroot" + assert is_kotor_install_dir(mismatched) is True diff --git a/Libraries/PyKotor/tests/test_indoorkit_case_path.py b/Libraries/PyKotor/tests/test_indoorkit_case_path.py new file mode 100644 index 000000000..f920b53be --- /dev/null +++ b/Libraries/PyKotor/tests/test_indoorkit_case_path.py @@ -0,0 +1,29 @@ +"""Regression tests for CaseAwarePath usage in indoor kit loading (PR #151).""" + +from __future__ import annotations + +import json +import sys +from pathlib import Path + +import pytest + +from pykotor.tools.indoorkit import load_kits_unified + + +@pytest.mark.skipif( + sys.platform == "win32", + reason="Case-mismatch path semantics differ on Windows filesystems.", +) +def test_load_kits_unified_case_mismatched_kits_directory(tmp_path: Path) -> None: + kits_dir = tmp_path / "MyKits" + kits_dir.mkdir() + v1 = {"name": "Legacy", "id": "legacy", "doors": [], "components": []} + (kits_dir / "legacy.json").write_text(json.dumps(v1), encoding="utf-8") + + mismatched_path = tmp_path / "mykits" + kits, tile_kits = load_kits_unified(mismatched_path) + + assert len(kits) == 1 + assert kits[0].id == "legacy" + assert tile_kits == []