From f2094a5693eee5aa5d807a08e1f66bb209b0e271 Mon Sep 17 00:00:00 2001 From: Debian Science Maintainers Date: Sat, 5 Oct 2024 11:43:25 +0100 Subject: [PATCH] Don't try to write to the source directory Not allowed in autopkgtest Author: Rebecca N. Palmer Forwarded: no Gbp-Pq: Name use_tmp_path.patch --- statsmodels/datasets/tests/test_utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/statsmodels/datasets/tests/test_utils.py b/statsmodels/datasets/tests/test_utils.py index 2af7de4..edd0f4a 100644 --- a/statsmodels/datasets/tests/test_utils.py +++ b/statsmodels/datasets/tests/test_utils.py @@ -9,8 +9,6 @@ import pytest from statsmodels.compat.python import PYTHON_IMPL_WASM from statsmodels.datasets import get_rdataset, webuse, check_internet, utils -cur_dir = os.path.dirname(os.path.abspath(__file__)) - IGNORED_EXCEPTIONS = (HTTPError, URLError, UnicodeEncodeError, timeout) if not PYTHON_IMPL_WASM: from ssl import SSLError @@ -18,38 +16,38 @@ if not PYTHON_IMPL_WASM: @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(): -- 2.30.2