Skip to content

Commit 195747f

Browse files
cursoragentPuritanWizard
andcommitted
test(coverage): add case-aware path regressions for diff cli and indoorkit
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
1 parent ca61ce8 commit 195747f

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Regression tests for diff_tool CLI path normalization and install detection."""
2+
3+
from __future__ import annotations
4+
5+
import json
6+
import sys
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
from pykotor.diff_tool.cli_utils import is_kotor_install_dir, normalize_path_arg
12+
13+
14+
@pytest.mark.parametrize(
15+
("raw", "expected"),
16+
[
17+
(None, None),
18+
("", None),
19+
(" ", None),
20+
('"C:\\Games\\KOTOR"', r"C:\Games\KOTOR"),
21+
("'C:/Games/KOTOR'", "C:/Games/KOTOR"),
22+
(r'C:\Program Files\Steam" C:\other', r"C:\Program Files\Steam"),
23+
(r'C:\Program Files\folder\\', r"C:\Program Files\folder"),
24+
("C:/folder/", "C:/folder"),
25+
],
26+
)
27+
def test_normalize_path_arg(raw: str | None, expected: str | None) -> None:
28+
assert normalize_path_arg(raw) == expected
29+
30+
31+
def test_is_kotor_install_dir_false_when_not_directory(tmp_path: Path) -> None:
32+
key_file = tmp_path / "chitin.key"
33+
key_file.write_bytes(b"")
34+
assert is_kotor_install_dir(key_file) is False
35+
36+
37+
def test_is_kotor_install_dir_false_without_chitin(tmp_path: Path) -> None:
38+
assert is_kotor_install_dir(tmp_path) is False
39+
40+
41+
def test_is_kotor_install_dir_true_with_chitin_key(tmp_path: Path) -> None:
42+
(tmp_path / "chitin.key").write_bytes(b"")
43+
assert is_kotor_install_dir(tmp_path) is True
44+
45+
46+
@pytest.mark.skipif(
47+
sys.platform == "win32",
48+
reason="Case-mismatch path semantics differ on Windows filesystems.",
49+
)
50+
def test_is_kotor_install_dir_case_mismatched_chitin_key(tmp_path: Path) -> None:
51+
install_dir = tmp_path / "GameRoot"
52+
install_dir.mkdir()
53+
(install_dir / "chitin.key").write_bytes(b"")
54+
55+
mismatched = tmp_path / "gameroot"
56+
assert is_kotor_install_dir(mismatched) is True
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Regression tests for CaseAwarePath usage in indoor kit loading (PR #151)."""
2+
3+
from __future__ import annotations
4+
5+
import json
6+
import sys
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
from pykotor.tools.indoorkit import load_kits_unified
12+
13+
14+
@pytest.mark.skipif(
15+
sys.platform == "win32",
16+
reason="Case-mismatch path semantics differ on Windows filesystems.",
17+
)
18+
def test_load_kits_unified_case_mismatched_kits_directory(tmp_path: Path) -> None:
19+
kits_dir = tmp_path / "MyKits"
20+
kits_dir.mkdir()
21+
v1 = {"name": "Legacy", "id": "legacy", "doors": [], "components": []}
22+
(kits_dir / "legacy.json").write_text(json.dumps(v1), encoding="utf-8")
23+
24+
mismatched_path = tmp_path / "mykits"
25+
kits, tile_kits = load_kits_unified(mismatched_path)
26+
27+
assert len(kits) == 1
28+
assert kits[0].id == "legacy"
29+
assert tile_kits == []

0 commit comments

Comments
 (0)