Skip to content

Commit 12a7999

Browse files
committed
Merge pull request #553 from bsipocz/eso_minor_test_clean
Eso/alma minor test clean
2 parents 62ee271 + 3e34a2f commit 12a7999

File tree

5 files changed

+73
-36
lines changed

5 files changed

+73
-36
lines changed

astroquery/alma/tests/test_alma.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22
import numpy as np
33
import os
44
from astropy.tests.helper import pytest
5-
6-
from .. import Alma
75
from ...utils.testing_tools import MockResponse
86
from ...exceptions import (InvalidQueryError)
97

8+
# keyring is an optional dependency required by the alma module.
9+
try:
10+
import keyring
11+
HAS_KEYRING = True
12+
except ImportError:
13+
HAS_KEYRING = False
14+
15+
if HAS_KEYRING:
16+
from .. import Alma
17+
18+
SKIP_TESTS = not HAS_KEYRING
19+
20+
1021
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
1122

23+
1224
def data_path(filename):
1325
return os.path.join(DATA_DIR, filename)
1426

@@ -36,6 +48,7 @@ def data_path(filename):
3648
'initial_response.html'}
3749
}
3850

51+
3952
def url_mapping(url):
4053
"""
4154
Map input URLs to output URLs for the staging test
@@ -50,9 +63,10 @@ def url_mapping(url):
5063
else:
5164
return mapping[url]
5265

66+
5367
def alma_request(request_type, url, params=None, payload=None, data=None,
5468
**kwargs):
55-
if isinstance(DATA_FILES[request_type][url],dict):
69+
if isinstance(DATA_FILES[request_type][url], dict):
5670
payload = (payload if payload is not None else
5771
params if params is not None else
5872
data if data is not None else
@@ -73,10 +87,11 @@ def alma_request(request_type, url, params=None, payload=None, data=None,
7387
return response
7488

7589

76-
7790
def _get_dataarchive_url(*args):
7891
return 'http://almascience.eso.org'
7992

93+
94+
@pytest.mark.skipif('SKIP_TESTS')
8095
def test_SgrAstar(monkeypatch):
8196
# Local caching prevents a remote query here
8297

@@ -95,6 +110,8 @@ def test_SgrAstar(monkeypatch):
95110
assert len(result) == 92
96111
assert b'2011.0.00217.S' in result['Project code']
97112

113+
114+
@pytest.mark.skipif('SKIP_TESTS')
98115
def test_staging(monkeypatch):
99116

100117
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
@@ -105,27 +122,29 @@ def test_staging(monkeypatch):
105122

106123
target = 'NGC4945'
107124
project_code = '2011.0.00121.S'
108-
payload = {'project_code':project_code,
109-
'source_name_resolver':target,}
125+
payload = {'project_code': project_code,
126+
'source_name_resolver': target}
110127
result = alma.query(payload=payload)
111128

112129
uid_url_table = alma.stage_data(result['Asdm uid'])
113130
assert len(uid_url_table) == 2
114131

115132

133+
@pytest.mark.skipif('SKIP_TESTS')
116134
def test_validator(monkeypatch):
117135

118136
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
119137
alma = Alma()
120138
monkeypatch.setattr(alma, '_get_dataarchive_url', _get_dataarchive_url)
121139
monkeypatch.setattr(alma, '_request', alma_request)
122140

123-
124141
with pytest.raises(InvalidQueryError) as exc:
125142
alma.query(payload={'invalid_parameter': 1})
126143

127144
assert 'invalid_parameter' in str(exc.value)
128145

146+
147+
@pytest.mark.skipif('SKIP_TESTS')
129148
def test_parse_staging_request_page_asdm(monkeypatch):
130149
"""
131150
Example:
@@ -157,6 +176,8 @@ def test_parse_staging_request_page_asdm(monkeypatch):
157176
assert tbl[0]['uid'] == 'uid___A002_X47bd4d_X4c7.asdm.sdm.tar'
158177
np.testing.assert_approx_equal(tbl[0]['size'], -1e-9)
159178

179+
180+
@pytest.mark.skipif('SKIP_TESTS')
160181
def test_parse_staging_request_page_mous(monkeypatch):
161182
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
162183
alma = Alma()
@@ -173,6 +194,8 @@ def test_parse_staging_request_page_mous(monkeypatch):
173194
np.testing.assert_approx_equal(tbl[0]['size'], 0.2093)
174195
assert len(tbl) == 26
175196

197+
198+
@pytest.mark.skipif('SKIP_TESTS')
176199
def test_parse_staging_request_page_mous_cycle0(monkeypatch):
177200
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
178201
alma = Alma()

astroquery/alma/tests/test_alma_remote.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2-
import os
32
import tempfile
43
import shutil
54
import numpy as np
65
from astropy.tests.helper import pytest, remote_data
76
from astropy import coordinates
87
from astropy import units as u
9-
from .. import Alma
10-
from ...exceptions import LoginError
118

9+
# keyring is an optional dependency required by the alma module.
10+
try:
11+
import keyring
12+
HAS_KEYRING = True
13+
except ImportError:
14+
HAS_KEYRING = False
1215

16+
if HAS_KEYRING:
17+
from .. import Alma
18+
19+
SKIP_TESTS = not HAS_KEYRING
20+
21+
22+
@pytest.mark.skipif('SKIP_TESTS')
1323
@remote_data
1424
class TestAlma:
1525

@@ -19,6 +29,7 @@ def setup_class(cls):
1929
@pytest.fixture()
2030
def temp_dir(self, request):
2131
my_temp_dir = tempfile.mkdtemp()
32+
2233
def fin():
2334
shutil.rmtree(my_temp_dir)
2435
request.addfinalizer(fin)
@@ -97,7 +108,7 @@ def test_cycle1(self, temp_dir):
97108

98109
target = 'NGC4945'
99110
project_code = '2012.1.00912.S'
100-
111+
101112
payload = {'project_code':project_code,
102113
'source_name_alma':target,}
103114
result = alma.query(payload=payload)
@@ -130,7 +141,7 @@ def test_cycle0(self, temp_dir):
130141

131142
target = 'NGC4945'
132143
project_code = '2011.0.00121.S'
133-
144+
134145
payload = {'project_code':project_code,
135146
'source_name_alma':target,}
136147
result = alma.query(payload=payload)
@@ -155,7 +166,7 @@ def test_cycle0(self, temp_dir):
155166
assert len(data) == 8
156167

157168
def test_help(self):
158-
169+
159170
help_list = Alma._get_help_page()
160171
assert help_list[0][0] == u'Position'
161172
assert help_list[1][0] == u'Energy'

astroquery/cosmosim/tests/test_cosmosim_remote.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
import tempfile
44
import shutil
55
from astropy.tests.helper import pytest, remote_data
6+
from ...exceptions import LoginError
7+
68
try:
79
import keyring
810
HAS_KEYRING = True
911
except ImportError:
1012
HAS_KEYRING = False
11-
try:
13+
14+
if HAS_KEYRING:
1215
from ...cosmosim import CosmoSim
13-
COSMOSIM_IMPORTED = True
14-
except ImportError:
15-
COSMOSIM_IMPORTED = False
16-
from ...exceptions import LoginError
1716

18-
SKIP_TESTS = not(HAS_KEYRING and COSMOSIM_IMPORTED)
17+
SKIP_TESTS = not HAS_KEYRING
1918

2019
#@pytest.mark.skipif('SKIP_TESTS')
2120
#@remote_data
2221
#class TestEso:
2322
# def __init__():
24-
23+

astroquery/eso/tests/test_eso.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import os
3-
from distutils.version import LooseVersion
4-
import astropy
5-
try:
6-
from ...eso import Eso
7-
ESO_IMPORTED = True
8-
except ImportError:
9-
ESO_IMPORTED = False
103
from astropy.tests.helper import pytest
114
from ...utils.testing_tools import MockResponse
125

13-
SKIP_TESTS = not ESO_IMPORTED
6+
# keyring is an optional dependency required by the eso module.
7+
try:
8+
import keyring
9+
HAS_KEYRING = True
10+
except ImportError:
11+
HAS_KEYRING = False
12+
13+
if HAS_KEYRING:
14+
from ...eso import Eso
15+
16+
SKIP_TESTS = not HAS_KEYRING
1417

1518
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
1619

@@ -22,12 +25,12 @@ def data_path(filename):
2225
'amber_form.html',
2326
'http://archive.eso.org/wdb/wdb/adp/phase3_main/form':
2427
'vvv_sgra_form.html',
25-
},
28+
},
2629
'POST': {'http://archive.eso.org/wdb/wdb/eso/amber/query':
2730
'amber_sgra_query.tbl',
2831
'http://archive.eso.org/wdb/wdb/adp/phase3_main/query':
2932
'vvv_sgra_survey_response.tbl',
30-
}
33+
}
3134
}
3235

3336

@@ -64,6 +67,7 @@ def test_SgrAstar(monkeypatch):
6467
assert len(result) == 50
6568
assert 'GC_IRS7' in result['Object']
6669

70+
6771
@pytest.mark.skipif('SKIP_TESTS')
6872
def test_vvv(monkeypatch):
6973
eso = Eso()

astroquery/eso/tests/test_eso_remote.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
import tempfile
33
import shutil
44
from astropy.tests.helper import pytest, remote_data
5+
from ...exceptions import LoginError
6+
7+
# keyring is an optional dependency required by the eso module.
58
try:
69
import keyring
710
HAS_KEYRING = True
811
except ImportError:
912
HAS_KEYRING = False
10-
try:
13+
14+
if HAS_KEYRING:
1115
from ...eso import Eso
12-
ESO_IMPORTED = True
13-
except ImportError:
14-
ESO_IMPORTED = False
15-
from ...exceptions import LoginError
1616

17-
SKIP_TESTS = not(HAS_KEYRING and ESO_IMPORTED)
17+
SKIP_TESTS = not HAS_KEYRING
1818

1919
instrument_list = [u'fors1', u'fors2', u'sphere', u'vimos', u'omegacam',
2020
u'hawki', u'isaac', u'naco', u'visir', u'vircam', u'apex',

0 commit comments

Comments
 (0)