26 lines
839 B
Python
26 lines
839 B
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from backup_tool.exclusions import ExclusionError, matches
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("path", "patterns", "expected"),
|
|
[
|
|
("notes.tmp", ["*.tmp"], True),
|
|
("nested/notes.tmp", ["*.tmp"], True),
|
|
("cache/item.txt", ["cache/"], True),
|
|
("cache/keep.txt", ["cache/", "!cache/keep.txt"], False),
|
|
("data/keep.txt", ["data/**"], True),
|
|
("data.txt", ["data/**"], False),
|
|
],
|
|
)
|
|
def test_gitignore_like_exclusions(path: str, patterns: list[str], expected: bool) -> None:
|
|
assert matches(path, patterns) is expected
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["../escape", "/absolute", "windows\\path", ""])
|
|
def test_exclusions_reject_unsafe_paths(value: str) -> None:
|
|
with pytest.raises(ExclusionError):
|
|
matches("safe.txt", [value])
|