Skip to content

Commit d69a7a6

Browse files
cursoragentPuritanWizard
andcommitted
test(common): cover case-aware is_kotor_install_dir
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
1 parent ca61ce8 commit d69a7a6

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""Regression tests for KOTOR install directory detection via CaseAwarePath."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
from collections.abc import Callable
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
from pykotor.diff_tool import cli_utils
12+
from pykotor.tools import patching
13+
from pykotor.tslpatcher.diff import engine
14+
15+
InstallDirChecker = Callable[[Path], bool | None]
16+
17+
_CHECKERS: tuple[tuple[str, InstallDirChecker], ...] = (
18+
("cli_utils", cli_utils.is_kotor_install_dir),
19+
("patching", patching.is_kotor_install_dir),
20+
("diff_engine", engine.is_kotor_install_dir),
21+
)
22+
23+
24+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
25+
def test_is_kotor_install_dir_true_when_chitin_key_present(
26+
checker: InstallDirChecker,
27+
tmp_path: Path,
28+
) -> None:
29+
(tmp_path / "chitin.key").write_bytes(b"")
30+
assert checker(tmp_path) is True
31+
32+
33+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
34+
def test_is_kotor_install_dir_false_without_chitin_key(
35+
checker: InstallDirChecker,
36+
tmp_path: Path,
37+
) -> None:
38+
assert checker(tmp_path) is False
39+
40+
41+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
42+
def test_is_kotor_install_dir_false_for_missing_path(
43+
checker: InstallDirChecker,
44+
tmp_path: Path,
45+
) -> None:
46+
assert checker(tmp_path / "does-not-exist") is False
47+
48+
49+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
50+
def test_is_kotor_install_dir_false_for_file_path(
51+
checker: InstallDirChecker,
52+
tmp_path: Path,
53+
) -> None:
54+
file_path = tmp_path / "not-a-dir"
55+
file_path.write_bytes(b"")
56+
assert checker(file_path) is False
57+
58+
59+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
60+
@pytest.mark.skipif(
61+
sys.platform == "win32",
62+
reason="Case-mismatch path semantics differ on Windows filesystems.",
63+
)
64+
def test_is_kotor_install_dir_case_mismatched_install_path(
65+
checker: InstallDirChecker,
66+
tmp_path: Path,
67+
) -> None:
68+
install_dir = tmp_path / "KotorInstall"
69+
install_dir.mkdir()
70+
(install_dir / "chitin.key").write_bytes(b"")
71+
72+
assert checker(tmp_path / "kotorinstall") is True
73+
74+
75+
@pytest.mark.parametrize("checker", [c for _, c in _CHECKERS], ids=[n for n, _ in _CHECKERS])
76+
@pytest.mark.skipif(
77+
sys.platform == "win32",
78+
reason="Case-mismatch path semantics differ on Windows filesystems.",
79+
)
80+
def test_is_kotor_install_dir_case_mismatched_chitin_key_name(
81+
checker: InstallDirChecker,
82+
tmp_path: Path,
83+
) -> None:
84+
(tmp_path / "CHITIN.KEY").write_bytes(b"")
85+
assert checker(tmp_path) is True

0 commit comments

Comments
 (0)