@@ -79,13 +79,50 @@ 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 .parametrize (
107+ "filename, force_filetype" ,
108+ [
109+ ("foo.test" , "json5" ),
110+ ("foo.json" , "json5" ),
111+ ],
112+ )
113+ def test_instanceloader_force_filetype_json (
114+ tmp_path , filename , force_filetype , open_wide
115+ ):
116+ if not JSON5_ENABLED :
117+ pytest .skip ("test requires json5" )
118+ f = tmp_path / filename
119+ f .write_text ("// a comment\n {}" )
120+ loader = InstanceLoader (open_wide (f ), force_filetype = force_filetype )
121+ data = list (loader .iter_files ())
122+ print (data )
123+ assert data == [(str (f ), {})]
124+
125+
89126def test_instanceloader_unknown_type_nonjson_content (tmp_path , open_wide ):
90127 f = tmp_path / "foo" # no extension here
91128 f .write_text ("a:b" ) # non-json data (cannot be detected as JSON)
0 commit comments