61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from django.utils import autoreload
|
|
from watchfiles import Change
|
|
|
|
from config.dev_autoreload import TussilagoWatchfilesReloader
|
|
from config.dev_autoreload import build_project_watch_roots
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
def test_build_project_watch_roots_excludes_firecracker(tmp_path: Path) -> None:
|
|
"""Project watch roots should skip firecracker and hidden directories."""
|
|
(tmp_path / "config").mkdir()
|
|
(tmp_path / "control_plane").mkdir()
|
|
(tmp_path / "firecracker").mkdir()
|
|
(tmp_path / ".venv").mkdir()
|
|
(tmp_path / "static").mkdir()
|
|
|
|
assert build_project_watch_roots(tmp_path) == (
|
|
tmp_path / "config",
|
|
tmp_path / "control_plane",
|
|
tmp_path / "static",
|
|
)
|
|
|
|
|
|
def test_reloader_replaces_repo_root_with_child_dirs(
|
|
tmp_path: Path,
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""Repo root watch should be split so firecracker is excluded."""
|
|
(tmp_path / "config").mkdir()
|
|
(tmp_path / "control_plane").mkdir()
|
|
(tmp_path / "firecracker").mkdir()
|
|
(tmp_path / "static").mkdir()
|
|
|
|
watched_settings = tmp_path / "config" / "settings.py"
|
|
watched_settings.touch()
|
|
firecracker_config = tmp_path / "firecracker" / "vm_config.json"
|
|
firecracker_config.touch()
|
|
|
|
monkeypatch.setattr(
|
|
autoreload,
|
|
"sys_path_directories",
|
|
lambda: iter((tmp_path, tmp_path / "config")),
|
|
)
|
|
|
|
reloader = TussilagoWatchfilesReloader(project_root=tmp_path)
|
|
roots = reloader.watched_roots((tmp_path / "manage.py", watched_settings))
|
|
|
|
assert tmp_path not in roots
|
|
assert tmp_path / "config" in roots
|
|
assert tmp_path / "control_plane" in roots
|
|
assert tmp_path / "static" in roots
|
|
assert tmp_path / "firecracker" not in roots
|
|
assert reloader.file_filter(Change.added, str(firecracker_config)) is False
|