Don't try to write to the source directory
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Tue, 12 Dec 2023 20:07:17 +0000 (20:07 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Tue, 12 Dec 2023 20:07:17 +0000 (20:07 +0000)
Not allowed in autopkgtest

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: no

Gbp-Pq: Name use_tmp_path.patch

statsmodels/datasets/tests/test_utils.py

index cf8458c815399ec12e8430dba9600447dd780826..990a2e391da50a0c331d5036d4dd27541e67b71a 100644 (file)
@@ -9,45 +9,43 @@ import pytest
 
 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():