1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
3
- import os
4
- import re
5
- import numpy as np
6
-
7
3
import pytest
8
4
from astropy .coordinates import SkyCoord
9
5
from astropy .table import Table
10
6
import astropy .units as u
11
7
12
- from astroquery .utils .mocks import MockResponse
13
- from astroquery .ipac .irsa import Irsa , conf
14
- from astroquery .ipac import irsa
15
-
16
- DATA_FILES = {'Cone' : 'Cone.xml' ,
17
- 'Box' : 'Box.xml' ,
18
- 'Polygon' : 'Polygon.xml' }
8
+ from astroquery .ipac .irsa import Irsa
9
+ from astroquery .exceptions import InvalidQueryError
19
10
20
11
OBJ_LIST = ["m31" , "00h42m44.330s +41d16m07.50s" ,
21
12
SkyCoord (l = 121.1743 * u .deg , b = - 21.5733 * u .deg , frame = "galactic" )]
22
13
23
14
24
- def data_path (filename ):
25
- data_dir = os .path .join (os .path .dirname (__file__ ), 'data' )
26
- return os .path .join (data_dir , filename )
27
-
28
-
29
- @pytest .fixture
30
- def patch_get (request ):
31
- mp = request .getfixturevalue ("monkeypatch" )
32
-
33
- mp .setattr (Irsa , '_request' , get_mockreturn )
34
- return mp
35
-
36
-
37
- def get_mockreturn (method , url , params = None , timeout = 10 , cache = False , ** kwargs ):
38
- filename = data_path (DATA_FILES [params ['spatial' ]])
39
- with open (filename , 'rb' ) as infile :
40
- content = infile .read ()
41
- return MockResponse (content , ** kwargs )
42
-
43
-
44
- #def test_args_to_payload():
45
- # out = Irsa._args_to_payload("fp_psc")
46
- # assert out == dict(catalog='fp_psc', outfmt=3, outrows=conf.row_limit,
47
- # selcols='')
48
-
49
-
50
15
@pytest .mark .parametrize (("coordinates" ), OBJ_LIST )
51
- def test_query_region_cone (coordinates , patch_get ):
52
- result = Irsa .query_region (
53
- coordinates , catalog = 'fp_psc' , spatial = 'Cone' , radius = 2 * u . arcmin )
16
+ def test_query_region_cone (coordinates ):
17
+ query = Irsa .query_region (coordinates , catalog = 'fp_psc' , spatial = 'Cone' , radius = 2 * u . arcmin ,
18
+ get_query_payload = True )
54
19
55
- assert isinstance (result , Table )
20
+ # We don't fully float compare in this string, there are slight differences due to the name-coordinate
21
+ # resolution and conversions
22
+ assert "SELECT * FROM fp_psc WHERE CONTAINS(POINT('ICRS',ra,dec),CIRCLE('ICRS',10.68" in query
23
+ assert ",41.26" in query
24
+ assert ",0.0333" in query
56
25
57
26
58
27
@pytest .mark .skip ("Upstream TAP doesn't support Box geometry yet" )
59
28
@pytest .mark .parametrize ("coordinates" , OBJ_LIST )
60
- def test_query_region_box (coordinates , patch_get ):
29
+ def test_query_region_box (coordinates ):
61
30
result = Irsa .query_region (
62
31
coordinates , catalog = 'fp_psc' , spatial = 'Box' , width = 2 * u .arcmin )
63
32
@@ -72,10 +41,22 @@ def test_query_region_box(coordinates, patch_get):
72
41
73
42
74
43
@pytest .mark .parametrize ("polygon" , [poly1 , poly2 ])
75
- def test_query_region_polygon (polygon , patch_get ):
76
- result = Irsa .query_region ("m31" , catalog = "fp_psc" , spatial = "Polygon" , polygon = polygon )
44
+ def test_query_region_polygon (polygon ):
45
+ query1 = Irsa .query_region (catalog = "fp_psc" , spatial = "Polygon" , polygon = polygon ,
46
+ get_query_payload = True )
47
+ query2 = Irsa .query_region ("m31" , catalog = "fp_psc" , spatial = "Polygon" , polygon = polygon ,
48
+ get_query_payload = True )
49
+
50
+ assert query1 == query2
51
+ assert query1 == ("SELECT * FROM fp_psc "
52
+ "WHERE CONTAINS(POINT('ICRS',ra,dec),POLYGON('ICRS',10.1,10.1,10.0,10.1,10.0,10.0))=1" )
77
53
78
- assert isinstance (result , Table )
54
+
55
+ def test_query_allsky ():
56
+ query1 = Irsa .query_region (catalog = "fp_psc" , spatial = "All-Sky" , get_query_payload = True )
57
+ query2 = Irsa .query_region ("m31" , catalog = "fp_psc" , spatial = "All-Sky" , get_query_payload = True )
58
+
59
+ assert query1 == query2 == "SELECT * FROM fp_psc"
79
60
80
61
81
62
@pytest .mark .parametrize ('spatial' , ['cone' , 'box' , 'polygon' , 'all-Sky' , 'All-sky' , 'invalid' ])
@@ -84,6 +65,11 @@ def test_spatial_invalid(spatial):
84
65
Irsa .query_region ("m31" , catalog = 'invalid_spatial' , spatial = spatial )
85
66
86
67
68
+ def test_no_catalog ():
69
+ with pytest .raises (InvalidQueryError ):
70
+ Irsa .query_region ("m31" , spatial = 'Cone' )
71
+
72
+
87
73
def test_deprecated_namespace_import_warning ():
88
74
with pytest .warns (DeprecationWarning ):
89
75
import astroquery .irsa # noqa: F401
0 commit comments