|
11 | 11 |
|
12 | 12 | import pytest |
13 | 13 |
|
| 14 | +from astropy.config.paths import set_temp_cache |
14 | 15 | from astropy.utils.data import (_get_download_cache_locs, CacheMissingWarning, |
15 | 16 | get_pkg_data_filename, get_readable_fileobj, conf) |
16 | 17 |
|
@@ -111,36 +112,37 @@ def test_download_noprogress(): |
111 | 112 |
|
112 | 113 |
|
113 | 114 | @pytest.mark.remote_data(source='astropy') |
114 | | -def test_download_cache(): |
| 115 | +def test_download_cache(tmpdir): |
115 | 116 |
|
116 | 117 | from astropy.utils.data import download_file, clear_download_cache |
117 | 118 |
|
118 | | - download_dir = _get_download_cache_locs()[0] |
119 | | - |
120 | | - # Download the test URL and make sure it exists, then clear just that |
121 | | - # URL and make sure it got deleted. |
122 | | - fnout = download_file(TESTURL, cache=True) |
123 | | - assert os.path.isdir(download_dir) |
124 | | - assert os.path.isfile(fnout) |
125 | | - clear_download_cache(TESTURL) |
126 | | - assert not os.path.exists(fnout) |
127 | | - |
128 | | - # Test issues raised in #4427 with clear_download_cache() without a URL, |
129 | | - # followed by subsequent download. |
130 | | - fnout = download_file(TESTURL, cache=True) |
131 | | - assert os.path.isfile(fnout) |
132 | | - clear_download_cache() |
133 | | - assert not os.path.exists(fnout) |
134 | | - assert not os.path.exists(download_dir) |
135 | | - fnout = download_file(TESTURL, cache=True) |
136 | | - assert os.path.isfile(fnout) |
137 | | - |
138 | | - # Clearing download cache succeeds even if the URL does not exist. |
139 | | - clear_download_cache('http://this_was_never_downloaded_before.com') |
140 | | - |
141 | | - # Make sure lockdir was released |
142 | | - lockdir = os.path.join(download_dir, 'lock') |
143 | | - assert not os.path.isdir(lockdir), 'Cache dir lock was not released!' |
| 119 | + with set_temp_cache(tmpdir): |
| 120 | + download_dir = _get_download_cache_locs()[0] |
| 121 | + |
| 122 | + # Download the test URL and make sure it exists, then clear just that |
| 123 | + # URL and make sure it got deleted. |
| 124 | + fnout = download_file(TESTURL, cache=True) |
| 125 | + assert os.path.isdir(download_dir) |
| 126 | + assert os.path.isfile(fnout) |
| 127 | + clear_download_cache(TESTURL) |
| 128 | + assert not os.path.exists(fnout) |
| 129 | + |
| 130 | + # Test issues raised in #4427 with clear_download_cache() without a |
| 131 | + # URL, followed by subsequent download. |
| 132 | + fnout = download_file(TESTURL, cache=True) |
| 133 | + assert os.path.isfile(fnout) |
| 134 | + clear_download_cache() |
| 135 | + assert not os.path.exists(fnout) |
| 136 | + assert not os.path.exists(download_dir) |
| 137 | + fnout = download_file(TESTURL, cache=True) |
| 138 | + assert os.path.isfile(fnout) |
| 139 | + |
| 140 | + # Clearing download cache succeeds even if the URL does not exist. |
| 141 | + clear_download_cache('http://this_was_never_downloaded_before.com') |
| 142 | + |
| 143 | + # Make sure lockdir was released |
| 144 | + lockdir = os.path.join(download_dir, 'lock') |
| 145 | + assert not os.path.isdir(lockdir), 'Cache dir lock was not released!' |
144 | 146 |
|
145 | 147 |
|
146 | 148 | @pytest.mark.remote_data(source='astropy') |
|
0 commit comments