16
16
from astropy .io .votable import parse
17
17
from astroquery .utils .commons import parse_coordinates , FileContainer
18
18
from astropy import units as u
19
- from astropy .utils .exceptions import AstropyDeprecationWarning
20
19
import pytest
21
20
import tempfile
22
21
import requests
23
- try :
24
- pyvo_OK = True
25
- from pyvo .auth import authsession , securitymethods
26
- from astroquery .cadc import Cadc , conf
27
- import astroquery .cadc .core as cadc_core
28
- except ImportError :
29
- pyvo_OK = False
30
- pytest .skip ("Install pyvo for the cadc module." , allow_module_level = True )
31
- except AstropyDeprecationWarning as ex :
32
- if str (ex ) == \
33
- 'The astropy.vo.samp module has now been moved to astropy.samp' :
34
- print ('AstropyDeprecationWarning: {}' .format (str (ex )))
35
- else :
36
- raise ex
37
- try :
38
- from unittest .mock import Mock , patch , PropertyMock
39
- except ImportError :
40
- pytest .skip ("Install mock for the cadc tests." , allow_module_level = True )
22
+
23
+ from pyvo .auth import securitymethods
24
+ from astroquery .cadc import Cadc , conf
25
+ import astroquery .cadc .core as cadc_core
26
+
27
+ from unittest .mock import Mock , patch , PropertyMock
41
28
42
29
43
30
def data_path (filename ):
@@ -47,7 +34,6 @@ def data_path(filename):
47
34
48
35
@patch ('astroquery.cadc.core.get_access_url' ,
49
36
Mock (side_effect = lambda x : 'https://some.url' ))
50
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
51
37
def test_get_tables ():
52
38
# default parameters
53
39
table_set = PropertyMock ()
@@ -62,7 +48,6 @@ def test_get_tables():
62
48
63
49
@patch ('astroquery.cadc.core.get_access_url' ,
64
50
Mock (side_effect = lambda x : 'https://some.url' ))
65
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
66
51
def test_get_table ():
67
52
table_set = PropertyMock ()
68
53
tables_result = [Mock () for _ in range (3 )]
@@ -80,7 +65,6 @@ def test_get_table():
80
65
81
66
@patch ('astroquery.cadc.core.get_access_url' ,
82
67
Mock (side_effect = lambda x : 'https://some.url' ))
83
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
84
68
def test_get_collections ():
85
69
cadc = Cadc ()
86
70
@@ -106,7 +90,6 @@ def mock_run_query(query, output_format=None, maxrec=None,
106
90
107
91
@patch ('astroquery.cadc.core.get_access_url' ,
108
92
Mock (side_effect = lambda x : 'https://some.url' ))
109
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
110
93
def test_load_async_job ():
111
94
with patch ('astroquery.cadc.core.pyvo.dal.TAPService' , autospec = True ) as tapservice_mock :
112
95
with patch ('astroquery.cadc.core.pyvo.dal.AsyncTAPJob' ,
@@ -124,7 +107,6 @@ def test_load_async_job():
124
107
@pytest .mark .skip ('Disabled until job listing available in pyvo' )
125
108
@patch ('astroquery.cadc.core.get_access_url' ,
126
109
Mock (side_effect = lambda x : 'https://some.url' ))
127
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
128
110
def test_list_async_jobs ():
129
111
with patch ('astroquery.cadc.core.pyvo.dal.TAPService' , autospec = True ) as tapservice_mock :
130
112
tapservice_mock .return_value .baseurl .return_value = 'https://www.example.com/tap'
@@ -136,7 +118,6 @@ def test_list_async_jobs():
136
118
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
137
119
@patch ('astroquery.cadc.core.pyvo.dal.TAPService.capabilities' , []) # TAP capabilities not needed
138
120
@patch ('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService.capabilities' , []) # DL capabilities not needed
139
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
140
121
def test_auth ():
141
122
# the Cadc() will cause a remote data call to TAP service capabilities
142
123
# To avoid this, use an anonymous session and replace it with an
@@ -183,7 +164,6 @@ def test_auth():
183
164
184
165
# make sure that caps is reset at the end of the test
185
166
@patch ('astroquery.cadc.core.get_access_url.caps' , {})
186
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
187
167
def test_get_access_url ():
188
168
# testing implementation of requests.get method:
189
169
def get (url , ** kwargs ):
@@ -219,7 +199,6 @@ def raise_for_status(self):
219
199
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
220
200
@patch ('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService' ,
221
201
Mock (return_value = Mock (capabilities = []))) # DL capabilities not needed
222
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
223
202
def test_get_data_urls ():
224
203
225
204
def get (* args , ** kwargs ):
@@ -268,7 +247,6 @@ class Result:
268
247
269
248
@patch ('astroquery.cadc.core.get_access_url' ,
270
249
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
271
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
272
250
def test_misc ():
273
251
cadc = Cadc ()
274
252
@@ -302,7 +280,6 @@ def test_misc():
302
280
Mock (return_value = Mock (capabilities = []))) # TAP capabilities not needed
303
281
@patch ('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService' ,
304
282
Mock (return_value = Mock (capabilities = []))) # DL capabilities not needed
305
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
306
283
def test_get_image_list ():
307
284
def get (* args , ** kwargs ):
308
285
class CapsResponse :
@@ -370,7 +347,6 @@ def __init__(self, **param_dict):
370
347
371
348
@patch ('astroquery.cadc.core.get_access_url' ,
372
349
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
373
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
374
350
def test_exec_sync ():
375
351
# save results in a file
376
352
# create the VOTable result
@@ -411,7 +387,6 @@ def test_exec_sync():
411
387
@patch ('astroquery.cadc.core.CadcClass.exec_sync' , Mock ())
412
388
@patch ('astroquery.cadc.core.CadcClass.get_image_list' ,
413
389
Mock (side_effect = lambda x , y , z : ['https://some.url' ]))
414
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
415
390
def test_get_images ():
416
391
with patch ('astroquery.utils.commons.get_readable_fileobj' , autospec = True ) as readable_fobj_mock :
417
392
readable_fobj_mock .return_value = open (data_path ('query_images.fits' ), 'rb' )
@@ -429,7 +404,6 @@ def test_get_images():
429
404
@patch ('astroquery.cadc.core.CadcClass.exec_sync' , Mock ())
430
405
@patch ('astroquery.cadc.core.CadcClass.get_image_list' ,
431
406
Mock (side_effect = lambda x , y , z : ['https://some.url' ]))
432
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
433
407
def test_get_images_async ():
434
408
with patch ('astroquery.utils.commons.get_readable_fileobj' , autospec = True ) as readable_fobj_mock :
435
409
readable_fobj_mock .return_value = open (data_path ('query_images.fits' ), 'rb' )
0 commit comments