-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnode_subscript_test.py
More file actions
85 lines (80 loc) · 2.74 KB
/
node_subscript_test.py
File metadata and controls
85 lines (80 loc) · 2.74 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Test the jsonpath module."""
from unittest import TestCase
from jsonpath2.path import Path
class TestNodeSubscript(TestCase):
"""Test the node subscript."""
# pylint: disable=invalid-name
def test_node_subscript(self):
"""Test the node subscript."""
cases = [
(
[
"foo",
"bar",
"fum",
"baz",
],
{
'$["collection"][$["index"]]': [
{
"index": [],
"expected_values": [],
},
{
"index": 1,
"expected_values": ["bar"],
},
],
'$["collection"][$["index"][*]]': [
{
"index": [1, 3],
"expected_values": ["bar", "baz"],
},
],
},
),
(
{
"foo": "bar",
"fum": "baz",
},
{
'$["collection"][$["index"]]': [
{
"index": [],
"expected_values": [],
},
{
"index": "foo",
"expected_values": ["bar"],
},
],
'$["collection"][$["index"][*]]': [
{
"index": ["foo", "fum"],
"expected_values": ["bar", "baz"],
},
],
},
),
]
for collection, cases_for_collection in cases:
for string, cases_for_string in cases_for_collection.items():
for case_for_string in cases_for_string:
path = Path.parse_str(string)
self.assertEqual(string, str(path))
matches = list(
path.match(
{
"collection": collection,
"index": case_for_string["index"],
}
)
)
self.assertListEqual(
case_for_string["expected_values"],
list(map(lambda match_data: match_data.current_value, matches)),
)
# pylint: enable=invalid-name