3
3
import pytest
4
4
5
5
from oascomply .ptrtemplates import (
6
- JSONPointerTemplate ,
7
- InvalidJSONPointerTemplateError ,
8
- JSONPointerTemplateEvaluationError ,
9
- RelativeJSONPointerTemplate ,
10
- InvalidRelativeJSONPointerTemplateError ,
11
- RelativeJSONPointerTemplateEvaluationError ,
6
+ JsonPtrTemplate ,
7
+ InvalidJsonPtrTemplateError ,
8
+ JsonPtrTemplateEvaluationError ,
9
+ RelJsonPtrTemplate ,
10
+ InvalidRelJsonPtrTemplateError ,
11
+ RelJsonPtrTemplateEvaluationError ,
12
12
)
13
13
14
14
22
22
def test_escape (unescaped , escaped ):
23
23
import sys
24
24
sys .stderr .write (f"{ unescaped !r} { escaped !r} " )
25
- assert JSONPointerTemplate .escape (unescaped ) == escaped
25
+ assert JsonPtrTemplate .escape (unescaped ) == escaped
26
26
27
27
28
28
@pytest .mark .parametrize ('escaped,unescaped' , (
@@ -35,7 +35,7 @@ def test_escape(unescaped, escaped):
35
35
def test_unescape (escaped , unescaped ):
36
36
import sys
37
37
sys .stderr .write (f"{ escaped !r} { unescaped !r} " )
38
- assert JSONPointerTemplate .unescape (escaped ) == unescaped
38
+ assert JsonPtrTemplate .unescape (escaped ) == unescaped
39
39
40
40
41
41
@pytest .mark .parametrize ('template_str,components' , (
@@ -54,7 +54,7 @@ def test_unescape(escaped, unescaped):
54
54
('/bar#' , [jschon .JSONPointer ('/bar#' )]),
55
55
))
56
56
def test_constructor (template_str , components ):
57
- jpt = JSONPointerTemplate (template_str )
57
+ jpt = JsonPtrTemplate (template_str )
58
58
assert jpt ._components == components
59
59
60
60
@@ -68,10 +68,10 @@ def test_constructor(template_str, components):
68
68
))
69
69
def test_constructor_errors (template_str ):
70
70
with pytest .raises (
71
- InvalidJSONPointerTemplateError ,
72
- match = 'not a valid JSONPointerTemplate ' ,
71
+ InvalidJsonPtrTemplateError ,
72
+ match = 'not a valid JsonPtrTemplate ' ,
73
73
):
74
- JSONPointerTemplate (template_str )
74
+ JsonPtrTemplate (template_str )
75
75
76
76
77
77
TEST_DOCUMENT = jschon .JSON ({
@@ -85,13 +85,13 @@ def test_constructor_errors(template_str):
85
85
86
86
@pytest .mark .parametrize ('template,output' , (
87
87
(
88
- JSONPointerTemplate ('' ),
88
+ JsonPtrTemplate ('' ),
89
89
[(jschon .JSONPointer ('' ), TEST_DOCUMENT , {}, None )],
90
90
), (
91
- JSONPointerTemplate ('/a/0' ),
91
+ JsonPtrTemplate ('/a/0' ),
92
92
[(jschon .JSONPointer ('/a/0' ), TEST_DOCUMENT ['a' ][0 ], {}, None )],
93
93
), (
94
- JSONPointerTemplate ('/e/{key}' ),
94
+ JsonPtrTemplate ('/e/{key}' ),
95
95
[
96
96
(
97
97
jschon .JSONPointer (f'/e/{ key } ' ),
@@ -101,7 +101,7 @@ def test_constructor_errors(template_str):
101
101
) for key in TEST_DOCUMENT ['e' ]
102
102
],
103
103
), (
104
- JSONPointerTemplate ('/e/{key}#' ),
104
+ JsonPtrTemplate ('/e/{key}#' ),
105
105
[
106
106
(
107
107
jschon .JSONPointer (f'/e/{ key } ' ),
@@ -111,7 +111,7 @@ def test_constructor_errors(template_str):
111
111
) for key in TEST_DOCUMENT ['e' ]
112
112
],
113
113
), (
114
- JSONPointerTemplate ('/e/{key1}/{index}' ),
114
+ JsonPtrTemplate ('/e/{key1}/{index}' ),
115
115
list (chain .from_iterable ([
116
116
[
117
117
(
@@ -123,7 +123,7 @@ def test_constructor_errors(template_str):
123
123
] for key1 in TEST_DOCUMENT ['e' ].keys ()
124
124
])),
125
125
), (
126
- JSONPointerTemplate ('/nope/{whatever}' ),
126
+ JsonPtrTemplate ('/nope/{whatever}' ),
127
127
[],
128
128
)
129
129
))
@@ -140,47 +140,47 @@ def test_evaluation(template, output):
140
140
('/a/0/{scalar}' , 'Cannot match template variable' , True ),
141
141
))
142
142
def test_evaluation_errors (template , match , require ):
143
- jpt = JSONPointerTemplate (template )
144
- with pytest .raises (JSONPointerTemplateEvaluationError , match = match ):
143
+ jpt = JsonPtrTemplate (template )
144
+ with pytest .raises (JsonPtrTemplateEvaluationError , match = match ):
145
145
list (jpt .evaluate (TEST_DOCUMENT , require_match = require ))
146
146
147
147
148
148
@pytest .mark .parametrize ('template_str,relptr,jptemplate' , (
149
149
('1+3#' , jschon .RelativeJSONPointer ('1+3#' ), None ),
150
- ('0/foo' , jschon .RelativeJSONPointer ('0' ), JSONPointerTemplate ('/foo' )),
150
+ ('0/foo' , jschon .RelativeJSONPointer ('0' ), JsonPtrTemplate ('/foo' )),
151
151
(
152
152
'1/{bar}#' ,
153
153
jschon .RelativeJSONPointer ('1' ),
154
- JSONPointerTemplate ('/{bar}#' ),
154
+ JsonPtrTemplate ('/{bar}#' ),
155
155
),
156
156
))
157
157
def test_rel_constructor (template_str , relptr , jptemplate ):
158
- rjpt = RelativeJSONPointerTemplate (template_str )
158
+ rjpt = RelJsonPtrTemplate (template_str )
159
159
assert rjpt ._relptr == relptr
160
160
assert rjpt ._jptemplate == jptemplate
161
161
162
162
163
163
@pytest .mark .parametrize ('template_str,match' , (
164
164
('0#/foo' , "Can't use '#'" ),
165
- ('stuff/nonsense' , 'not a valid RelativeJSONPointerTemplate ' ),
166
- ('0/{bar}#/foo' , 'not a valid RelativeJSONPointerTemplate ' ),
165
+ ('stuff/nonsense' , 'not a valid RelJsonPtrTemplate ' ),
166
+ ('0/{bar}#/foo' , 'not a valid RelJsonPtrTemplate ' ),
167
167
))
168
168
def test_rel_constructor_errors (template_str , match ):
169
- with pytest .raises (InvalidRelativeJSONPointerTemplateError , match = match ):
170
- RelativeJSONPointerTemplate (template_str )
169
+ with pytest .raises (InvalidRelJsonPtrTemplateError , match = match ):
170
+ RelJsonPtrTemplate (template_str )
171
171
172
172
173
173
@pytest .mark .parametrize ('template,start,output' , (
174
174
(
175
- RelativeJSONPointerTemplate ('0+1' ),
175
+ RelJsonPtrTemplate ('0+1' ),
176
176
jschon .JSONPointer ('/a/1' ).evaluate (TEST_DOCUMENT ),
177
177
[(jschon .RelativeJSONPointer ('0+1' ), TEST_DOCUMENT ['a' ][2 ], {}, None )],
178
178
), (
179
- RelativeJSONPointerTemplate ('1#' ),
179
+ RelJsonPtrTemplate ('1#' ),
180
180
jschon .JSONPointer ('/e/f' ).evaluate (TEST_DOCUMENT ),
181
181
[(jschon .RelativeJSONPointer ('1#' ), TEST_DOCUMENT ['e' ], {}, 'e' )],
182
182
), (
183
- RelativeJSONPointerTemplate ('0/{var}' ),
183
+ RelJsonPtrTemplate ('0/{var}' ),
184
184
jschon .JSONPointer ('/e/i' ).evaluate (TEST_DOCUMENT ),
185
185
[
186
186
(
@@ -197,7 +197,7 @@ def test_rel_constructor_errors(template_str, match):
197
197
),
198
198
],
199
199
), (
200
- RelativeJSONPointerTemplate ('0/nope/{whatever}' ),
200
+ RelJsonPtrTemplate ('0/nope/{whatever}' ),
201
201
TEST_DOCUMENT ,
202
202
[],
203
203
)
@@ -208,17 +208,17 @@ def test_rel_evaluation(template, start, output):
208
208
209
209
@pytest .mark .parametrize ('template,start,match,require' , (
210
210
(
211
- RelativeJSONPointerTemplate ('1/{whatever}' ),
211
+ RelJsonPtrTemplate ('1/{whatever}' ),
212
212
TEST_DOCUMENT ,
213
213
'Could not evaluate origin' ,
214
214
False ,
215
215
), (
216
- RelativeJSONPointerTemplate ('0/x' ),
216
+ RelJsonPtrTemplate ('0/x' ),
217
217
TEST_DOCUMENT ,
218
218
r'Path .* not found .* \(after applying' ,
219
219
True ,
220
220
)
221
221
))
222
222
def test_rel_evaluation_errors (template , start , match , require ):
223
- with pytest .raises (RelativeJSONPointerTemplateEvaluationError , match = match ):
223
+ with pytest .raises (RelJsonPtrTemplateEvaluationError , match = match ):
224
224
list (template .evaluate (start , require_match = require ))
0 commit comments