"""Tests for ``ki18n.paths`` (PyInstaller / source checkout detection).""" import sys from pathlib import Path from ki18n import paths def test_not_frozen_by_default(monkeypatch): monkeypatch.setattr(sys, "frozen", False, raising=False) assert paths.is_frozen() is False def test_frozen_flag_detected(monkeypatch): monkeypatch.setattr(sys, "frozen", True, raising=False) assert paths.is_frozen() is True def test_is_frozen_returns_bool(monkeypatch): monkeypatch.setattr(sys, "frozen", 1, raising=False) assert paths.is_frozen() is True def test_source_checkout_uses_parent_of_package_directory(monkeypatch): monkeypatch.setattr(sys, "frozen", False, raising=False) assert paths.bundle_root() == Path(paths.__file__).resolve().parent.parent def test_frozen_uses_meipass(monkeypatch, tmp_path): monkeypatch.setattr(sys, "frozen", True, raising=False) monkeypatch.setattr(sys, "_MEIPASS", str(tmp_path), raising=False) assert paths.bundle_root() == tmp_path def test_frozen_without_meipass_uses_executable_directory(monkeypatch, tmp_path): executable = tmp_path.resolve() / "bin" / "app" monkeypatch.setattr(sys, "frozen", True, raising=False) monkeypatch.setattr(sys, "_MEIPASS", None, raising=False) monkeypatch.setattr(sys, "executable", str(executable)) assert paths.bundle_root() == executable.parent def test_bundle_root_returns_path(): assert isinstance(paths.bundle_root(), Path)