|
3 | 3 | """
|
4 | 4 | import mmap
|
5 | 5 | import os
|
| 6 | +import re |
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 |
|
@@ -148,6 +149,31 @@ def test_read_non_existant(self, reader, module, error_class, fn_ext):
|
148 | 149 | with pytest.raises(error_class):
|
149 | 150 | reader(path)
|
150 | 151 |
|
| 152 | + @pytest.mark.parametrize('reader, module, error_class, fn_ext', [ |
| 153 | + (pd.read_csv, 'os', FileNotFoundError, 'csv'), |
| 154 | + (pd.read_fwf, 'os', FileNotFoundError, 'txt'), |
| 155 | + (pd.read_excel, 'xlrd', FileNotFoundError, 'xlsx'), |
| 156 | + (pd.read_feather, 'feather', Exception, 'feather'), |
| 157 | + (pd.read_hdf, 'tables', FileNotFoundError, 'h5'), |
| 158 | + (pd.read_stata, 'os', FileNotFoundError, 'dta'), |
| 159 | + (pd.read_sas, 'os', FileNotFoundError, 'sas7bdat'), |
| 160 | + (pd.read_json, 'os', ValueError, 'json'), |
| 161 | + (pd.read_msgpack, 'os', ValueError, 'mp'), |
| 162 | + (pd.read_pickle, 'os', FileNotFoundError, 'pickle'), |
| 163 | + ]) |
| 164 | + def test_read_expands_user_home_dir(self, reader, module, |
| 165 | + error_class, fn_ext, monkeypatch): |
| 166 | + pytest.importorskip(module) |
| 167 | + |
| 168 | + path = os.path.join('~', 'does_not_exist.' + fn_ext) |
| 169 | + monkeypatch.setattr(icom, '_expand_user', |
| 170 | + lambda x: os.path.join('foo', x)) |
| 171 | + |
| 172 | + message = "".join(["foo", os.path.sep, "does_not_exist.", fn_ext]) |
| 173 | + |
| 174 | + with pytest.raises(error_class, message=re.escape(message)): |
| 175 | + reader(path) |
| 176 | + |
151 | 177 | def test_read_non_existant_read_table(self):
|
152 | 178 | path = os.path.join(HERE, 'data', 'does_not_exist.' + 'csv')
|
153 | 179 | with pytest.raises(FileNotFoundError):
|
|
0 commit comments