File tree 1 file changed +60
-0
lines changed
1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from check_jsonschema .parsers .json5 import ENABLED as JSON5_ENABLED
6
+
7
+ SIMPLE_SCHEMA = {
8
+ "$schema" : "http://json-schema.org/draft-07/schema" ,
9
+ "properties" : {
10
+ "title" : {"type" : "string" },
11
+ },
12
+ "additionalProperties" : False ,
13
+ }
14
+ PASSING_DOCUMENT = """
15
+ // a comment
16
+ {"title": "doc one"}
17
+ """
18
+ FAILING_DOCUMENT = """
19
+ // a comment
20
+ {"title": 2}
21
+ """
22
+
23
+
24
+ @pytest .mark .skipif (not JSON5_ENABLED , reason = "test requires json5" )
25
+ @pytest .mark .parametrize ("passing_data" , [True , False ])
26
+ def test_json5_filetype_forced_on_json_suffixed_instance (
27
+ run_line , tmp_path , passing_data
28
+ ):
29
+ schemafile = tmp_path / "schema.json"
30
+ schemafile .write_text (json .dumps (SIMPLE_SCHEMA ))
31
+
32
+ doc = tmp_path / "doc.json"
33
+ if passing_data :
34
+ doc .write_text (PASSING_DOCUMENT )
35
+ else :
36
+ doc .write_text (FAILING_DOCUMENT )
37
+
38
+ result = run_line (
39
+ [
40
+ "check-jsonschema" ,
41
+ "--force-filetype" ,
42
+ "json5" ,
43
+ "--schemafile" ,
44
+ str (schemafile ),
45
+ str (doc ),
46
+ ]
47
+ )
48
+ assert result .exit_code == (0 if passing_data else 1 )
49
+
50
+ # but even in the passing case, a rerun without the force flag will fail
51
+ if passing_data :
52
+ result_without_filetype = run_line (
53
+ [
54
+ "check-jsonschema" ,
55
+ "--schemafile" ,
56
+ str (schemafile ),
57
+ str (doc ),
58
+ ]
59
+ )
60
+ assert result_without_filetype .exit_code == 1
You can’t perform that action at this time.
0 commit comments