33
33
34
34
GAIA_QUERIER = GaiaClass (show_server_messages = False )
35
35
JOB_DATA = (Path (__file__ ).with_name ("data" ) / "job_1.vot" ).read_text ()
36
+ RADIUS = 1 * u .deg
36
37
SKYCOORD = SkyCoord (ra = 19 * u .deg , dec = 20 * u .deg , frame = "icrs" )
37
38
38
39
@@ -83,6 +84,13 @@ def mock_querier_async():
83
84
return GaiaClass (tap_plus_conn_handler = conn_handler , datalink_handler = tapplus , show_server_messages = False )
84
85
85
86
87
+ @pytest .fixture
88
+ def cross_match_kwargs ():
89
+ return {"full_qualified_table_name_a" : "schemaA.tableA" ,
90
+ "full_qualified_table_name_b" : "schemaB.tableB" ,
91
+ "results_table_name" : "results" }
92
+
93
+
86
94
def test_show_message ():
87
95
connHandler = DummyConnHandler ()
88
96
@@ -101,44 +109,33 @@ def test_show_message():
101
109
GaiaClass (tap_plus_conn_handler = connHandler , datalink_handler = tapplus , show_server_messages = True )
102
110
103
111
104
- def test_query_object (column_attrs , mock_querier ):
105
- with pytest .raises (ValueError ) as err :
106
- mock_querier .query_object (SKYCOORD )
107
- assert "Missing required argument: width" in err .value .args [0 ]
108
-
109
- width = 12 * u .deg
110
-
111
- with pytest .raises (ValueError ) as err :
112
- mock_querier .query_object (SKYCOORD , width = width )
113
- assert "Missing required argument: height" in err .value .args [0 ]
114
-
115
- table = mock_querier .query_object (SKYCOORD , width = width , height = 10 * u .deg )
116
- assert len (table ) == 3
117
- for colname , attrs in column_attrs .items ():
118
- assert table [colname ].attrs_equal (attrs )
119
- # by radius
120
- table = mock_querier .query_object (SKYCOORD , radius = 1 * u .deg )
112
+ @pytest .mark .parametrize (
113
+ "kwargs" , [{"width" : 12 * u .deg , "height" : 10 * u .deg }, {"radius" : RADIUS }])
114
+ def test_query_object (column_attrs , mock_querier , kwargs ):
115
+ table = mock_querier .query_object (SKYCOORD , ** kwargs )
121
116
assert len (table ) == 3
122
117
for colname , attrs in column_attrs .items ():
123
118
assert table [colname ].attrs_equal (attrs )
124
119
125
120
126
- def test_query_object_async (column_attrs , mock_querier_async ):
127
- table = mock_querier_async .query_object_async (
128
- SKYCOORD , width = 12 * u .deg , height = 10 * u .deg
129
- )
130
- assert len (table ) == 3
131
- for colname , attrs in column_attrs .items ():
132
- assert table [colname ].attrs_equal (attrs )
133
- # by radius
134
- table = mock_querier_async .query_object_async (SKYCOORD , radius = 1 * u .deg )
121
+ @pytest .mark .parametrize (
122
+ "kwargs,reported_missing" , [({}, "width" ), ({"width" : 12 * u .deg }, "height" )])
123
+ def test_query_object_missing_argument (kwargs , reported_missing ):
124
+ with pytest .raises (ValueError , match = f"^Missing required argument: { reported_missing } $" ):
125
+ GAIA_QUERIER .query_object (SKYCOORD , ** kwargs )
126
+
127
+
128
+ @pytest .mark .parametrize (
129
+ "kwargs" , ({"width" : 12 * u .deg , "height" : 10 * u .deg }, {"radius" : RADIUS }))
130
+ def test_query_object_async (column_attrs , mock_querier_async , kwargs ):
131
+ table = mock_querier_async .query_object_async (SKYCOORD , ** kwargs )
135
132
assert len (table ) == 3
136
133
for colname , attrs in column_attrs .items ():
137
134
assert table [colname ].attrs_equal (attrs )
138
135
139
136
140
137
def test_cone_search_sync (column_attrs , mock_querier ):
141
- job = mock_querier .cone_search (SKYCOORD , radius = 1 * u . deg )
138
+ job = mock_querier .cone_search (SKYCOORD , radius = RADIUS )
142
139
assert job .async_ is False
143
140
assert job .get_phase () == "COMPLETED"
144
141
assert job .failed is False
@@ -150,8 +147,7 @@ def test_cone_search_sync(column_attrs, mock_querier):
150
147
151
148
152
149
def test_cone_search_async (column_attrs , mock_querier_async ):
153
- radius = 1.0 * u .deg
154
- job = mock_querier_async .cone_search_async (SKYCOORD , radius = radius )
150
+ job = mock_querier_async .cone_search_async (SKYCOORD , radius = RADIUS )
155
151
assert job .async_ is True
156
152
assert job .get_phase () == "COMPLETED"
157
153
assert job .failed is False
@@ -161,16 +157,18 @@ def test_cone_search_async(column_attrs, mock_querier_async):
161
157
for colname , attrs in column_attrs .items ():
162
158
assert results [colname ].attrs_equal (attrs )
163
159
160
+
161
+ def test_cone_search_and_changing_MAIN_GAIA_TABLE (mock_querier_async ):
164
162
# Regression test for #2093 and #2099 - changing the MAIN_GAIA_TABLE
165
163
# had no effect.
166
- # The preceding tests should have used the default value.
164
+ job = mock_querier_async . cone_search_async ( SKYCOORD , radius = RADIUS )
167
165
assert 'gaiadr3.gaia_source' in job .parameters ['query' ]
168
166
with conf .set_temp ("MAIN_GAIA_TABLE" , "name_from_conf" ):
169
- job = mock_querier_async .cone_search_async (SKYCOORD , radius = radius )
167
+ job = mock_querier_async .cone_search_async (SKYCOORD , radius = RADIUS )
170
168
assert "name_from_conf" in job .parameters ["query" ]
171
169
# Changing the value through the class should overrule conf.
172
170
mock_querier_async .MAIN_GAIA_TABLE = "name_from_class"
173
- job = mock_querier_async .cone_search_async (SKYCOORD , radius = radius )
171
+ job = mock_querier_async .cone_search_async (SKYCOORD , radius = RADIUS )
174
172
assert "name_from_class" in job .parameters ["query" ]
175
173
176
174
@@ -210,94 +208,53 @@ def get_datalinks_monkeypatched(self, ids, verbose):
210
208
assert isinstance (result , Table )
211
209
212
210
213
- def test_xmatch (mock_querier_async ):
214
- # missing table A
215
- with pytest .raises (ValueError ) as err :
216
- mock_querier_async .cross_match (
217
- full_qualified_table_name_b = 'schemaB.tableB' ,
218
- results_table_name = 'results' ,
219
- )
220
- assert "Table name A argument is mandatory" in err .value .args [0 ]
221
- # missing schema A
222
- with pytest .raises (ValueError ) as err :
223
- mock_querier_async .cross_match (
224
- full_qualified_table_name_a = 'tableA' ,
225
- full_qualified_table_name_b = 'schemaB.tableB' ,
226
- results_table_name = 'results' ,
227
- )
228
- assert "Not found schema name in full qualified table A: 'tableA'" \
229
- in err .value .args [0 ]
230
- # missing table B
231
- with pytest .raises (ValueError ) as err :
232
- mock_querier_async .cross_match (
233
- full_qualified_table_name_a = 'schemaA.tableA' ,
234
- results_table_name = 'results' ,
235
- )
236
- assert "Table name B argument is mandatory" in err .value .args [0 ]
237
- # missing schema B
238
- with pytest .raises (ValueError ) as err :
239
- mock_querier_async .cross_match (
240
- full_qualified_table_name_a = 'schemaA.tableA' ,
241
- full_qualified_table_name_b = 'tableB' ,
242
- results_table_name = 'results' ,
243
- )
244
- assert "Not found schema name in full qualified table B: 'tableB'" \
245
- in err .value .args [0 ]
246
- # missing results table
247
- with pytest .raises (ValueError ) as err :
248
- mock_querier_async .cross_match (
249
- full_qualified_table_name_a = 'schemaA.tableA' ,
250
- full_qualified_table_name_b = 'schemaB.tableB' ,
251
- )
252
- assert "Results table name argument is mandatory" in err .value .args [0 ]
253
- # wrong results table (with schema)
254
- with pytest .raises (ValueError ) as err :
255
- mock_querier_async .cross_match (
256
- full_qualified_table_name_a = 'schemaA.tableA' ,
257
- full_qualified_table_name_b = 'schemaB.tableB' ,
258
- results_table_name = 'schema.results' ,
259
- )
260
- assert "Please, do not specify schema for 'results_table_name'" \
261
- in err .value .args [0 ]
262
- # radius < 0.1
263
- with pytest .raises (ValueError ) as err :
264
- mock_querier_async .cross_match (
265
- full_qualified_table_name_a = 'schemaA.tableA' ,
266
- full_qualified_table_name_b = 'schemaB.tableB' ,
267
- results_table_name = 'results' ,
268
- radius = 0.01 ,
269
- )
270
- assert "Invalid radius value. Found 0.01, valid range is: 0.1 to 10.0" \
271
- in err .value .args [0 ]
272
- # radius > 10.0
273
- with pytest .raises (ValueError ) as err :
274
- mock_querier_async .cross_match (
275
- full_qualified_table_name_a = 'schemaA.tableA' ,
276
- full_qualified_table_name_b = 'schemaB.tableB' ,
277
- results_table_name = 'results' ,
278
- radius = 10.1
279
- )
280
- assert "Invalid radius value. Found 10.1, valid range is: 0.1 to 10.0" \
281
- in err .value .args [0 ]
282
- job = mock_querier_async .cross_match (
283
- full_qualified_table_name_a = 'schemaA.tableA' ,
284
- full_qualified_table_name_b = 'schemaB.tableB' ,
285
- results_table_name = 'results' ,
286
- )
211
+ @pytest .mark .parametrize ("background" , [False , True ])
212
+ def test_cross_match (background , cross_match_kwargs , mock_querier_async ):
213
+ job = mock_querier_async .cross_match (** cross_match_kwargs , background = background )
287
214
assert job .async_ is True
288
- assert job .get_phase () == "COMPLETED"
289
- assert job .failed is False
290
- job = mock_querier_async .cross_match (
291
- full_qualified_table_name_a = 'schemaA.tableA' ,
292
- full_qualified_table_name_b = 'schemaB.tableB' ,
293
- results_table_name = 'results' ,
294
- background = True ,
295
- )
296
- assert job .async_ is True
297
- assert job .get_phase () == "EXECUTING"
215
+ assert job .get_phase () == "EXECUTING" if background else "COMPLETED"
298
216
assert job .failed is False
299
217
300
218
219
+ @pytest .mark .parametrize (
220
+ "kwarg,invalid_value,error_message" ,
221
+ [("full_qualified_table_name_a" ,
222
+ "tableA" ,
223
+ "^Not found schema name in full qualified table A: 'tableA'$" ),
224
+ ("full_qualified_table_name_b" ,
225
+ "tableB" ,
226
+ "^Not found schema name in full qualified table B: 'tableB'$" ),
227
+ ("results_table_name" ,
228
+ "schema.results" ,
229
+ "^Please, do not specify schema for 'results_table_name'$" )])
230
+ def test_cross_match_invalid_mandatory_kwarg (
231
+ cross_match_kwargs , kwarg , invalid_value , error_message
232
+ ):
233
+ cross_match_kwargs [kwarg ] = invalid_value
234
+ with pytest .raises (ValueError , match = error_message ):
235
+ GAIA_QUERIER .cross_match (** cross_match_kwargs )
236
+
237
+
238
+ @pytest .mark .parametrize ("radius" , [0.01 , 10.1 ])
239
+ def test_cross_match_invalid_radius (cross_match_kwargs , radius ):
240
+ with pytest .raises (
241
+ ValueError ,
242
+ match = rf"^Invalid radius value. Found { radius } , valid range is: 0.1 to 10.0$" ,
243
+ ):
244
+ GAIA_QUERIER .cross_match (** cross_match_kwargs , radius = radius )
245
+
246
+
247
+ @pytest .mark .parametrize (
248
+ "missing_kwarg,msg" ,
249
+ [("full_qualified_table_name_a" , "Table name A" ),
250
+ ("full_qualified_table_name_b" , "Table name B" ),
251
+ ("results_table_name" , "Results table name" )])
252
+ def test_cross_match_missing_mandatory_kwarg (cross_match_kwargs , missing_kwarg , msg ):
253
+ del cross_match_kwargs [missing_kwarg ]
254
+ with pytest .raises (ValueError , match = rf"^{ msg } argument is mandatory$" ):
255
+ GAIA_QUERIER .cross_match (** cross_match_kwargs )
256
+
257
+
301
258
@patch .object (TapPlus , 'login' )
302
259
def test_login (mock_login ):
303
260
conn_handler = DummyConnHandler ()
0 commit comments