@@ -228,7 +228,7 @@ def test_query():
228228 nrao ._get_dataarchive_url = Mock ()
229229 nrao ._tap = tap_mock
230230 result = nrao .query_region (SkyCoord (1 * u .deg , 2 * u .deg , frame = 'icrs' ),
231- radius = 1 * u .deg )
231+ radius = 0.001 * u .deg )
232232 assert len (result ) == 0
233233 assert 'proposal_id' in result .columns
234234 tap_mock .search .assert_called_once_with (
@@ -246,102 +246,14 @@ def test_query():
246246 nrao ._tap = tap_mock
247247 with patch ('astroquery.nrao.tapsql.coord.SkyCoord.from_name' ) as name_mock :
248248 name_mock .return_value = SkyCoord (1 , 2 , unit = 'deg' )
249- result = nrao . query_object ( 'M83' , public = False ,
250- band_list = [ 3 ] )
249+ # mock data generated by running this query w/maxrec=5
250+ result = nrao . query_object ( 'M83' )
251251 assert len (result ) == 1
252252
253253 tap_mock .search .assert_called_once_with (
254- "select * from ivoa.obscore WHERE "
255- "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,0.16666666666666666), s_region) = 1) "
256- "AND band_list LIKE '%3%' AND science_observation='T' AND "
257- "data_rights='Proprietary'" ,
254+ "select * from tap_schema.obscore WHERE CONTAINS(POINT('ICRS',s_ra,s_dec),CIRCLE('ICRS',204.25383,-29.865761111,0.16666666666666666))=1" ,
258255 language = 'ADQL' , maxrec = None )
259256
260- # repeat for legacy columns
261- mock_result = Mock ()
262- tap_mock = Mock ()
263- mock_result .to_table .return_value = onerow_result
264- tap_mock .search .return_value = mock_result
265- nrao = Nrao ()
266- nrao ._tap = tap_mock
267- with patch ('astroquery.nrao.tapsql.coord.SkyCoord.from_name' ) as name_mock :
268- name_mock .return_value = SkyCoord (1 , 2 , unit = 'deg' )
269- result_legacy = nrao .query_object ('M83' , public = False ,
270- legacy_columns = True ,
271- band_list = [3 ])
272- assert len (result ) == 1
273-
274- assert 'Project code' in result_legacy .columns
275- tap_mock .search .assert_called_once_with (
276- "select * from ivoa.obscore WHERE "
277- "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,0.16666666666666666), s_region) = 1) "
278- "AND band_list LIKE '%3%' AND science_observation='T' AND "
279- "data_rights='Proprietary'" ,
280- language = 'ADQL' , maxrec = None )
281- row_legacy = result_legacy [0 ]
282- row = result [0 ]
283- for item in _OBSCORE_TO_nraoRESULT .items ():
284- if item [0 ] == 't_min' :
285- assert Time (row [item [0 ]], format = 'mjd' ).strftime ('%d-%m-%Y' ) == \
286- row_legacy [item [1 ]]
287- else :
288- assert row [item [0 ]] == row_legacy [item [1 ]]
289-
290- # query with different arguments
291- tap_mock = Mock ()
292- empty_result = Table .read (os .path .join (DATA_DIR , 'nrao-empty.txt' ),
293- format = 'ascii' )
294- mock_result = Mock ()
295- mock_result .to_table .return_value = empty_result
296- tap_mock .search .return_value = mock_result
297- nrao = Nrao ()
298- nrao ._get_dataarchive_url = Mock ()
299- nrao ._tap = tap_mock
300- result = nrao .query_region ('1 2' , radius = 1 * u .deg ,
301- payload = {'frequency' : '22' }, public = None ,
302- band_list = '1 3' , science = False ,
303- start_date = '01-01-2010' ,
304- polarisation_type = 'Dual' ,
305- fov = 0.0123130 ,
306- integration_time = 25 )
307- assert len (result ) == 0
308- tap_mock .search .assert_called_with (
309- "select * from ivoa.obscore WHERE frequency=22.0 AND "
310- "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,1.0), s_region) = 1) AND "
311- "(band_list LIKE '%1%' OR band_list LIKE '%3%') AND "
312- "t_min=55197.0 AND pol_states='/XX/YY/' AND s_fov=0.012313 AND "
313- "t_exptime=25 AND science_observation='F'" ,
314- language = 'ADQL' , maxrec = None
315- )
316-
317-
318- def test_sia ():
319- sia_mock = Mock ()
320- empty_result = Table .read (os .path .join (DATA_DIR , 'nrao-empty.txt' ),
321- format = 'ascii' )
322- sia_mock .search .return_value = Mock (table = empty_result )
323- nrao = Nrao ()
324- nrao ._get_dataarchive_url = Mock ()
325- nrao ._sia = sia_mock
326- result = nrao .query_sia (pos = 'CIRCLE 1 2 1' , calib_level = [0 , 1 ],
327- data_rights = 'Public' ,
328- band = (300 , 400 ),
329- time = 545454 , maxrec = 10 , pol = ['XX' , 'YY' ],
330- instrument = 'JAO' , collection = 'nrao' ,
331- field_of_view = 0.0123130 , data_type = 'cube' ,
332- target_name = 'J0423-013' ,
333- publisher_did = 'ADS/JAO.nrao#2013.1.00546.S' ,
334- exptime = 25 )
335- assert len (result .table ) == 0
336- assert_called_with (sia_mock .search , calib_level = [0 , 1 ],
337- band = (300 , 400 ), data_type = 'cube' ,
338- pos = 'CIRCLE 1 2 1' ,
339- time = 545454 , maxrec = 10 , pol = ['XX' , 'YY' ],
340- instrument = 'JAO' , collection = 'nrao' ,
341- data_rights = 'Public' ,
342- field_of_view = 0.0123130 ,
343- target_name = 'J0423-013' ,
344- publisher_did = 'ADS/JAO.nrao#2013.1.00546.S' , exptime = 25 )
345257
346258
347259def test_tap ():
@@ -352,150 +264,20 @@ def test_tap():
352264 nrao = Nrao ()
353265 nrao ._get_dataarchive_url = Mock ()
354266 nrao ._tap = tap_mock
355- result = nrao .query_tap ('select * from ivoa .ObsCore' )
267+ result = nrao .query_tap ('select * from tap_scheme .ObsCore' )
356268 assert len (result .table ) == 0
357269
358- tap_mock .search .assert_called_once_with ('select * from ivoa .ObsCore' ,
270+ tap_mock .search .assert_called_once_with ('select * from tap_scheme .ObsCore' ,
359271 language = 'ADQL' , maxrec = None )
360272
361273
362- @pytest .mark .parametrize ('data_archive_url' ,
363- [
364- ('https://nraoscience.nrao.edu' ),
365- ('https://nraoscience.eso.org' ),
366- ('https://nraoscience.nao.ac.jp' )
367- ])
368- def test_tap_url (data_archive_url ):
369- _test_tap_url (data_archive_url )
370-
371-
372274def _test_tap_url (data_archive_url ):
373275 nrao = Nrao ()
374276 nrao ._get_dataarchive_url = Mock (return_value = data_archive_url )
375277 nrao ._get_dataarchive_url .reset_mock ()
376278 assert nrao .tap_url == f"{ data_archive_url } /tap"
377279
378280
379- @pytest .mark .parametrize ('data_archive_url' ,
380- [
381- ('https://nraoscience.nrao.edu' ),
382- ('https://nraoscience.eso.org' ),
383- ('https://nraoscience.nao.ac.jp' )
384- ])
385- def test_sia_url (data_archive_url ):
386- _test_sia_url (data_archive_url )
387-
388-
389- def _test_sia_url (data_archive_url ):
390- nrao = Nrao ()
391- nrao ._get_dataarchive_url = Mock (return_value = data_archive_url )
392- nrao ._get_dataarchive_url .reset_mock ()
393- assert nrao .sia_url == f"{ data_archive_url } /sia2"
394-
395-
396- @pytest .mark .parametrize ('data_archive_url' ,
397- [
398- ('https://nraoscience.nrao.edu' ),
399- ('https://nraoscience.eso.org' ),
400- ('https://nraoscience.nao.ac.jp' )
401- ])
402- def test_datalink_url (data_archive_url ):
403- _test_datalink_url (data_archive_url )
404-
405-
406- def _test_datalink_url (data_archive_url ):
407- nrao = Nrao ()
408- nrao ._get_dataarchive_url = Mock (return_value = data_archive_url )
409- nrao ._get_dataarchive_url .reset_mock ()
410- assert nrao .datalink_url == f"{ data_archive_url } /datalink/sync"
411-
412-
413- def test_get_data_info ():
414- class MockDataLinkService :
415- def run_sync (self , uid ):
416- return _mocked_datalink_sync (uid )
417-
418- nrao = Nrao ()
419- nrao ._get_dataarchive_url = Mock ()
420- nrao ._datalink = MockDataLinkService ()
421- result = nrao .get_data_info (uids = 'uid://A001/X12a3/Xe9' )
422- assert len (result ) == 9
423-
424-
425- # This method will be used by the mock in test_get_data_info_expand_tarfiles to replace requests.get
426- def _mocked_datalink_sync (* args , ** kwargs ):
427- class MockResponse :
428- adhoc_service_1_param1 = type ('' , (object , ), {'ID' : 'standardID' ,
429- 'value' : 'ivo://ivoa.net/std/DataLink#links-1.0' })()
430- adhoc_service_1_param2 = type (
431- '' , (object , ), {
432- 'ID' : 'accessURL' ,
433- 'value' : 'https://nraoscience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar' }
434- )()
435- adhoc_service_1 = type (
436- '' , (object , ), {
437- 'ID' : 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar' , 'params' : [
438- adhoc_service_1_param1 , adhoc_service_1_param2 ]})()
439-
440- adhoc_service_2_param1 = type ('' , (object , ), {'ID' : 'standardID' ,
441- 'value' : 'ivo://ivoa.net/std/DataLink#links-1.0' })()
442- adhoc_service_2_param2 = type (
443- '' , (object , ), {
444- 'ID' : 'accessURL' ,
445- 'value' : 'https://nraoscience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar' }
446- )()
447- adhoc_service_2 = type (
448- '' , (object , ), {
449- 'ID' : 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar' , 'params' : [
450- adhoc_service_1_param1 , adhoc_service_1_param2 ]})()
451-
452- adhoc_services = {
453- 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar' : adhoc_service_1 ,
454- 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar' : adhoc_service_2
455- }
456-
457- def __init__ (self , table ):
458- self .table = table
459-
460- def to_table (self ):
461- return self .table
462-
463- @property
464- def status (self ):
465- return ['OK' ]
466-
467- def iter_adhocservices (self ):
468- return [self .adhoc_service_1 , self .adhoc_service_2 ]
469-
470- def get_adhocservice_by_id (self , adhoc_service_id ):
471- return self .adhoc_services [adhoc_service_id ]
472-
473- print (f"\n \n FOUND ARGS { args } \n \n " )
474-
475- if args [0 ] == 'uid://A001/X12a3/Xe9' :
476- return MockResponse (Table .read (data_path ('nrao-datalink.xml' ), format = 'votable' ))
477- elif args [0 ] == '2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar' :
478- return MockResponse (Table .read (data_path ('nrao-datalink-recurse-this.xml' ), format = 'votable' ))
479- elif args [0 ] == '2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar' :
480- return MockResponse (Table .read (data_path ('nrao-datalink-recurse-aux.xml' ), format = 'votable' ))
481-
482- pytest .fail ('Should not get here.' )
483-
484-
485- # @patch('pyvo.dal.adhoc.DatalinkService', side_effect=_mocked_datalink_sync)
486- def test_get_data_info_expand_tarfiles ():
487- class MockDataLinkService :
488- def run_sync (self , uid ):
489- return _mocked_datalink_sync (uid )
490-
491- nrao = Nrao ()
492- nrao ._datalink = MockDataLinkService ()
493- result = nrao .get_data_info (uids = 'uid://A001/X12a3/Xe9' , expand_tarfiles = True )
494-
495- # Entire expanded structure is 19 links long.
496- assert len (result ) == 19
497-
498-
499281def test_galactic_query ():
500282 """
501283 regression test for 1867
@@ -513,34 +295,3 @@ def test_galactic_query():
513295 radius = 1 * u .deg , get_query_payload = True )
514296
515297 assert "'ICRS',266.405,-28.9362,1.0" in result
516-
517-
518- def test_download_files ():
519- def _requests_mock (method , url , ** kwargs ):
520- response = Mock ()
521- response .headers = {
522- 'Content-Disposition' : 'attachment; '
523- 'filename={}' .format (url .split ('/' )[- 1 ])}
524- return response
525-
526- def _download_file_mock (url , file_name , ** kwargs ):
527- return file_name
528- nrao = Nrao ()
529- nrao ._request = Mock (side_effect = _requests_mock )
530- nrao ._download_file = Mock (side_effect = _download_file_mock )
531- downloaded_files = nrao .download_files (['https://location/file1' ])
532- assert len (downloaded_files ) == 1
533- assert downloaded_files [0 ].endswith ('file1' )
534-
535- nrao ._request .reset_mock ()
536- nrao ._download_file .reset_mock ()
537- downloaded_files = nrao .download_files (['https://location/file1' ,
538- 'https://location/file2' ])
539- assert len (downloaded_files ) == 2
540-
541- # error cases
542- nrao ._request = Mock ()
543- # no Content-Disposition results in no downloaded file
544- nrao ._request .return_value = Mock (headers = {})
545- result = nrao .download_files (['https://location/file1' ])
546- assert not result
0 commit comments