|
| 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 |
0 commit comments