11# test on a JavaScript regex which is not a valid python regex
2- # `--format-regex=disabled` should skip
32# `--format-regex=default` should accept it
43# `--format-regex=python` should reject it
54#
3938}
4039
4140
42- @pytest .fixture (params = ["disabled" , "default" , "python" ])
43- def regexopt (request ):
41+ @pytest .fixture (
42+ params = [
43+ ("--disable-formats" , "regex" ),
44+ ("--format-regex" , "default" ),
45+ ("--format-regex" , "python" ),
46+ ]
47+ )
48+ def regexopts (request ):
4449 return request .param
4550
4651
47- def test_regex_format_good (run_line_simple , tmp_path , regexopt ):
52+ def test_regex_format_good (run_line_simple , tmp_path , regexopts ):
4853 schemafile = tmp_path / "schema.json"
4954 schemafile .write_text (json .dumps (FORMAT_SCHEMA ))
5055
5156 doc = tmp_path / "doc.json"
5257 doc .write_text (json .dumps (ALWAYS_PASSING_DOCUMENT ))
5358
54- run_line_simple (
55- ["--format-regex" , regexopt , "--schemafile" , str (schemafile ), str (doc )]
56- )
59+ run_line_simple ([* regexopts , "--schemafile" , str (schemafile ), str (doc )])
5760
5861
59- def test_regex_format_accepts_non_str_inputs (run_line_simple , tmp_path , regexopt ):
62+ def test_regex_format_accepts_non_str_inputs (run_line_simple , tmp_path , regexopts ):
6063 # potentially confusing, but a format checker is allowed to check non-str instances
6164 # validate the format checker behavior on such a case
6265 schemafile = tmp_path / "schema.json"
@@ -70,25 +73,22 @@ def test_regex_format_accepts_non_str_inputs(run_line_simple, tmp_path, regexopt
7073 )
7174 doc = tmp_path / "doc.json"
7275 doc .write_text (json .dumps ({"pattern" : 0 }))
73- run_line_simple (
74- ["--format-regex" , regexopt , "--schemafile" , str (schemafile ), str (doc )]
75- )
76+ run_line_simple ([* regexopts , "--schemafile" , str (schemafile ), str (doc )])
7677
7778
78- def test_regex_format_bad (run_line , tmp_path , regexopt ):
79+ def test_regex_format_bad (run_line , tmp_path , regexopts ):
7980 schemafile = tmp_path / "schema.json"
8081 schemafile .write_text (json .dumps (FORMAT_SCHEMA ))
8182
8283 doc = tmp_path / "doc.json"
8384 doc .write_text (json .dumps (ALWAYS_FAILING_DOCUMENT ))
8485
85- expect_ok = regexopt == "disabled"
86+ expect_ok = regexopts == ( "--disable-formats" , "regex" )
8687
8788 res = run_line (
8889 [
8990 "check-jsonschema" ,
90- "--format-regex" ,
91- regexopt ,
91+ * regexopts ,
9292 "--schemafile" ,
9393 str (schemafile ),
9494 str (doc ),
@@ -101,20 +101,19 @@ def test_regex_format_bad(run_line, tmp_path, regexopt):
101101 assert "is not a 'regex'" in res .stdout
102102
103103
104- def test_regex_format_js_specific (run_line , tmp_path , regexopt ):
104+ def test_regex_format_js_specific (run_line , tmp_path , regexopts ):
105105 schemafile = tmp_path / "schema.json"
106106 schemafile .write_text (json .dumps (FORMAT_SCHEMA ))
107107
108108 doc = tmp_path / "doc.json"
109109 doc .write_text (json .dumps (JS_REGEX_DOCUMENT ))
110110
111- expect_ok = regexopt in ("disabled " , "default " )
111+ expect_ok = regexopts != ("--format-regex " , "python " )
112112
113113 res = run_line (
114114 [
115115 "check-jsonschema" ,
116- "--format-regex" ,
117- regexopt ,
116+ * regexopts ,
118117 "--schemafile" ,
119118 str (schemafile ),
120119 str (doc ),
0 commit comments