-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils_test.py
62 lines (52 loc) · 1.85 KB
/
utils_test.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
import unittest
from utils import PathMatchingTree
class TestPathMatchingTree(unittest.TestCase):
def test_get_matching_exact_match(self):
config = {
"foo/bar": "value1",
"baz/qux": "value2"
}
pmt = PathMatchingTree(config)
result = pmt.get_matching("foo/bar")
self.assertEqual(result, "value1")
def test_get_matching_partial_match(self):
config = {
"foo/bar": "value1",
"baz/qux": "value2"
}
pmt = PathMatchingTree(config)
self.assertIsNone(pmt.get_matching("foo"))
def test_get_matching_wildcard_match(self):
config = {
"/foo/*": "value1",
"/baz/qux": "value2"
}
pmt = PathMatchingTree(config)
self.assertEqual(pmt.get_matching("foo/bar"), "value1")
def test_get_matching_multiple_wildcard_match(self):
config = {
"/foo/*": "value1",
"/foo/*/bar": "value2"
}
pmt = PathMatchingTree(config)
self.assertIsNone(pmt.get_matching("/foo"))
self.assertEqual(pmt.get_matching("/foo/baz"), "value1")
self.assertEqual(pmt.get_matching("/foo/baz/bar2"), "value1")
self.assertEqual(pmt.get_matching("/foo/baz/bar"), "value2")
def test_get_matching_no_match(self):
config = {
"/foo/bar": "value1",
"/baz/qux": "value2"
}
pmt = PathMatchingTree(config)
self.assertIsNone(pmt.get_matching("/foo"))
self.assertIsNone(pmt.get_matching("/baz"))
def test_get_matching_empty_string_match(self):
config = {
"/": "value1"
}
pmt = PathMatchingTree(config)
self.assertEqual(pmt.get_matching("/"), "value1")
self.assertEqual(pmt.get_matching("/test"), "value1")
if __name__ == "__main__":
unittest.main()