@@ -67,14 +67,16 @@ def test_parse_result_set_schema(
67
67
assert args .schema_path is None
68
68
69
69
70
- def test_requires_some_args (runner ):
71
- result = runner .invoke (cli_main , [])
70
+ def test_requires_some_args (cli_runner ):
71
+ result = cli_runner .invoke (cli_main , [])
72
72
assert result .exit_code == 2
73
73
74
74
75
- def test_schemafile_and_instancefile (runner , mock_parse_result , in_tmp_dir , tmp_path ):
75
+ def test_schemafile_and_instancefile (
76
+ cli_runner , mock_parse_result , in_tmp_dir , tmp_path
77
+ ):
76
78
touch_files (tmp_path , "foo.json" )
77
- runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
79
+ cli_runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
78
80
assert mock_parse_result .schema_mode == SchemaLoadingMode .filepath
79
81
assert mock_parse_result .schema_path == "schema.json"
80
82
assert isinstance (mock_parse_result .instancefiles , tuple )
@@ -83,25 +85,27 @@ def test_schemafile_and_instancefile(runner, mock_parse_result, in_tmp_dir, tmp_
83
85
assert tuple (f .name for f in mock_parse_result .instancefiles ) == ("foo.json" ,)
84
86
85
87
86
- def test_requires_at_least_one_instancefile (runner ):
87
- result = runner .invoke (cli_main , ["--schemafile" , "schema.json" ])
88
+ def test_requires_at_least_one_instancefile (cli_runner ):
89
+ result = cli_runner .invoke (cli_main , ["--schemafile" , "schema.json" ])
88
90
assert result .exit_code == 2
89
91
90
92
91
- def test_requires_schemafile (runner , in_tmp_dir , tmp_path ):
93
+ def test_requires_schemafile (cli_runner , in_tmp_dir , tmp_path ):
92
94
touch_files (tmp_path , "foo.json" )
93
- result = runner .invoke (cli_main , ["foo.json" ])
95
+ result = cli_runner .invoke (cli_main , ["foo.json" ])
94
96
assert result .exit_code == 2
95
97
96
98
97
- def test_no_cache_defaults_false (runner , mock_parse_result ):
98
- runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
99
+ def test_no_cache_defaults_false (cli_runner , mock_parse_result ):
100
+ cli_runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
99
101
assert mock_parse_result .disable_cache is False
100
102
101
103
102
- def test_no_cache_flag_is_true (runner , mock_parse_result , in_tmp_dir , tmp_path ):
104
+ def test_no_cache_flag_is_true (cli_runner , mock_parse_result , in_tmp_dir , tmp_path ):
103
105
touch_files (tmp_path , "foo.json" )
104
- runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" , "--no-cache" ])
106
+ cli_runner .invoke (
107
+ cli_main , ["--schemafile" , "schema.json" , "foo.json" , "--no-cache" ]
108
+ )
105
109
assert mock_parse_result .disable_cache is True
106
110
107
111
@@ -133,9 +137,9 @@ def test_no_cache_flag_is_true(runner, mock_parse_result, in_tmp_dir, tmp_path):
133
137
],
134
138
],
135
139
)
136
- def test_mutex_schema_opts (runner , cmd_args , in_tmp_dir , tmp_path ):
140
+ def test_mutex_schema_opts (cli_runner , cmd_args , in_tmp_dir , tmp_path ):
137
141
touch_files (tmp_path , "foo.json" )
138
- result = runner .invoke (cli_main , cmd_args + ["foo.json" ])
142
+ result = cli_runner .invoke (cli_main , cmd_args + ["foo.json" ])
139
143
assert result .exit_code == 2
140
144
assert "are mutually exclusive" in result .stderr
141
145
@@ -148,24 +152,24 @@ def test_mutex_schema_opts(runner, cmd_args, in_tmp_dir, tmp_path):
148
152
["-h" ],
149
153
],
150
154
)
151
- def test_supports_common_option (runner , cmd_args ):
152
- result = runner .invoke (cli_main , cmd_args )
155
+ def test_supports_common_option (cli_runner , cmd_args ):
156
+ result = cli_runner .invoke (cli_main , cmd_args )
153
157
assert result .exit_code == 0
154
158
155
159
156
160
@pytest .mark .parametrize (
157
161
"setting,expect_value" , [(None , None ), ("1" , False ), ("0" , False )]
158
162
)
159
163
def test_no_color_env_var (
160
- runner , monkeypatch , setting , expect_value , boxed_context , in_tmp_dir , tmp_path
164
+ cli_runner , monkeypatch , setting , expect_value , boxed_context , in_tmp_dir , tmp_path
161
165
):
162
166
if setting is None :
163
167
monkeypatch .delenv ("NO_COLOR" , raising = False )
164
168
else :
165
169
monkeypatch .setenv ("NO_COLOR" , setting )
166
170
167
171
touch_files (tmp_path , "foo.json" )
168
- runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
172
+ cli_runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
169
173
assert boxed_context .ref .color == expect_value
170
174
171
175
@@ -174,22 +178,22 @@ def test_no_color_env_var(
174
178
[(None , None ), ("auto" , None ), ("always" , True ), ("never" , False )],
175
179
)
176
180
def test_color_cli_option (
177
- runner , setting , expected_value , boxed_context , in_tmp_dir , tmp_path
181
+ cli_runner , setting , expected_value , boxed_context , in_tmp_dir , tmp_path
178
182
):
179
183
args = ["--schemafile" , "schema.json" , "foo.json" ]
180
184
if setting :
181
185
args .extend (("--color" , setting ))
182
186
touch_files (tmp_path , "foo.json" )
183
- runner .invoke (cli_main , args )
187
+ cli_runner .invoke (cli_main , args )
184
188
assert boxed_context .ref .color == expected_value
185
189
186
190
187
191
def test_no_color_env_var_overrides_cli_option (
188
- runner , monkeypatch , mock_cli_exec , boxed_context , in_tmp_dir , tmp_path
192
+ cli_runner , monkeypatch , mock_cli_exec , boxed_context , in_tmp_dir , tmp_path
189
193
):
190
194
monkeypatch .setenv ("NO_COLOR" , "1" )
191
195
touch_files (tmp_path , "foo.json" )
192
- runner .invoke (
196
+ cli_runner .invoke (
193
197
cli_main , ["--color=always" , "--schemafile" , "schema.json" , "foo.json" ]
194
198
)
195
199
assert boxed_context .ref .color is False
@@ -200,21 +204,23 @@ def test_no_color_env_var_overrides_cli_option(
200
204
[("auto" , 0 ), ("always" , 0 ), ("never" , 0 ), ("anything_else" , 2 )],
201
205
)
202
206
def test_color_cli_option_is_choice (
203
- runner , setting , expected_value , in_tmp_dir , tmp_path
207
+ cli_runner , setting , expected_value , in_tmp_dir , tmp_path
204
208
):
205
209
touch_files (tmp_path , "foo.json" )
206
210
assert (
207
- runner .invoke (
211
+ cli_runner .invoke (
208
212
cli_main ,
209
213
["--color" , setting , "--schemafile" , "schema.json" , "foo.json" ],
210
214
).exit_code
211
215
== expected_value
212
216
)
213
217
214
218
215
- def test_formats_default_to_enabled (runner , mock_parse_result , in_tmp_dir , tmp_path ):
219
+ def test_formats_default_to_enabled (
220
+ cli_runner , mock_parse_result , in_tmp_dir , tmp_path
221
+ ):
216
222
touch_files (tmp_path , "foo.json" )
217
- runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
223
+ cli_runner .invoke (cli_main , ["--schemafile" , "schema.json" , "foo.json" ])
218
224
assert mock_parse_result .disable_all_formats is False
219
225
assert mock_parse_result .disable_formats == ()
220
226
@@ -232,10 +238,10 @@ def test_formats_default_to_enabled(runner, mock_parse_result, in_tmp_dir, tmp_p
232
238
),
233
239
)
234
240
def test_disable_selected_formats (
235
- runner , mock_parse_result , addargs , in_tmp_dir , tmp_path
241
+ cli_runner , mock_parse_result , addargs , in_tmp_dir , tmp_path
236
242
):
237
243
touch_files (tmp_path , "foo.json" )
238
- runner .invoke (
244
+ cli_runner .invoke (
239
245
cli_main ,
240
246
[
241
247
"--schemafile" ,
@@ -263,10 +269,12 @@ def test_disable_selected_formats(
263
269
["--disable-formats" , "*,email" ],
264
270
),
265
271
)
266
- def test_disable_all_formats (runner , mock_parse_result , addargs , in_tmp_dir , tmp_path ):
272
+ def test_disable_all_formats (
273
+ cli_runner , mock_parse_result , addargs , in_tmp_dir , tmp_path
274
+ ):
267
275
touch_files (tmp_path , "foo.json" )
268
276
# this should be an override, with or without other args
269
- runner .invoke (
277
+ cli_runner .invoke (
270
278
cli_main ,
271
279
[
272
280
"--schemafile" ,
@@ -279,13 +287,13 @@ def test_disable_all_formats(runner, mock_parse_result, addargs, in_tmp_dir, tmp
279
287
280
288
281
289
def test_can_specify_custom_validator_class (
282
- runner , mock_parse_result , mock_module , in_tmp_dir , tmp_path
290
+ cli_runner , mock_parse_result , mock_module , in_tmp_dir , tmp_path
283
291
):
284
292
mock_module ("foo.py" , "class MyValidator: pass" )
285
293
import foo
286
294
287
295
touch_files (tmp_path , "foo.json" )
288
- result = runner .invoke (
296
+ result = cli_runner .invoke (
289
297
cli_main ,
290
298
[
291
299
"--schemafile" ,
@@ -303,7 +311,7 @@ def test_can_specify_custom_validator_class(
303
311
"failmode" , ("syntax" , "import" , "attr" , "function" , "non_callable" )
304
312
)
305
313
def test_custom_validator_class_fails (
306
- runner , mock_parse_result , mock_module , failmode , in_tmp_dir , tmp_path
314
+ cli_runner , mock_parse_result , mock_module , failmode , in_tmp_dir , tmp_path
307
315
):
308
316
mock_module (
309
317
"foo.py" ,
@@ -331,7 +339,7 @@ def validator_func(*args, **kwargs):
331
339
raise NotImplementedError
332
340
333
341
touch_files (tmp_path , "foo.json" )
334
- result = runner .invoke (
342
+ result = cli_runner .invoke (
335
343
cli_main ,
336
344
["--schemafile" , "schema.json" , "foo.json" , "--validator-class" , arg ],
337
345
)
0 commit comments