Crea servizio watchdog configurabile
This commit is contained in:
54
tests/test_config_and_filters.py
Normal file
54
tests/test_config_and_filters.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from bakrest.config import parse_config
|
||||
from bakrest.filters import WatchFilter
|
||||
|
||||
|
||||
def test_parse_config_normalizes_extensions(tmp_path: Path) -> None:
|
||||
config = parse_config(
|
||||
{
|
||||
"watch": {
|
||||
"include_dirs": [str(tmp_path)],
|
||||
"include_extensions": ["jpg", ".PNG"],
|
||||
"exclude_dirs": [],
|
||||
"exclude_patterns": [],
|
||||
}
|
||||
},
|
||||
tmp_path / "config.toml",
|
||||
)
|
||||
|
||||
assert config.watch.include_extensions == frozenset({".jpg", ".png"})
|
||||
|
||||
|
||||
def test_filter_accepts_included_extension(tmp_path: Path) -> None:
|
||||
config = parse_config(
|
||||
{
|
||||
"watch": {
|
||||
"include_dirs": [str(tmp_path)],
|
||||
"include_extensions": [".jpg"],
|
||||
"exclude_dirs": [],
|
||||
"exclude_patterns": [],
|
||||
}
|
||||
},
|
||||
tmp_path / "config.toml",
|
||||
)
|
||||
|
||||
assert WatchFilter(config.watch).should_track(tmp_path / "image.jpg")
|
||||
|
||||
|
||||
def test_filter_rejects_excluded_pattern(tmp_path: Path) -> None:
|
||||
config = parse_config(
|
||||
{
|
||||
"watch": {
|
||||
"include_dirs": [str(tmp_path)],
|
||||
"include_extensions": [".jpg"],
|
||||
"exclude_dirs": [],
|
||||
"exclude_patterns": ["~$*"],
|
||||
}
|
||||
},
|
||||
tmp_path / "config.toml",
|
||||
)
|
||||
|
||||
assert not WatchFilter(config.watch).should_track(tmp_path / "~$image.jpg")
|
||||
Reference in New Issue
Block a user