33from check_jsonschema .instance_loader import InstanceLoader
44from check_jsonschema .parsers import BadFileTypeError , FailedFileLoadError
55from check_jsonschema .parsers .json5 import ENABLED as JSON5_ENABLED
6- from check_jsonschema .parsers .toml import ENABLED as TOML_ENABLED
76
87
98# handy helper for opening multiple files for InstanceLoader
@@ -70,6 +69,23 @@ def test_instanceloader_yaml_data(tmp_path, filename, default_filetype, open_wid
7069 assert data == [(str (f ), {"a" : {"b" : [1 , 2 ], "c" : "d" }})]
7170
7271
72+ @pytest .mark .parametrize (
73+ "filename, default_filetype" ,
74+ [
75+ ("foo.toml" , "notarealfiletype" ),
76+ ("foo.toml" , "json" ),
77+ ("foo.toml" , "yaml" ),
78+ ("foo" , "toml" ),
79+ ],
80+ )
81+ def test_instanceloader_toml_data (tmp_path , filename , default_filetype , open_wide ):
82+ f = tmp_path / "foo.toml"
83+ f .write_text ('[foo]\n bar = "baz"\n ' )
84+ loader = InstanceLoader (open_wide (f ), default_filetype = default_filetype )
85+ data = list (loader .iter_files ())
86+ assert data == [(str (f ), {"foo" : {"bar" : "baz" }})]
87+
88+
7389def test_instanceloader_unknown_type_nonjson_content (tmp_path , open_wide ):
7490 f = tmp_path / "foo" # no extension here
7591 f .write_text ("a:b" ) # non-json data (cannot be detected as JSON)
@@ -93,13 +109,6 @@ def test_instanceloader_unknown_type_nonjson_content(tmp_path, open_wide):
93109 {},
94110 "pip install json5" ,
95111 ),
96- (
97- TOML_ENABLED ,
98- "toml" ,
99- '[foo]\n bar = "baz"\n ' ,
100- {"foo" : {"bar" : "baz" }},
101- "pip install tomli" ,
102- ),
103112 ],
104113)
105114def test_instanceloader_optional_format_handling (
@@ -162,8 +171,6 @@ def test_instanceloader_invalid_data(
162171):
163172 if file_format == "json5" and not JSON5_ENABLED :
164173 pytest .skip ("test requires 'json5' support" )
165- if file_format == "toml" and not TOML_ENABLED :
166- pytest .skip ("test requires 'toml' support" )
167174
168175 f = tmp_path / filename
169176 f .write_text (content )
@@ -211,8 +218,6 @@ def test_instanceloader_invalid_data_mixed_with_valid_data(tmp_path, open_wide):
211218def test_instanceloader_mixed_filetypes (tmp_path , filetypes , open_wide ):
212219 if not JSON5_ENABLED and "json5" in filetypes :
213220 pytest .skip ("test requires json5" )
214- if not TOML_ENABLED and "toml" in filetypes :
215- pytest .skip ("test requires toml" )
216221 files = {}
217222 file_order = []
218223 if "json" in filetypes :
0 commit comments