-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_filter.py
More file actions
89 lines (69 loc) · 2.51 KB
/
test_filter.py
File metadata and controls
89 lines (69 loc) · 2.51 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from empack.file_patterns import FileFilter, FilePattern
def test_regex_pattern():
fp = FilePattern.parse_obj(
{
"regex": R"^(?!.*\/tests\/).*((.*.\.py$)|(.*.\.so$))|(.*dateutil-zoneinfo\.tar\.gz$)",
}
)
assert fp.match("/home/fu/bar.py")
assert fp.match("/home/fu/bar.so")
assert not fp.match("/home/tests/fu/bar.py")
assert not fp.match("/home/tests/fu/bar.so")
assert fp.match("/hometests/fu/bar.py")
assert fp.match("/hometests/fu/bar.so")
def test_unix_pattern():
fp = FilePattern.parse_obj({"pattern": "*.py"})
assert fp.match("/home/fu/bar.py")
assert not fp.match("/hometests/fu/bar.pyc")
fp = FilePattern.parse_obj({"pattern": "**/tests/*"})
assert fp.match("/home/tests/bar")
assert not fp.match("/home/fu/bar")
def test_file_filter():
fp = FileFilter.parse_obj(
{
"include_patterns": [{"pattern": "*.py"}, {"pattern": "*.so"}],
"exclude_patterns": [{"pattern": "**/tests/*"}],
}
)
assert fp.match("/home/fu/bar.py")
assert fp.match("/home/fu/bar.so")
assert not fp.match("/home/tests/fu/bar.py")
assert not fp.match("/home/tests/fu/bar.so")
assert fp.match("/hometests/fu/bar.py")
assert fp.match("/hometests/fu/bar.so")
def test_empty_file_filter():
fp = FileFilter.parse_obj({"include_patterns": [], "exclude_patterns": []})
assert not fp.match("/home/fu/bar.py")
assert not fp.match("/home/fu/bar.so")
assert not fp.match("/home/tests/fu/bar.py")
assert not fp.match("/home/tests/fu/bar.so")
assert not fp.match("/hometests/fu/bar.py")
assert not fp.match("/hometests/fu/bar.so")
def test_default_patterns():
fp = FileFilter.parse_obj(
{
"include_patterns": [
{"pattern": "*.py"},
{"pattern": "lib/*.so*"},
],
"exclude_patterns": [
{"pattern": "tests/*"},
{"pattern": "docs/*"},
{"pattern": "*/tests/*"},
{"pattern": "*/docs/*"},
],
}
)
assert fp.match("mylib/some/file.py")
assert fp.match("lib/xyz.so")
assert fp.match("lib/xyz.so.32.1")
assert fp.match("lib/some/xyz.so.32.1")
assert not fp.match("tests/myother.py")
assert not fp.match("docs/myother.py")
assert not fp.match("xyz/docs/myother.py")
assert not fp.match("xyz/tests/myother.py")
if __name__ == "__main__":
import sys
import pytest
retcode = pytest.main()
sys.exit(retcode)