test_import_path.py
911 Bytes
from __future__ import annotations
from pathlib import Path
from apps.web_api.bootstrap.import_path import ensure_project_root_on_sys_path
def test_ensure_project_root_on_sys_path_inserts_root_once_at_front():
fake_file = Path("apps/web_api/app.py")
path_entries = ["existing-entry"]
project_root = ensure_project_root_on_sys_path(fake_file, path_entries)
assert path_entries[0] == str(project_root)
assert path_entries == [str(project_root), "existing-entry"]
def test_ensure_project_root_on_sys_path_does_not_duplicate_existing_root():
fake_file = Path("apps/web_api/app.py")
existing_root = str(Path(fake_file).resolve().parents[2])
path_entries = [existing_root, "existing-entry"]
project_root = ensure_project_root_on_sys_path(fake_file, path_entries)
assert project_root == Path(existing_root)
assert path_entries == [existing_root, "existing-entry"]