@@ -79,13 +79,50 @@ 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 .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
+
89
126
def test_instanceloader_unknown_type_nonjson_content (tmp_path , open_wide ):
90
127
f = tmp_path / "foo" # no extension here
91
128
f .write_text ("a:b" ) # non-json data (cannot be detected as JSON)
0 commit comments