@@ -79,13 +79,49 @@ def test_instanceloader_yaml_data(tmp_path, filename, default_filetype, open_wid
79
79
],
80
80
)
81
81
def test_instanceloader_toml_data (tmp_path , filename , default_filetype , open_wide ):
82
- f = tmp_path / "foo.toml"
82
+ f = tmp_path / filename
83
83
f .write_text ('[foo]\n bar = "baz"\n ' )
84
84
loader = InstanceLoader (open_wide (f ), default_filetype = default_filetype )
85
85
data = list (loader .iter_files ())
86
86
assert data == [(str (f ), {"foo" : {"bar" : "baz" }})]
87
87
88
88
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
+
89
125
def test_instanceloader_unknown_type_nonjson_content (tmp_path , open_wide ):
90
126
f = tmp_path / "foo" # no extension here
91
127
f .write_text ("a:b" ) # non-json data (cannot be detected as JSON)
0 commit comments