-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_path_methods.py
executable file
·117 lines (103 loc) · 4.45 KB
/
test_path_methods.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import unittest
from ..svndumpfilter import MatchFiles, add_dependents
DUMP_VERSIONS = [2, 3]
class PathMethodTestCase(unittest.TestCase):
def path_match_exclude(self, expected, excluded):
"""
Returns true if path is included.
"""
check = MatchFiles(False)
for item in excluded:
check.add_to_matches(item)
for path, result in iter(expected.items()):
self.assertEqual(check.is_included(path), result)
return True
def path_match_include(self, expected, included):
"""
Returns true if path is included.
"""
check = MatchFiles(True)
for item in included:
check.add_to_matches(item)
for path, result in iter(expected.items()):
self.assertEqual(check.is_included(path), result)
def test_path_include_1(self):
"""
Tests path inclusion with a 1-level inclusion parameter.
"""
expected = {"exclude_me": False, "exclude_me/file1.txt": False, "include_me": True,
"include_me/file1.txt": True, "include_me/exclude_me/file1.txt": True,
"include_me/exclude_me": True, "exclude_me/include_me": False}
included = ["include_me"]
self.path_match_include(expected, included)
def test_path_include_2(self):
"""
Tests path inclusion with a 2-level inclusion parameter.
"""
expected = {"foon": False, "foo": False, "foo/boon": False, "foo/boon/file1.txt": False,
"foo/bar": True, "foo/bar/file1.txt": True, "foon/bar": False,
"foon/var/file.txt": False, "bar": False}
included = ["foo/bar"]
self.path_match_include(expected, included)
def test_path_exclude_1(self):
"""
Tests path exclusion with a 1-level exclusion parameter.
"""
expected = {"exclude_me": False, "exclude_me/file1.txt": False, "include_me": True,
"include_me/file1.txt": True, "include_me/exclude_me/file1.txt": True,
"include_me/exclude_me": True, "exclude_me/include_me": False}
excluded = ["exclude_me"]
self.path_match_exclude(expected, excluded)
def test_path_exclude_2(self):
"""
Tests path exclusion with a 2-level exclusion parameter.
"""
expected = {"foon": True, "foo": True, "foo/boon": True, "foo/boon/file1.txt": True,
"foo/bar": False, "foo/bar/file1.txt": False, "foon/bar": True,
"foon/var/file.txt": True, "bar": True}
excluded = ["foo/bar"]
self.path_match_exclude(expected, excluded)
def test_add_dependents_1(self):
"""
Path coconut/branches is added.
"""
for dump_version in DUMP_VERSIONS:
check = MatchFiles(True)
check.add_to_matches("coconut/branches")
check.add_to_matches("User")
to_write = []
add_dependents(to_write, check.matches, dump_version)
actual_paths = [node.head["Node-path"] for node in to_write]
expected_paths = ["coconut"]
self.assertEqual(actual_paths, expected_paths)
def test_add_dependents_2(self):
"""
Nothing has been added.
"""
for dump_version in DUMP_VERSIONS:
check = MatchFiles(True)
to_write = []
add_dependents(to_write, check.matches, dump_version)
actual_paths = [node.head["Node-path"] for node in to_write]
expected_paths = []
self.assertEqual(actual_paths, expected_paths)
def test_add_dependents_3(self):
"""
Path coconut/branches is added.
Path coconut/branches/testname is added.
Path test/testme/test3 is added.
Path test is added.
Path whoop/whoo/woon is added.
"""
for dump_version in DUMP_VERSIONS:
check = MatchFiles(True)
check.add_to_matches("coconut/branches")
check.add_to_matches("coconut/branches/testname")
check.add_to_matches("test/testme/test3")
check.add_to_matches("test")
check.add_to_matches("whoop/whoo/woon")
to_write = []
add_dependents(to_write, check.matches, dump_version)
actual_paths = [node.head["Node-path"] for node in to_write]
expected_paths = ["whoop", "coconut", "whoop/whoo"]
self.assertEqual(set(actual_paths), set(expected_paths))