@@ -79,13 +79,49 @@ def test_instanceloader_yaml_data(tmp_path, filename, default_filetype, open_wid
7979 ],
8080)
8181def test_instanceloader_toml_data (tmp_path , filename , default_filetype , open_wide ):
82- f = tmp_path / "foo.toml"
82+ f = tmp_path / filename
8383 f .write_text ('[foo]\n bar = "baz"\n ' )
8484 loader = InstanceLoader (open_wide (f ), default_filetype = default_filetype )
8585 data = list (loader .iter_files ())
8686 assert data == [(str (f ), {"foo" : {"bar" : "baz" }})]
8787
8888
89+ @pytest .mark .parametrize (
90+ "filename, force_filetype" ,
91+ [
92+ ("foo.test" , "toml" ),
93+ ("foo" , "toml" ),
94+ ],
95+ )
96+ def test_instanceloader_force_filetype_toml (
97+ tmp_path , filename , force_filetype , open_wide
98+ ):
99+ f = tmp_path / filename
100+ f .write_text ('[foo]\n bar = "baz"\n ' )
101+ loader = InstanceLoader (open_wide (f ), force_filetype = force_filetype )
102+ data = list (loader .iter_files ())
103+ assert data == [(str (f ), {"foo" : {"bar" : "baz" }})]
104+
105+
106+ @pytest .mark .skipif (not JSON5_ENABLED , reason = "test requires json5" )
107+ @pytest .mark .parametrize (
108+ "filename, force_filetype" ,
109+ [
110+ ("foo.test" , "json5" ),
111+ ("foo.json" , "json5" ),
112+ ],
113+ )
114+ def test_instanceloader_force_filetype_json (
115+ tmp_path , filename , force_filetype , open_wide
116+ ):
117+ f = tmp_path / filename
118+ f .write_text ("// a comment\n {}" )
119+ loader = InstanceLoader (open_wide (f ), force_filetype = force_filetype )
120+ data = list (loader .iter_files ())
121+ print (data )
122+ assert data == [(str (f ), {})]
123+
124+
89125def test_instanceloader_unknown_type_nonjson_content (tmp_path , open_wide ):
90126 f = tmp_path / "foo" # no extension here
91127 f .write_text ("a:b" ) # non-json data (cannot be detected as JSON)
0 commit comments