1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
3
+ import io
3
4
import os
4
- import re
5
- import numpy as np
6
-
7
5
import pytest
8
- from astropy .coordinates import SkyCoord
9
- from astropy .table import Table
10
- import astropy .units as u
11
6
7
+ #from astropy.coordinates import SkyCoord
8
+ #from astropy.table import Table
9
+ #import astropy.units as u
10
+ from astropy .io import votable
11
+ from astropy .table import Table
12
12
from astroquery .utils .mocks import MockResponse
13
- from astroquery .ipac .most import Most , conf
13
+ from astroquery .ipac .irsa .most import Most , conf
14
+ from astropy .utils .diff import report_diff_values
15
+
14
16
15
- DATA_FILES = "MOST_regular_outputs.html"
17
+ DATA_FILES = {
18
+ "Regular" : "MOST_regular.html" ,
19
+ "Full" : "MOST_full_with_tarballs.html" ,
20
+ "VOTable" : "MOST_VOTable.xml" ,
21
+ "Brief" : "most_results_table.tbl" ,
22
+ "Gator" : "most_gator_table.tbl"
23
+ }
16
24
17
25
18
26
def data_path (filename ):
@@ -27,15 +35,158 @@ def patch_get(request):
27
35
return mp
28
36
29
37
30
- def get_mockreturn (method , url , params = None , timeout = 10 , cache = False , ** kwargs ):
31
- filename = data_path (DATA_FILES )
38
+ def get_mockreturn (method = None , url = None , data = None , timeout = 120 , ** kwargs ):
39
+ if method == "GET" :
40
+ filename = data_path (url )
41
+ else :
42
+ filename = data_path (DATA_FILES [data ["output_mode" ]])
32
43
with open (filename , 'rb' ) as infile :
33
44
content = infile .read ()
34
45
return MockResponse (content , ** kwargs )
35
46
36
47
37
- def test_get_regular ():
38
- response = Most .query ()
39
- breakpoint ()
48
+ def test_validation (patch_get ):
49
+ with pytest .raises (ValueError ):
50
+ Most .query ()
51
+
52
+ with pytest .raises (ValueError ):
53
+ Most .query (catalog = "wise_allsky_4band" )
54
+
55
+ # make sure no funny business happens with
56
+ # overwriting of default values
57
+ Most .query (
58
+ catalog = "wise_allsky_4band" ,
59
+ obj_name = "Victoria"
60
+ )
61
+ Most .query (
62
+ catalog = "wise_allsky_4band" ,
63
+ obj_name = "Victoria" ,
64
+ input_type = "name_input"
65
+ )
66
+
67
+ with pytest .raises (ValueError ):
68
+ # fails because insufficient orbital parameters specified
69
+ Most .query (
70
+ catalog = "wise_allsky_4band" ,
71
+ output_mode = "Brief" ,
72
+ input_type = "manual_input" ,
73
+ obj_type = "Asteroid" ,
74
+ perih_dist = 1.5 ,
75
+ eccentricity = 0.5
76
+ )
77
+
78
+ Most .query (
79
+ catalog = "wise_allsky_4band" ,
80
+ output_mode = "Brief" ,
81
+ input_type = "manual_input" ,
82
+ obj_type = "Asteroid" ,
83
+ semimajor_axis = 2.68 ,
84
+ eccentricity = 0.33 ,
85
+ )
86
+
87
+ with pytest .raises (ValueError ):
88
+ # Comets require perihel_dist keyword
89
+ # instead of smimajor_axis
90
+ Most .query (
91
+ catalog = "wise_allsky_4band" ,
92
+ output_mode = "Brief" ,
93
+ input_type = "manual_input" ,
94
+ obj_type = "Comet" ,
95
+ semimajor_axis = 2.68 ,
96
+ eccentricity = 0.33
97
+ )
98
+
99
+ with pytest .raises (ValueError ):
100
+ # object type is case sensitive
101
+ Most .query (
102
+ catalog = "wise_allsky_4band" ,
103
+ output_mode = "Brief" ,
104
+ input_type = "manual_input" ,
105
+ obj_type = "comet" ,
106
+ semimajor_axis = 2.68 ,
107
+ eccentricity = 0.33
108
+ )
109
+
110
+ with pytest .raises (ValueError ):
111
+ # missing mpc_data and obj_type
112
+ Most .query (
113
+ catalog = "wise_allsky_4band" ,
114
+ output_mode = "Brief" ,
115
+ input_type = "mpc_input"
116
+ )
117
+
118
+ Most .query (
119
+ catalog = "wise_allsky_4band" ,
120
+ output_mode = "Brief" ,
121
+ input_type = "mpc_input" ,
122
+ obj_type = "Asteroid" ,
123
+ mpc_data = "K10N010+2010+08+16.1477+1.494525+0.533798+153.4910+113.2118+12.8762+20100621+17.0+4.0+P/2010+N1+(WISE)+MPC+75712"
124
+ )
125
+
126
+
127
+ def test_regular (patch_get ):
128
+ response = Most .query (obj_name = "Victoria" )
129
+
130
+ assert "results" in response
131
+ assert "metadata" in response
132
+ assert "region" in response
133
+ assert "fits_tarball" not in response
134
+ assert "region_tarball" not in response
135
+
136
+ results = Table .read (data_path ("most_results_table.tbl" ), format = "ipac" )
137
+ metadata = Table .read (data_path ("most_imgframes_matched_final_table.tbl" ), format = "ipac" )
138
+ url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region/ds9_orbit_path.reg"
139
+
140
+ silent_stream = io .StringIO ()
141
+ assert report_diff_values (results , response ["results" ], silent_stream )
142
+ assert report_diff_values (metadata , response ["metadata" ], silent_stream )
143
+ assert url == response ["region" ]
144
+
145
+
146
+ def test_get_full_with_tarballs (patch_get ):
147
+ response = Most .query (
148
+ obj_name = "Victoria" ,
149
+ output_mode = "Full" ,
150
+ fits_region_files = True
151
+ )
152
+
153
+ assert "results" in response
154
+ assert "metadata" in response
155
+ assert "region" in response
156
+ assert "fits_tarball" in response
157
+ assert "region_tarball" in response
158
+
159
+ results = Table .read (data_path ("most_results_table.tbl" ), format = "ipac" )
160
+ metadata = Table .read (data_path ("most_imgframes_matched_final_table.tbl" ), format = "ipac" )
161
+ url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region/ds9_orbit_path.reg"
162
+ region_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region_A850RA.tar"
163
+ fits_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/fitsimage_A850RA.tar.gz"
164
+
165
+ silent_stream = io .StringIO ()
166
+ assert report_diff_values (results , response ["results" ], silent_stream )
167
+ assert report_diff_values (metadata , response ["metadata" ], silent_stream )
168
+ assert url == response ["region" ]
169
+ assert region_tar == response ["region_tarball" ]
170
+ assert fits_tar == response ["fits_tarball" ]
171
+
172
+
173
+ def test_votable (patch_get ):
174
+ response = Most .query (
175
+ output_mode = "VOTable" ,
176
+ obj_name = "Victoria"
177
+ )
178
+
179
+ vtbl = votable .parse (data_path ("MOST_VOTable.xml" ))
180
+ silent_stream = io .StringIO ()
181
+ assert report_diff_values (response , vtbl , silent_stream )
182
+
183
+
184
+ def test_gator (patch_get ):
185
+ response = Most .query (
186
+ output_mode = "Gator" ,
187
+ obj_name = "Victoria"
188
+ )
40
189
41
- a = 1
190
+ tbl = Table .read (data_path ("most_gator_table.tbl" ), format = "ipac" )
191
+ silent_stream = io .StringIO ()
192
+ assert report_diff_values (tbl , response , silent_stream )
0 commit comments