-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_query_intersection.py
More file actions
48 lines (33 loc) · 1.39 KB
/
test_query_intersection.py
File metadata and controls
48 lines (33 loc) · 1.39 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
import asyncio
import json
import operator
import pytest
from jsonpath import JSONPathEnvironment
from jsonpath import JSONPathSyntaxError
from jsonpath import NodeList
from ._cts_case import Case
@pytest.fixture()
def env() -> JSONPathEnvironment:
return JSONPathEnvironment(strict=False)
with open("tests/query_intersection.json", encoding="utf8") as fd:
data = [Case(**case) for case in json.load(fd)["tests"]]
@pytest.mark.parametrize("case", data, ids=operator.attrgetter("name"))
def test_query_intersection_operator(env: JSONPathEnvironment, case: Case) -> None:
assert case.document is not None
nodes = NodeList(env.finditer(case.selector, case.document))
case.assert_nodes(nodes)
@pytest.mark.parametrize("case", data, ids=operator.attrgetter("name"))
def test_query_intersection_operator_async(
env: JSONPathEnvironment, case: Case
) -> None:
async def coro() -> NodeList:
assert case.document is not None
it = await env.finditer_async(case.selector, case.document)
return NodeList([node async for node in it])
nodes = asyncio.run(coro())
case.assert_nodes(nodes)
@pytest.mark.parametrize("case", data, ids=operator.attrgetter("name"))
def test_query_intersection_operator_fails_in_strict_mode(case: Case) -> None:
env = JSONPathEnvironment(strict=True)
with pytest.raises(JSONPathSyntaxError):
env.compile(case.selector)