@@ -12,82 +12,62 @@ def test_version(self):
12
12
As of v4.0.0, __version__ is deprecated in favor of importlib.metadata.
13
13
"""
14
14
15
- with self .assertWarns (DeprecationWarning ) as w :
15
+ message = "Accessing jsonschema.__version__ is deprecated"
16
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
16
17
from jsonschema import __version__ # noqa
17
18
18
19
self .assertEqual (w .filename , __file__ )
19
- self .assertTrue (
20
- str (w .warning ).startswith (
21
- "Accessing jsonschema.__version__ is deprecated" ,
22
- ),
23
- )
24
20
25
21
def test_validators_ErrorTree (self ):
26
22
"""
27
23
As of v4.0.0, importing ErrorTree from jsonschema.validators is
28
24
deprecated in favor of doing so from jsonschema.exceptions.
29
25
"""
30
26
31
- with self .assertWarns (DeprecationWarning ) as w :
27
+ message = "Importing ErrorTree from jsonschema.validators is "
28
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
32
29
from jsonschema .validators import ErrorTree # noqa
33
30
34
31
self .assertEqual (w .filename , __file__ )
35
- self .assertTrue (
36
- str (w .warning ).startswith (
37
- "Importing ErrorTree from jsonschema.validators is deprecated" ,
38
- ),
39
- )
40
32
41
33
def test_validators_validators (self ):
42
34
"""
43
35
As of v4.0.0, accessing jsonschema.validators.validators is
44
36
deprecated.
45
37
"""
46
38
47
- with self .assertWarns (DeprecationWarning ) as w :
39
+ message = "Accessing jsonschema.validators.validators is deprecated"
40
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
48
41
value = validators .validators
49
- self .assertEqual (value , validators ._VALIDATORS )
50
42
43
+ self .assertEqual (value , validators ._VALIDATORS )
51
44
self .assertEqual (w .filename , __file__ )
52
- self .assertTrue (
53
- str (w .warning ).startswith (
54
- "Accessing jsonschema.validators.validators is deprecated" ,
55
- ),
56
- )
57
45
58
46
def test_validators_meta_schemas (self ):
59
47
"""
60
48
As of v4.0.0, accessing jsonschema.validators.meta_schemas is
61
49
deprecated.
62
50
"""
63
51
64
- with self .assertWarns (DeprecationWarning ) as w :
52
+ message = "Accessing jsonschema.validators.meta_schemas is deprecated"
53
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
65
54
value = validators .meta_schemas
66
- self .assertEqual (value , validators ._META_SCHEMAS )
67
55
56
+ self .assertEqual (value , validators ._META_SCHEMAS )
68
57
self .assertEqual (w .filename , __file__ )
69
- self .assertTrue (
70
- str (w .warning ).startswith (
71
- "Accessing jsonschema.validators.meta_schemas is deprecated" ,
72
- ),
73
- )
74
58
75
59
def test_RefResolver_in_scope (self ):
76
60
"""
77
61
As of v4.0.0, RefResolver.in_scope is deprecated.
78
62
"""
79
63
80
64
resolver = validators ._RefResolver .from_schema ({})
81
- with self .assertWarns (DeprecationWarning ) as w :
65
+ message = "jsonschema.RefResolver.in_scope is deprecated "
66
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
82
67
with resolver .in_scope ("foo" ):
83
68
pass
84
69
85
70
self .assertEqual (w .filename , __file__ )
86
- self .assertTrue (
87
- str (w .warning ).startswith (
88
- "jsonschema.RefResolver.in_scope is deprecated " ,
89
- ),
90
- )
91
71
92
72
def test_Validator_is_valid_two_arguments (self ):
93
73
"""
@@ -96,16 +76,12 @@ def test_Validator_is_valid_two_arguments(self):
96
76
"""
97
77
98
78
validator = validators .Draft7Validator ({})
99
- with self .assertWarns (DeprecationWarning ) as w :
79
+ message = "Passing a schema to Validator.is_valid is deprecated "
80
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
100
81
result = validator .is_valid ("foo" , {"type" : "number" })
101
82
102
83
self .assertFalse (result )
103
84
self .assertEqual (w .filename , __file__ )
104
- self .assertTrue (
105
- str (w .warning ).startswith (
106
- "Passing a schema to Validator.is_valid is deprecated " ,
107
- ),
108
- )
109
85
110
86
def test_Validator_iter_errors_two_arguments (self ):
111
87
"""
@@ -114,32 +90,24 @@ def test_Validator_iter_errors_two_arguments(self):
114
90
"""
115
91
116
92
validator = validators .Draft7Validator ({})
117
- with self .assertWarns (DeprecationWarning ) as w :
93
+ message = "Passing a schema to Validator.iter_errors is deprecated "
94
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
118
95
error , = validator .iter_errors ("foo" , {"type" : "number" })
119
96
120
97
self .assertEqual (error .validator , "type" )
121
98
self .assertEqual (w .filename , __file__ )
122
- self .assertTrue (
123
- str (w .warning ).startswith (
124
- "Passing a schema to Validator.iter_errors is deprecated " ,
125
- ),
126
- )
127
99
128
100
def test_Validator_resolver (self ):
129
101
"""
130
102
As of v4.18.0, accessing Validator.resolver is deprecated.
131
103
"""
132
104
133
105
validator = validators .Draft7Validator ({})
134
- with self .assertWarns (DeprecationWarning ) as w :
106
+ message = "Accessing Draft7Validator.resolver is "
107
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
135
108
self .assertIsInstance (validator .resolver , validators ._RefResolver )
136
109
137
110
self .assertEqual (w .filename , __file__ )
138
- self .assertTrue (
139
- str (w .warning ).startswith (
140
- "Accessing Draft7Validator.resolver is " ,
141
- ),
142
- )
143
111
144
112
def test_RefResolver (self ):
145
113
"""
@@ -167,16 +135,14 @@ def test_Validator_subclassing(self):
167
135
A future version will explicitly raise an error.
168
136
"""
169
137
170
- with self .assertWarns (DeprecationWarning ) as w :
138
+ message = "Subclassing validator classes is "
139
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
171
140
class Subclass (validators .Draft202012Validator ):
172
141
pass
173
142
174
143
self .assertEqual (w .filename , __file__ )
175
- self .assertTrue (
176
- str (w .warning ).startswith ("Subclassing validator classes is " ),
177
- )
178
144
179
- with self .assertWarns (DeprecationWarning ) as w :
145
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
180
146
class AnotherSubclass (validators .create (meta_schema = {})):
181
147
pass
182
148
@@ -188,109 +154,77 @@ def test_FormatChecker_cls_checks(self):
188
154
189
155
self .addCleanup (FormatChecker .checkers .pop , "boom" , None )
190
156
191
- with self .assertWarns (DeprecationWarning ) as w :
157
+ message = "FormatChecker.cls_checks "
158
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
192
159
FormatChecker .cls_checks ("boom" )
193
160
194
161
self .assertEqual (w .filename , __file__ )
195
- self .assertTrue (
196
- str (w .warning ).startswith ("FormatChecker.cls_checks " ),
197
- )
198
162
199
163
def test_draftN_format_checker (self ):
200
164
"""
201
165
As of v4.16.0, accessing jsonschema.draftn_format_checker is deprecated
202
166
in favor of Validator.FORMAT_CHECKER.
203
167
"""
204
168
205
- with self .assertWarns (DeprecationWarning ) as w :
169
+ message = "Accessing jsonschema.draft202012_format_checker is "
170
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
206
171
from jsonschema import draft202012_format_checker # noqa
207
172
208
173
self .assertIs (
209
174
draft202012_format_checker ,
210
175
validators .Draft202012Validator .FORMAT_CHECKER ,
211
176
)
212
177
self .assertEqual (w .filename , __file__ )
213
- self .assertTrue (
214
- str (w .warning ).startswith (
215
- "Accessing jsonschema.draft202012_format_checker is " ,
216
- ),
217
- msg = w .warning ,
218
- )
219
178
220
- with self .assertWarns (DeprecationWarning ) as w :
179
+ message = "Accessing jsonschema.draft201909_format_checker is "
180
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
221
181
from jsonschema import draft201909_format_checker # noqa
222
182
223
183
self .assertIs (
224
184
draft201909_format_checker ,
225
185
validators .Draft201909Validator .FORMAT_CHECKER ,
226
186
)
227
187
self .assertEqual (w .filename , __file__ )
228
- self .assertTrue (
229
- str (w .warning ).startswith (
230
- "Accessing jsonschema.draft201909_format_checker is " ,
231
- ),
232
- msg = w .warning ,
233
- )
234
188
235
- with self .assertWarns (DeprecationWarning ) as w :
189
+ message = "Accessing jsonschema.draft7_format_checker is "
190
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
236
191
from jsonschema import draft7_format_checker # noqa
237
192
238
193
self .assertIs (
239
194
draft7_format_checker ,
240
195
validators .Draft7Validator .FORMAT_CHECKER ,
241
196
)
242
197
self .assertEqual (w .filename , __file__ )
243
- self .assertTrue (
244
- str (w .warning ).startswith (
245
- "Accessing jsonschema.draft7_format_checker is " ,
246
- ),
247
- msg = w .warning ,
248
- )
249
198
250
- with self .assertWarns (DeprecationWarning ) as w :
199
+ message = "Accessing jsonschema.draft6_format_checker is "
200
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
251
201
from jsonschema import draft6_format_checker # noqa
252
202
253
203
self .assertIs (
254
204
draft6_format_checker ,
255
205
validators .Draft6Validator .FORMAT_CHECKER ,
256
206
)
257
207
self .assertEqual (w .filename , __file__ )
258
- self .assertTrue (
259
- str (w .warning ).startswith (
260
- "Accessing jsonschema.draft6_format_checker is " ,
261
- ),
262
- msg = w .warning ,
263
- )
264
208
265
- with self .assertWarns (DeprecationWarning ) as w :
209
+ message = "Accessing jsonschema.draft4_format_checker is "
210
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
266
211
from jsonschema import draft4_format_checker # noqa
267
212
268
213
self .assertIs (
269
214
draft4_format_checker ,
270
215
validators .Draft4Validator .FORMAT_CHECKER ,
271
216
)
272
217
self .assertEqual (w .filename , __file__ )
273
- self .assertTrue (
274
- str (w .warning ).startswith (
275
- "Accessing jsonschema.draft4_format_checker is " ,
276
- ),
277
- msg = w .warning ,
278
- )
279
218
280
- with self .assertWarns (DeprecationWarning ) as w :
219
+ message = "Accessing jsonschema.draft3_format_checker is "
220
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
281
221
from jsonschema import draft3_format_checker # noqa
282
222
283
223
self .assertIs (
284
224
draft3_format_checker ,
285
225
validators .Draft3Validator .FORMAT_CHECKER ,
286
226
)
287
227
self .assertEqual (w .filename , __file__ )
288
- self .assertTrue (
289
- str (w .warning ).startswith (
290
- "Accessing jsonschema.draft3_format_checker is " ,
291
- ),
292
- msg = w .warning ,
293
- )
294
228
295
229
with self .assertRaises (ImportError ):
296
230
from jsonschema import draft1234_format_checker # noqa
@@ -300,16 +234,12 @@ def test_import_cli(self):
300
234
As of v4.17.0, importing jsonschema.cli is deprecated.
301
235
"""
302
236
303
- with self .assertWarns (DeprecationWarning ) as w :
237
+ message = "The jsonschema CLI is deprecated and will be removed "
238
+ with self .assertWarnsRegex (DeprecationWarning , message ) as w :
304
239
import jsonschema .cli
305
240
importlib .reload (jsonschema .cli )
306
241
307
242
self .assertEqual (w .filename , importlib .__file__ )
308
- self .assertTrue (
309
- str (w .warning ).startswith (
310
- "The jsonschema CLI is deprecated and will be removed " ,
311
- ),
312
- )
313
243
314
244
def test_cli (self ):
315
245
"""
0 commit comments