Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions astroquery/alma/tests/test_alma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
import numpy as np
import os
from astropy.tests.helper import pytest

from .. import Alma
from ...utils.testing_tools import MockResponse
from ...exceptions import (InvalidQueryError)

# keyring is an optional dependency required by the alma module.
try:
import keyring
HAS_KEYRING = True
except ImportError:
HAS_KEYRING = False

if HAS_KEYRING:
from .. import Alma

SKIP_TESTS = not HAS_KEYRING


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


def data_path(filename):
return os.path.join(DATA_DIR, filename)

Expand Down Expand Up @@ -36,6 +48,7 @@ def data_path(filename):
'initial_response.html'}
}


def url_mapping(url):
"""
Map input URLs to output URLs for the staging test
Expand All @@ -50,9 +63,10 @@ def url_mapping(url):
else:
return mapping[url]


def alma_request(request_type, url, params=None, payload=None, data=None,
**kwargs):
if isinstance(DATA_FILES[request_type][url],dict):
if isinstance(DATA_FILES[request_type][url], dict):
payload = (payload if payload is not None else
params if params is not None else
data if data is not None else
Expand All @@ -73,10 +87,11 @@ def alma_request(request_type, url, params=None, payload=None, data=None,
return response



def _get_dataarchive_url(*args):
return 'http://almascience.eso.org'


@pytest.mark.skipif('SKIP_TESTS')
def test_SgrAstar(monkeypatch):
# Local caching prevents a remote query here

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


@pytest.mark.skipif('SKIP_TESTS')
def test_staging(monkeypatch):

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

target = 'NGC4945'
project_code = '2011.0.00121.S'
payload = {'project_code':project_code,
'source_name_resolver':target,}
payload = {'project_code': project_code,
'source_name_resolver': target}
result = alma.query(payload=payload)

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


@pytest.mark.skipif('SKIP_TESTS')
def test_validator(monkeypatch):

monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
alma = Alma()
monkeypatch.setattr(alma, '_get_dataarchive_url', _get_dataarchive_url)
monkeypatch.setattr(alma, '_request', alma_request)


with pytest.raises(InvalidQueryError) as exc:
alma.query(payload={'invalid_parameter': 1})

assert 'invalid_parameter' in str(exc.value)


@pytest.mark.skipif('SKIP_TESTS')
def test_parse_staging_request_page_asdm(monkeypatch):
"""
Example:
Expand Down Expand Up @@ -157,6 +176,8 @@ def test_parse_staging_request_page_asdm(monkeypatch):
assert tbl[0]['uid'] == 'uid___A002_X47bd4d_X4c7.asdm.sdm.tar'
np.testing.assert_approx_equal(tbl[0]['size'], -1e-9)


@pytest.mark.skipif('SKIP_TESTS')
def test_parse_staging_request_page_mous(monkeypatch):
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
alma = Alma()
Expand All @@ -173,6 +194,8 @@ def test_parse_staging_request_page_mous(monkeypatch):
np.testing.assert_approx_equal(tbl[0]['size'], 0.2093)
assert len(tbl) == 26


@pytest.mark.skipif('SKIP_TESTS')
def test_parse_staging_request_page_mous_cycle0(monkeypatch):
monkeypatch.setattr(Alma, '_get_dataarchive_url', _get_dataarchive_url)
alma = Alma()
Expand Down
23 changes: 17 additions & 6 deletions astroquery/alma/tests/test_alma_remote.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import os
import tempfile
import shutil
import numpy as np
from astropy.tests.helper import pytest, remote_data
from astropy import coordinates
from astropy import units as u
from .. import Alma
from ...exceptions import LoginError

# keyring is an optional dependency required by the alma module.
try:
import keyring
HAS_KEYRING = True
except ImportError:
HAS_KEYRING = False

if HAS_KEYRING:
from .. import Alma

SKIP_TESTS = not HAS_KEYRING


@pytest.mark.skipif('SKIP_TESTS')
@remote_data
class TestAlma:

Expand All @@ -19,6 +29,7 @@ def setup_class(cls):
@pytest.fixture()
def temp_dir(self, request):
my_temp_dir = tempfile.mkdtemp()

def fin():
shutil.rmtree(my_temp_dir)
request.addfinalizer(fin)
Expand Down Expand Up @@ -97,7 +108,7 @@ def test_cycle1(self, temp_dir):

target = 'NGC4945'
project_code = '2012.1.00912.S'

payload = {'project_code':project_code,
'source_name_alma':target,}
result = alma.query(payload=payload)
Expand Down Expand Up @@ -130,7 +141,7 @@ def test_cycle0(self, temp_dir):

target = 'NGC4945'
project_code = '2011.0.00121.S'

payload = {'project_code':project_code,
'source_name_alma':target,}
result = alma.query(payload=payload)
Expand All @@ -155,7 +166,7 @@ def test_cycle0(self, temp_dir):
assert len(data) == 8

def test_help(self):

help_list = Alma._get_help_page()
assert help_list[0][0] == u'Position'
assert help_list[1][0] == u'Energy'
Expand Down
13 changes: 6 additions & 7 deletions astroquery/cosmosim/tests/test_cosmosim_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import tempfile
import shutil
from astropy.tests.helper import pytest, remote_data
from ...exceptions import LoginError

try:
import keyring
HAS_KEYRING = True
except ImportError:
HAS_KEYRING = False
try:

if HAS_KEYRING:
from ...cosmosim import CosmoSim
COSMOSIM_IMPORTED = True
except ImportError:
COSMOSIM_IMPORTED = False
from ...exceptions import LoginError

SKIP_TESTS = not(HAS_KEYRING and COSMOSIM_IMPORTED)
SKIP_TESTS = not HAS_KEYRING

#@pytest.mark.skipif('SKIP_TESTS')
#@remote_data
#class TestEso:
# def __init__():

24 changes: 14 additions & 10 deletions astroquery/eso/tests/test_eso.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import os
from distutils.version import LooseVersion
import astropy
try:
from ...eso import Eso
ESO_IMPORTED = True
except ImportError:
ESO_IMPORTED = False
from astropy.tests.helper import pytest
from ...utils.testing_tools import MockResponse

SKIP_TESTS = not ESO_IMPORTED
# keyring is an optional dependency required by the eso module.
try:
import keyring
HAS_KEYRING = True
except ImportError:
HAS_KEYRING = False

if HAS_KEYRING:
from ...eso import Eso

SKIP_TESTS = not HAS_KEYRING

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

Expand All @@ -22,12 +25,12 @@ def data_path(filename):
'amber_form.html',
'http://archive.eso.org/wdb/wdb/adp/phase3_main/form':
'vvv_sgra_form.html',
},
},
'POST': {'http://archive.eso.org/wdb/wdb/eso/amber/query':
'amber_sgra_query.tbl',
'http://archive.eso.org/wdb/wdb/adp/phase3_main/query':
'vvv_sgra_survey_response.tbl',
}
}
}


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


@pytest.mark.skipif('SKIP_TESTS')
def test_vvv(monkeypatch):
eso = Eso()
Expand Down
12 changes: 6 additions & 6 deletions astroquery/eso/tests/test_eso_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import tempfile
import shutil
from astropy.tests.helper import pytest, remote_data
from ...exceptions import LoginError

# keyring is an optional dependency required by the eso module.
try:
import keyring
HAS_KEYRING = True
except ImportError:
HAS_KEYRING = False
try:

if HAS_KEYRING:
from ...eso import Eso
ESO_IMPORTED = True
except ImportError:
ESO_IMPORTED = False
from ...exceptions import LoginError

SKIP_TESTS = not(HAS_KEYRING and ESO_IMPORTED)
SKIP_TESTS = not HAS_KEYRING

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