88from astropy .config import paths
99
1010from astroquery .query import QueryWithLogin
11- from astroquery import conf
11+ from astroquery import cache_conf
1212
1313URL1 = "http://fakeurl.edu"
1414URL2 = "http://fakeurl.ac.uk"
@@ -33,7 +33,7 @@ def get_mockreturn(url, *args, **kwargs):
3333 requests .Session .request = get_mockreturn
3434
3535
36- class TestClass (QueryWithLogin ):
36+ class CacheTestClass (QueryWithLogin ):
3737 """Bare bones class for testing caching"""
3838
3939 def test_func (self , requrl ):
@@ -42,45 +42,40 @@ def test_func(self, requrl):
4242
4343 def _login (self , username ):
4444
45- resp = self ._request (method = "GET" , url = username )
46-
47- if resp .content == "Penguin" :
48- return True
49- else :
50- return False
45+ return self ._request (method = "GET" , url = username ).content == "Penguin"
5146
5247
5348def test_conf ():
54- conf .reset ()
49+ cache_conf .reset ()
5550
56- default_timeout = conf .cache_timeout
57- default_active = conf .cache_active
51+ default_timeout = cache_conf .cache_timeout
52+ default_active = cache_conf .cache_active
5853
5954 assert default_timeout == 604800
6055 assert default_active is True
6156
62- with conf .set_temp ("cache_timeout" , 5 ):
63- assert conf .cache_timeout == 5
57+ with cache_conf .set_temp ("cache_timeout" , 5 ):
58+ assert cache_conf .cache_timeout == 5
6459
65- with conf .set_temp ("cache_active" , False ):
66- assert conf .cache_active is False
60+ with cache_conf .set_temp ("cache_active" , False ):
61+ assert cache_conf .cache_active is False
6762
68- assert conf .cache_timeout == default_timeout
69- assert conf .cache_active == default_active
63+ assert cache_conf .cache_timeout == default_timeout
64+ assert cache_conf .cache_active == default_active
7065
71- conf .cache_timeout = 5
72- conf .cache_active = False
73- conf .reset ()
66+ cache_conf .cache_timeout = 5
67+ cache_conf .cache_active = False
68+ cache_conf .reset ()
7469
75- assert conf .cache_timeout == default_timeout
76- assert conf .cache_active == default_active
70+ assert cache_conf .cache_timeout == default_timeout
71+ assert cache_conf .cache_active == default_active
7772
7873
7974def test_basic_caching ():
80- conf .reset ()
75+ cache_conf .reset ()
8176
82- mytest = TestClass ()
83- assert conf .cache_active
77+ mytest = CacheTestClass ()
78+ assert cache_conf .cache_active
8479
8580 mytest .clear_cache ()
8681 assert len (os .listdir (mytest .cache_location )) == 0
@@ -108,35 +103,35 @@ def test_basic_caching():
108103 assert resp .content == TEXT2 # Now get new response
109104
110105
111- def test_change_location (tmpdir ):
112- conf .reset ()
106+ def test_change_location (tmp_path ):
107+ cache_conf .reset ()
113108
114- mytest = TestClass ()
109+ mytest = CacheTestClass ()
115110 default_cache_location = mytest .cache_location
116111
117112 assert paths .get_cache_dir () in str (default_cache_location )
118113 assert "astroquery" in mytest .cache_location .parts
119114 assert mytest .name in mytest .cache_location .parts
120115
121- new_loc = "new_dir"
116+ new_loc = tmp_path . joinpath ( "new_dir" )
122117 mytest .cache_location = new_loc
123- assert str ( mytest .cache_location ) == new_loc
118+ assert mytest .cache_location == new_loc
124119
125120 mytest .reset_cache_location ()
126121 assert mytest .cache_location == default_cache_location
127122
128- Path ( new_loc ) .mkdir (parents = True , exist_ok = True )
123+ new_loc .mkdir (parents = True , exist_ok = True )
129124 with paths .set_temp_cache (new_loc ):
130- assert new_loc in mytest .cache_location . parts
125+ assert str ( new_loc ) in str ( mytest .cache_location )
131126 assert "astroquery" in mytest .cache_location .parts
132127 assert mytest .name in mytest .cache_location .parts
133128
134129
135130def test_login ():
136- conf .reset ()
131+ cache_conf .reset ()
137132
138- mytest = TestClass ()
139- assert conf .cache_active
133+ mytest = CacheTestClass ()
134+ assert cache_conf .cache_active
140135
141136 mytest .clear_cache ()
142137 assert len (os .listdir (mytest .cache_location )) == 0
@@ -154,15 +149,15 @@ def test_login():
154149
155150
156151def test_timeout ():
157- conf .reset ()
152+ cache_conf .reset ()
158153
159- mytest = TestClass ()
160- assert conf .cache_active
154+ mytest = CacheTestClass ()
155+ assert cache_conf .cache_active
161156
162157 mytest .clear_cache ()
163158 assert len (os .listdir (mytest .cache_location )) == 0
164159
165- conf .cache_timeout = 2 # Set to 2 sec so we can reach timeout easily
160+ cache_conf .cache_timeout = 2 # Set to 2 sec so we can reach timeout easily
166161
167162 set_response (TEXT1 ) # setting the response
168163
@@ -180,10 +175,10 @@ def test_timeout():
180175
181176
182177def test_deactivate ():
183- conf .reset ()
178+ cache_conf .reset ()
184179
185- mytest = TestClass ()
186- conf .cache_active = False
180+ mytest = CacheTestClass ()
181+ cache_conf .cache_active = False
187182
188183 mytest .clear_cache ()
189184 assert len (os .listdir (mytest .cache_location )) == 0
@@ -200,10 +195,10 @@ def test_deactivate():
200195 assert resp .content == TEXT2
201196 assert len (os .listdir (mytest .cache_location )) == 0
202197
203- conf .reset ()
204- assert conf .cache_active is True
198+ cache_conf .reset ()
199+ assert cache_conf .cache_active is True
205200
206- with conf .set_temp ('cache_active' , False ):
201+ with cache_conf .set_temp ('cache_active' , False ):
207202 mytest .clear_cache ()
208203 assert len (os .listdir (mytest .cache_location )) == 0
209204
@@ -219,4 +214,4 @@ def test_deactivate():
219214 assert resp .content == TEXT2
220215 assert len (os .listdir (mytest .cache_location )) == 0
221216
222- assert conf .cache_active is True
217+ assert cache_conf .cache_active is True
0 commit comments