1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import pytest
from scantree.test_utils import get_mock_recursion_path
class TestRecursionFilterBase:
from scantree import RecursionFilter as test_class
@pytest.mark.parametrize(
"description, filter_kwargs, expected_output",
[
(
"include all",
{"linked_dirs": True, "linked_files": True},
["dir", "dir/file.txt", "ldir", "dir/lfile"],
),
("default include all", {}, ["dir", "dir/file.txt", "ldir", "dir/lfile"]),
(
"exclude linked dirs",
{"linked_dirs": False, "linked_files": True},
["dir", "dir/file.txt", "dir/lfile"],
),
(
"exclude linked files",
{"linked_dirs": True, "linked_files": False},
["dir", "dir/file.txt", "ldir"],
),
(
"exclude linked files and dirs",
{"linked_dirs": False, "linked_files": False},
["dir", "dir/file.txt"],
),
(
"include only .txt files (dirs always included)",
{"match": ["*.txt"]},
["dir", "dir/file.txt", "ldir"],
),
(
"exclude .txt files (dirs always included)",
{"match": ["*", "!*.txt"]},
["dir", "ldir", "dir/lfile"],
),
],
)
def test_call(self, description, filter_kwargs, expected_output):
paths = [
get_mock_recursion_path("dir", is_dir=True),
get_mock_recursion_path("dir/file.txt"),
get_mock_recursion_path("ldir", is_dir=True, is_symlink=True),
get_mock_recursion_path("dir/lfile", is_symlink=True),
]
relpath_to_path = {path.relative: path for path in paths}
rfilter = self.test_class(**filter_kwargs)
filtered_paths = list(rfilter(paths))
assert filtered_paths == [
relpath_to_path[relpath] for relpath in expected_output
]
|