8
8
from astropy .config import paths
9
9
10
10
from astroquery .query import QueryWithLogin
11
- from astroquery import conf
11
+ from astroquery import cache_conf
12
12
13
13
URL1 = "http://fakeurl.edu"
14
14
URL2 = "http://fakeurl.ac.uk"
@@ -33,7 +33,7 @@ def get_mockreturn(url, *args, **kwargs):
33
33
requests .Session .request = get_mockreturn
34
34
35
35
36
- class TestClass (QueryWithLogin ):
36
+ class CacheTestClass (QueryWithLogin ):
37
37
"""Bare bones class for testing caching"""
38
38
39
39
def test_func (self , requrl ):
@@ -42,45 +42,40 @@ def test_func(self, requrl):
42
42
43
43
def _login (self , username ):
44
44
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"
51
46
52
47
53
48
def test_conf ():
54
- conf .reset ()
49
+ cache_conf .reset ()
55
50
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
58
53
59
54
assert default_timeout == 604800
60
55
assert default_active is True
61
56
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
64
59
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
67
62
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
70
65
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 ()
74
69
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
77
72
78
73
79
74
def test_basic_caching ():
80
- conf .reset ()
75
+ cache_conf .reset ()
81
76
82
- mytest = TestClass ()
83
- assert conf .cache_active
77
+ mytest = CacheTestClass ()
78
+ assert cache_conf .cache_active
84
79
85
80
mytest .clear_cache ()
86
81
assert len (os .listdir (mytest .cache_location )) == 0
@@ -108,35 +103,35 @@ def test_basic_caching():
108
103
assert resp .content == TEXT2 # Now get new response
109
104
110
105
111
- def test_change_location (tmpdir ):
112
- conf .reset ()
106
+ def test_change_location (tmp_path ):
107
+ cache_conf .reset ()
113
108
114
- mytest = TestClass ()
109
+ mytest = CacheTestClass ()
115
110
default_cache_location = mytest .cache_location
116
111
117
112
assert paths .get_cache_dir () in str (default_cache_location )
118
113
assert "astroquery" in mytest .cache_location .parts
119
114
assert mytest .name in mytest .cache_location .parts
120
115
121
- new_loc = "new_dir"
116
+ new_loc = tmp_path . joinpath ( "new_dir" )
122
117
mytest .cache_location = new_loc
123
- assert str ( mytest .cache_location ) == new_loc
118
+ assert mytest .cache_location == new_loc
124
119
125
120
mytest .reset_cache_location ()
126
121
assert mytest .cache_location == default_cache_location
127
122
128
- Path ( new_loc ) .mkdir (parents = True , exist_ok = True )
123
+ new_loc .mkdir (parents = True , exist_ok = True )
129
124
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 )
131
126
assert "astroquery" in mytest .cache_location .parts
132
127
assert mytest .name in mytest .cache_location .parts
133
128
134
129
135
130
def test_login ():
136
- conf .reset ()
131
+ cache_conf .reset ()
137
132
138
- mytest = TestClass ()
139
- assert conf .cache_active
133
+ mytest = CacheTestClass ()
134
+ assert cache_conf .cache_active
140
135
141
136
mytest .clear_cache ()
142
137
assert len (os .listdir (mytest .cache_location )) == 0
@@ -154,15 +149,15 @@ def test_login():
154
149
155
150
156
151
def test_timeout ():
157
- conf .reset ()
152
+ cache_conf .reset ()
158
153
159
- mytest = TestClass ()
160
- assert conf .cache_active
154
+ mytest = CacheTestClass ()
155
+ assert cache_conf .cache_active
161
156
162
157
mytest .clear_cache ()
163
158
assert len (os .listdir (mytest .cache_location )) == 0
164
159
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
166
161
167
162
set_response (TEXT1 ) # setting the response
168
163
@@ -180,10 +175,10 @@ def test_timeout():
180
175
181
176
182
177
def test_deactivate ():
183
- conf .reset ()
178
+ cache_conf .reset ()
184
179
185
- mytest = TestClass ()
186
- conf .cache_active = False
180
+ mytest = CacheTestClass ()
181
+ cache_conf .cache_active = False
187
182
188
183
mytest .clear_cache ()
189
184
assert len (os .listdir (mytest .cache_location )) == 0
@@ -200,10 +195,10 @@ def test_deactivate():
200
195
assert resp .content == TEXT2
201
196
assert len (os .listdir (mytest .cache_location )) == 0
202
197
203
- conf .reset ()
204
- assert conf .cache_active is True
198
+ cache_conf .reset ()
199
+ assert cache_conf .cache_active is True
205
200
206
- with conf .set_temp ('cache_active' , False ):
201
+ with cache_conf .set_temp ('cache_active' , False ):
207
202
mytest .clear_cache ()
208
203
assert len (os .listdir (mytest .cache_location )) == 0
209
204
@@ -219,4 +214,4 @@ def test_deactivate():
219
214
assert resp .content == TEXT2
220
215
assert len (os .listdir (mytest .cache_location )) == 0
221
216
222
- assert conf .cache_active is True
217
+ assert cache_conf .cache_active is True
0 commit comments