File: test_esasky.py

package info (click to toggle)
astroquery 0.3.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,528 kB
  • ctags: 3,402
  • sloc: xml: 113,303; python: 21,713; makefile: 135; ansic: 88; sh: 46
file content (52 lines) | stat: -rwxr-xr-x 1,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

from astropy.tests.helper import pytest

import os
import unittest

from ...utils.testing_tools import MockResponse
from ...esasky import ESASky


DATA_FILES = {'GET':
              {'http://ammidev.n1data.lan:8080/esasky-tap/observations':
               'observations.txt',
               'http://sky.esa.int/esasky-tap/catalogs':
               'catalogs.txt'
               },
              }

def data_path(filename):
    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    return os.path.join(data_dir, filename)

def nonremote_request(request_type, url, **kwargs):
    with open(data_path(DATA_FILES[request_type][url]), 'rb') as f:
        response = MockResponse(content=f.read(), url=url)
    return response

@pytest.fixture
def esasky_request(request):
    mp = request.getfixturevalue("monkeypatch")
    mp.setattr(ESASky, '_request', nonremote_request)
    return mp

@pytest.mark.usefixtures("esasky_request")
class TestEsaSkyLocal(unittest.TestCase):
    def test_esasky_query_region_maps_invalid_position(self):
        with self.assertRaises(ValueError):
            ESASky.query_region_maps(51, "5 arcmin")
            
    def test_esasky_query_region_maps_invalid_radius(self):
        with self.assertRaises(ValueError):
            ESASky.query_region_maps("M51", 5)

    def test_esasky_query_region_maps_invalid_mission(self):
        with self.assertRaises(ValueError):
            ESASky.query_region_maps("M51", "5 arcmin", missions=True)
            
    def test_list_catalogs(self):
        result = ESASky.list_catalogs()
        assert (len(result) == 13)