forked from wwkimball/yamlpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_common_searches.py
109 lines (104 loc) · 5.78 KB
/
test_common_searches.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
import pytest
import ruamel.yaml as ry
from yamlpath.enums import AnchorMatches, PathSearchMethods
from yamlpath.path import SearchTerms
from yamlpath.common import Searches
class Test_common_searches():
"""Tests for the Searches helper class."""
###
# search_matches
###
@pytest.mark.parametrize("match, method, needle, haystack", [
(True, PathSearchMethods.CONTAINS, "a", "parents"),
(True, PathSearchMethods.ENDS_WITH, "ts", "parents"),
(True, PathSearchMethods.EQUALS, "parents", "parents"),
(True, PathSearchMethods.EQUALS, 42, 42),
(True, PathSearchMethods.EQUALS, "42", 42),
(True, PathSearchMethods.EQUALS, 3.14159265385, 3.14159265385),
(True, PathSearchMethods.EQUALS, "3.14159265385", 3.14159265385),
(True, PathSearchMethods.EQUALS, True, True),
(True, PathSearchMethods.EQUALS, "True", True),
(True, PathSearchMethods.EQUALS, "true", True),
(True, PathSearchMethods.EQUALS, False, False),
(True, PathSearchMethods.EQUALS, "False", False),
(True, PathSearchMethods.EQUALS, "false", False),
(True, PathSearchMethods.GREATER_THAN, 2, 4),
(True, PathSearchMethods.GREATER_THAN, "2", 4),
(True, PathSearchMethods.GREATER_THAN, 2, "4"),
(True, PathSearchMethods.GREATER_THAN, "2", "4"),
(True, PathSearchMethods.GREATER_THAN, 2.1, 2.2),
(True, PathSearchMethods.GREATER_THAN, "2.1", 2.2),
(True, PathSearchMethods.GREATER_THAN, 2.1, "2.2"),
(True, PathSearchMethods.GREATER_THAN, "2.1", "2.2"),
(True, PathSearchMethods.GREATER_THAN, 2, 2.1),
(True, PathSearchMethods.GREATER_THAN, "2", 2.1),
(True, PathSearchMethods.GREATER_THAN, 2, "2.1"),
(True, PathSearchMethods.GREATER_THAN, "2", "2.1"),
(True, PathSearchMethods.GREATER_THAN, 2.9, 3),
(True, PathSearchMethods.GREATER_THAN, "2.9", 3),
(True, PathSearchMethods.GREATER_THAN, 2.9, "3"),
(True, PathSearchMethods.GREATER_THAN, "2.9", "3"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2, 4),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2", 4),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2, "4"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2", "4"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2.1, 2.2),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2.1", 2.2),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2.1, "2.2"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2.1", "2.2"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2, 2.1),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2", 2.1),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2, "2.1"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2", "2.1"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2.9, 3),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2.9", 3),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, 2.9, "3"),
(True, PathSearchMethods.GREATER_THAN_OR_EQUAL, "2.9", "3"),
(True, PathSearchMethods.LESS_THAN, 4, 2),
(True, PathSearchMethods.LESS_THAN, "4", 2),
(True, PathSearchMethods.LESS_THAN, 4, "2"),
(True, PathSearchMethods.LESS_THAN, "4", "2"),
(True, PathSearchMethods.LESS_THAN, 4.2, 4.1),
(True, PathSearchMethods.LESS_THAN, "4.2", 4.1),
(True, PathSearchMethods.LESS_THAN, 4.2, "4.1"),
(True, PathSearchMethods.LESS_THAN, "4.2", "4.1"),
(True, PathSearchMethods.LESS_THAN, 4.2, 4),
(True, PathSearchMethods.LESS_THAN, "4.2", 4),
(True, PathSearchMethods.LESS_THAN, 4.2, "4"),
(True, PathSearchMethods.LESS_THAN, "4.2", "4"),
(True, PathSearchMethods.LESS_THAN, 4, 3.9),
(True, PathSearchMethods.LESS_THAN, "4", 3.9),
(True, PathSearchMethods.LESS_THAN, 4, "3.9"),
(True, PathSearchMethods.LESS_THAN, "4", "3.9"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4, 2),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4", 2),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4, "2"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4", "2"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4.2, 4.1),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4.2", 4.1),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4.2, "4.1"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4.2", "4.1"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4.2, 4),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4.2", 4),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4.2, "4"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4.2", "4"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4, 3.9),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4", 3.9),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, 4, "3.9"),
(True, PathSearchMethods.LESS_THAN_OR_EQUAL, "4", "3.9"),
(True, PathSearchMethods.REGEX, ".+", "a"),
(True, PathSearchMethods.STARTS_WITH, "p", "parents")
])
def test_search_matches(self, match, method, needle, haystack):
assert match == Searches.search_matches(method, needle, haystack)
###
# search_anchor
###
def test_search_anchor(self):
anchor_value = "anchor_name"
node = ry.scalarstring.PlainScalarString("anchored value", anchor=anchor_value)
terms = SearchTerms(False, PathSearchMethods.CONTAINS, ".", "name")
seen_anchors = []
search_anchors = True
include_aliases = True
assert Searches.search_anchor(node, terms, seen_anchors, search_anchors=search_anchors, include_aliases=include_aliases) == AnchorMatches.MATCH