@@ -137,19 +137,24 @@ def test_get_pkg_data_contents():
137137@remote_data
138138def test_data_noastropy_fallback (monkeypatch , recwarn ):
139139 """
140- Tests to make sure configuration items fall back to their defaults when
141- there's a problem accessing the astropy directory
140+ Tests to make sure the default behavior when the cache directory can't
141+ be located is correct
142142 """
143143 from pytest import raises
144144 from .. import data
145145 from ...config import paths
146146
147+ # needed for testing the *real* lock at the end
148+ lockdir = os .path .join (_get_download_cache_locs ()[0 ], 'lock' )
149+
147150 #better yet, set the configuration to make sure the temp files are deleted
148151 data .DELETE_TEMPORARY_DOWNLOADS_AT_EXIT .set (True )
149152
150- #make sure the config directory is not searched
153+ #make sure the config and cache directories are not searched
151154 monkeypatch .setenv ('XDG_CONFIG_HOME' , 'foo' )
152155 monkeypatch .delenv ('XDG_CONFIG_HOME' )
156+ monkeypatch .setenv ('XDG_CACHE_HOME' , 'bar' )
157+ monkeypatch .delenv ('XDG_CACHE_HOME' )
153158
154159 # make sure the _find_or_create_astropy_dir function fails as though the
155160 # astropy dir could not be accessed
@@ -162,7 +167,7 @@ def osraiser(dirnm, linkto):
162167 paths .get_cache_dir ()
163168
164169 #first try with cache
165- fnout = data .get_pkg_data_filename (TESTURL )
170+ fnout = data .download_file (TESTURL , cache = True )
166171 assert os .path .isfile (fnout )
167172
168173 assert len (recwarn .list ) > 1
@@ -172,7 +177,7 @@ def osraiser(dirnm, linkto):
172177 assert w1 .category == data .CacheMissingWarning
173178 assert 'Remote data cache could not be accessed' in w1 .message .args [0 ]
174179 assert w2 .category == data .CacheMissingWarning
175- assert 'File downloaded to temp file ' in w2 .message .args [0 ]
180+ assert 'File downloaded to temporary location ' in w2 .message .args [0 ]
176181 assert fnout == w2 .message .args [1 ]
177182
178183 #clearing the cache should be a no-up that doesn't affect fnout
@@ -192,13 +197,14 @@ def osraiser(dirnm, linkto):
192197 assert 'Not clearing data cache - cache inacessable' in str (w3 .message )
193198
194199 #now try with no cache
195- with data .get_pkg_data_fileobj (TESTURL , cache = False ) as googlepage :
200+ fnnocache = data .download_file (TESTURL , cache = False )
201+ with open (fnnocache ) as googlepage :
196202 assert googlepage .read ().decode ().find ('oogle</title>' ) > - 1
197203
198204 #no warnings should be raise in fileobj because cache is unnecessary
199205 assert len (recwarn .list ) == 0
200206
201- lockdir = os . path . join ( _get_download_cache_locs ()[ 0 ], 'lock' )
207+ # lockdir determined above as the *real* lockdir, not the temp one
202208 assert not os .path .isdir (lockdir ), 'Cache dir lock was not released!'
203209
204210
0 commit comments