from statsmodels.datasets import get_rdataset, webuse, check_internet, utils
-cur_dir = os.path.dirname(os.path.abspath(__file__))
-
IGNORED_EXCEPTIONS = (HTTPError, URLError, SSLError, UnicodeEncodeError,
timeout)
@pytest.mark.smoke
-def test_get_rdataset():
+def test_get_rdataset(tmp_path):
test_url = "https://raw.githubusercontent.com/vincentarelbundock/" \
"Rdatasets/master/csv/datasets/cars.csv"
internet_available = check_internet(test_url)
if not internet_available: # pragma: no cover
pytest.skip('Unable to retrieve file - skipping test')
try:
- duncan = get_rdataset("Duncan", "carData", cache=cur_dir)
+ duncan = get_rdataset("Duncan", "carData", cache=tmp_path)
except IGNORED_EXCEPTIONS:
pytest.skip('Failed with HTTPError or URLError, these are random')
assert_(isinstance(duncan, utils.Dataset))
- duncan = get_rdataset("Duncan", "carData", cache=cur_dir)
+ duncan = get_rdataset("Duncan", "carData", cache=tmp_path)
assert_(duncan.from_cache)
@pytest.mark.smoke
-def test_get_rdataset_write_read_cache():
+def test_get_rdataset_write_read_cache(tmp_path):
# test writing and reading cache
try:
- guerry = get_rdataset("Guerry", "HistData", cache=cur_dir)
+ guerry = get_rdataset("Guerry", "HistData", cache=tmp_path)
except IGNORED_EXCEPTIONS:
pytest.skip('Failed with HTTPError or URLError, these are random')
assert_(guerry.from_cache is False)
- guerry2 = get_rdataset("Guerry", "HistData", cache=cur_dir)
+ guerry2 = get_rdataset("Guerry", "HistData", cache=tmp_path)
assert_(guerry2.from_cache is True)
fn = "raw.githubusercontent.com,vincentarelbundock,Rdatasets,master,csv," \
"HistData,Guerry-v2.csv.zip"
- os.remove(os.path.join(cur_dir, fn))
+ os.remove(os.path.join(tmp_path, fn))
fn = "raw.githubusercontent.com,vincentarelbundock,Rdatasets,master,doc," \
"HistData,rst,Guerry-v2.rst.zip"
- os.remove(os.path.join(cur_dir, fn))
+ os.remove(os.path.join(tmp_path, fn))
def test_webuse():