-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_path_searchkeywordterms.py
42 lines (37 loc) · 1.9 KB
/
test_path_searchkeywordterms.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
import pytest
from yamlpath.enums import PathSearchKeywords
from yamlpath.path import SearchKeywordTerms
class Test_path_SearchKeywordTerms():
"""Tests for the SearchKeywordTerms class."""
@pytest.mark.parametrize("invert,keyword,parameters,output", [
(True, PathSearchKeywords.HAS_CHILD, "abc", "[!has_child(abc)]"),
(False, PathSearchKeywords.HAS_CHILD, "abc", "[has_child(abc)]"),
(False, PathSearchKeywords.HAS_CHILD, "abc\\,def", "[has_child(abc\\,def)]"),
(False, PathSearchKeywords.HAS_CHILD, "abc, def", "[has_child(abc, def)]"),
(False, PathSearchKeywords.HAS_CHILD, "abc,' def'", "[has_child(abc,' def')]"),
])
def test_str(self, invert, keyword, parameters, output):
assert output == str(SearchKeywordTerms(invert, keyword, parameters))
@pytest.mark.parametrize("parameters,output", [
("abc", ["abc"]),
("abc\\,def", ["abc,def"]),
("abc, def", ["abc", "def"]),
("abc,' def'", ["abc", " def"]),
("1,'1', 1, '1', 1 , ' 1', '1 ', ' 1 '", ["1", "1", "1", "1", "1", " 1", "1 ", " 1 "]),
("true, False,'True','false'", ["true", "False", "True", "false"]),
("'',,\"\", '', ,,\"\\'\",'\\\"'", ["", "", "", "", "", "", "'", "\""]),
("'And then, she said, \"Quote!\"'", ["And then, she said, \"Quote!\""]),
(None, []),
])
def test_parameter_parsing(self, parameters, output):
skt = SearchKeywordTerms(False, PathSearchKeywords.HAS_CHILD, parameters)
assert output == skt.parameters
@pytest.mark.parametrize("parameters", [
("','a'"),
("a,\"b,"),
])
def test_unmatched_demarcation(self, parameters):
skt = SearchKeywordTerms(False, PathSearchKeywords.HAS_CHILD, parameters)
with pytest.raises(ValueError) as ex:
parmlist = skt.parameters
assert -1 < str(ex.value).find("one or more unmatched demarcation symbol")