WIP
This commit is contained in:
parent
e70a0584c9
commit
a7a5b5c8ea
43 changed files with 5531 additions and 9 deletions
61
tests/test_dev_autoreload.py
Normal file
61
tests/test_dev_autoreload.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue