Skip to content

Commit 7511388

Browse files
committed
TST: Add tests for trying to read non-existent files pandas-dev#15296
1 parent 3b02e73 commit 7511388

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/io/test_common.py

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ def test_iterator(self):
125125
tm.assert_frame_equal(first, expected.iloc[[0]])
126126
tm.assert_frame_equal(concat(it), expected.iloc[1:])
127127

128+
@pytest.mark.parametrize('reader, module, error_class, fn_ext', [
129+
(pd.read_csv, 'os', pd.compat.FileNotFoundError, 'csv'),
130+
(pd.read_table, 'os', pd.compat.FileNotFoundError, 'csv'),
131+
(pd.read_fwf, 'os', pd.compat.FileNotFoundError, 'txt'),
132+
(pd.read_excel, 'xlrd', ValueError, 'xlsx'),
133+
(pd.read_feather, 'feather', ValueError, 'feather'),
134+
(pd.read_hdf, 'tables', ValueError, 'h5'),
135+
(pd.read_stata, 'os', pd.compat.FileNotFoundError, 'dta'),
136+
(pd.read_sas, 'os', pd.compat.FileNotFoundError, 'sas7bdat'),
137+
(pd.read_json, 'os', ValueError, 'json'),
138+
(pd.read_msgpack, 'os', ValueError, 'mp'),
139+
(pd.read_pickle, 'os', pd.compat.FileNotFoundError, 'pickle'),
140+
])
141+
def test_read_non_existant(self, reader, module, error_class, fn_ext):
142+
pytest.importorskip(module)
143+
144+
path = os.path.join(HERE, 'data', 'does_not_exist.' + fn_ext)
145+
with pytest.raises(error_class):
146+
reader(path)
147+
128148
@pytest.mark.parametrize('reader, module, path', [
129149
(pd.read_csv, 'os', os.path.join(HERE, 'data', 'iris.csv')),
130150
(pd.read_table, 'os', os.path.join(HERE, 'data', 'iris.csv')),

0 commit comments

Comments
 (0)