Skip to content

Commit b55eb43

Browse files
committed
integrating better with astropy config framework
1 parent 2589b8a commit b55eb43

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

astroquery/query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def _request(self, method, url,
338338
# ":" so replace them with an underscore
339339
local_filename = local_filename.replace(':', '_')
340340

341-
local_filepath = os.path.join(savedir or self.cache_location or '.', local_filename)
341+
local_filepath = os.path.join(savedir or self._cache_location or '.', local_filename)
342342

343343
response = self._download_file(url, local_filepath, cache=cache, timeout=timeout,
344344
continuation=continuation, method=method,
@@ -361,15 +361,16 @@ def _request(self, method, url,
361361
json=json)
362362
else:
363363
response = query.from_cache(self.cache_location, cache_conf.cache_timeout)
364+
364365
if not response:
365366
response = query.request(self._session,
366-
self.cache_location,
367+
self._cache_location,
367368
stream=stream,
368369
auth=auth,
369370
allow_redirects=allow_redirects,
370371
verify=verify,
371372
json=json)
372-
to_cache(response, query.request_file(self.cache_location))
373+
to_cache(response, query.request_file(self._cache_location))
373374

374375
self._last_query = query
375376
return response
@@ -514,6 +515,7 @@ def __exit__(self, exc_type, exc_value, traceback):
514515
return False
515516

516517

518+
517519
class QueryWithLogin(BaseQuery):
518520
"""
519521
This is the base class for all the query classes which are required to

astroquery/tests/test_cache.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from astroquery.query import QueryWithLogin
1111
from astroquery import cache_conf
1212

13+
1314
URL1 = "http://fakeurl.edu"
1415
URL2 = "http://fakeurl.ac.uk"
1516

@@ -82,22 +83,22 @@ def test_basic_caching(changing_mocked_response):
8283
assert cache_conf.cache_active
8384

8485
mytest.clear_cache()
85-
assert len(os.listdir(mytest.cache_location)) == 0
86+
assert len(os.listdir(mytest.get_cache_location())) == 0
8687

8788
resp = mytest.test_func(URL1)
8889
assert resp.content == TEXT1
89-
assert len(os.listdir(mytest.cache_location)) == 1
90+
assert len(os.listdir(mytest.get_cache_location())) == 1
9091

9192
resp = mytest.test_func(URL2) # query that has not been cached
9293
assert resp.content == TEXT2
93-
assert len(os.listdir(mytest.cache_location)) == 2
94+
assert len(os.listdir(mytest.get_cache_location())) == 2
9495

9596
resp = mytest.test_func(URL1)
9697
assert resp.content == TEXT1 # query that was cached
97-
assert len(os.listdir(mytest.cache_location)) == 2 # no new cache file
98+
assert len(os.listdir(mytest.get_cache_location())) == 2 # no new cache file
9899

99100
mytest.clear_cache()
100-
assert len(os.listdir(mytest.cache_location)) == 0
101+
assert len(os.listdir(mytest.get_cache_location())) == 0
101102

102103
resp = mytest.test_func(URL1)
103104
assert resp.content == TEXT2 # Now get new response
@@ -134,11 +135,11 @@ def test_login(changing_mocked_response):
134135
assert cache_conf.cache_active
135136

136137
mytest.clear_cache()
137-
assert len(os.listdir(mytest.cache_location)) == 0
138+
assert len(os.listdir(mytest.get_cache_location())) == 0
138139

139140
mytest.login("ceb")
140141
assert mytest.authenticated()
141-
assert len(os.listdir(mytest.cache_location)) == 0 # request should not be cached
142+
assert len(os.listdir(mytest.get_cache_location())) == 0 # request should not be cached
142143

143144
mytest.login("ceb")
144145
assert not mytest.authenticated() # Should not be accessing cache
@@ -151,7 +152,7 @@ def test_timeout(changing_mocked_response, monkeypatch):
151152
assert cache_conf.cache_active
152153

153154
mytest.clear_cache()
154-
assert len(os.listdir(mytest.cache_location)) == 0
155+
assert len(os.listdir(mytest.get_cache_location())) == 0
155156

156157
resp = mytest.test_func(URL1) # should be cached
157158
assert resp.content == TEXT1
@@ -183,11 +184,11 @@ def test_deactivate_directly(changing_mocked_response):
183184
cache_conf.cache_active = False
184185

185186
mytest.clear_cache()
186-
assert len(os.listdir(mytest.cache_location)) == 0
187+
assert len(os.listdir(mytest.get_cache_location())) == 0
187188

188189
resp = mytest.test_func(URL1)
189190
assert resp.content == TEXT1
190-
assert len(os.listdir(mytest.cache_location)) == 0
191+
assert len(os.listdir(mytest.get_cache_location())) == 0
191192

192193
resp = mytest.test_func(URL1)
193194
assert resp.content == TEXT2

0 commit comments

Comments
 (0)