1818
1919import pytest
2020
21- import jsonpath
21+ from jsonpath import JSONPathEnvironment
22+ from jsonpath import JSONPathError
23+ from jsonpath import NodeList
2224
2325
2426@dataclass
@@ -35,10 +37,6 @@ class Case:
3537
3638
3739SKIP = {
38- # "basic, no leading whitespace": "flexible whitespace policy",
39- "basic, no trailing whitespace" : "flexible whitespace policy" ,
40- # "basic, bald descendant segment": "almost has a consensus",
41- # "filter, index segment on object, selects nothing": "flexible selector policy",
4240 "functions, match, dot matcher on \\ u2028" : "standard library re policy" ,
4341 "functions, match, dot matcher on \\ u2029" : "standard library re policy" ,
4442 "functions, search, dot matcher on \\ u2028" : "standard library re policy" ,
@@ -76,14 +74,6 @@ class Case:
7674 "name selector, double quotes, non-surrogate surrogate" : "expected behavior policy" ,
7775 "name selector, double quotes, surrogate supplementary" : "expected behavior policy" ,
7876 "name selector, double quotes, supplementary surrogate" : "expected behavior policy" ,
79- # "whitespace, selectors, space between dot and name": "flexible whitespace policy", # noqa: E501
80- # "whitespace, selectors, newline between dot and name": "flexible whitespace policy", # noqa: E501
81- # "whitespace, selectors, tab between dot and name": "flexible whitespace policy", # noqa: E501
82- # "whitespace, selectors, return between dot and name": "flexible whitespace policy", # noqa: E501
83- # "whitespace, selectors, space between recursive descent and name": "flexible whitespace policy", # noqa: E501
84- # "whitespace, selectors, newline between recursive descent and name": "flexible whitespace policy", # noqa: E501
85- # "whitespace, selectors, tab between recursive descent and name": "flexible whitespace policy", # noqa: E501
86- # "whitespace, selectors, return between recursive descent and name": "flexible whitespace policy", # noqa: E501
8777}
8878
8979
@@ -101,13 +91,18 @@ def invalid_cases() -> List[Case]:
10191 return [case for case in cases () if case .invalid_selector ]
10292
10393
94+ @pytest .fixture ()
95+ def env () -> JSONPathEnvironment :
96+ return JSONPathEnvironment (strict = True )
97+
98+
10499@pytest .mark .parametrize ("case" , valid_cases (), ids = operator .attrgetter ("name" ))
105- def test_compliance (case : Case ) -> None :
100+ def test_compliance (env : JSONPathEnvironment , case : Case ) -> None :
106101 if case .name in SKIP :
107102 pytest .skip (reason = SKIP [case .name ])
108103
109104 assert case .document is not None
110- nodes = jsonpath . NodeList (jsonpath .finditer (case .selector , case .document ))
105+ nodes = NodeList (env .finditer (case .selector , case .document ))
111106
112107 if case .results is not None :
113108 assert case .results_paths is not None
@@ -120,14 +115,14 @@ def test_compliance(case: Case) -> None:
120115
121116
122117@pytest .mark .parametrize ("case" , valid_cases (), ids = operator .attrgetter ("name" ))
123- def test_compliance_async (case : Case ) -> None :
118+ def test_compliance_async (env : JSONPathEnvironment , case : Case ) -> None :
124119 if case .name in SKIP :
125120 pytest .skip (reason = SKIP [case .name ])
126121
127- async def coro () -> jsonpath . NodeList :
122+ async def coro () -> NodeList :
128123 assert case .document is not None
129- it = await jsonpath .finditer_async (case .selector , case .document )
130- return jsonpath . NodeList ([node async for node in it ])
124+ it = await env .finditer_async (case .selector , case .document )
125+ return NodeList ([node async for node in it ])
131126
132127 nodes = asyncio .run (coro ())
133128
@@ -142,9 +137,9 @@ async def coro() -> jsonpath.NodeList:
142137
143138
144139@pytest .mark .parametrize ("case" , invalid_cases (), ids = operator .attrgetter ("name" ))
145- def test_invalid_selectors (case : Case ) -> None :
140+ def test_invalid_selectors (env : JSONPathEnvironment , case : Case ) -> None :
146141 if case .name in SKIP :
147142 pytest .skip (reason = SKIP [case .name ])
148143
149- with pytest .raises (jsonpath . JSONPathError ):
150- jsonpath .compile (case .selector )
144+ with pytest .raises (JSONPathError ):
145+ env .compile (case .selector )
0 commit comments