11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22from datetime import datetime , timezone
33import os
4+ from io import StringIO
45from pathlib import Path
56from urllib .parse import urlparse
67import re
2324except ImportError :
2425 HAS_REGIONS = False
2526
26- # ALMA tests involving staging take too long, leading to travis timeouts
2727# TODO: make this a configuration item
2828SKIP_SLOW = True
2929
@@ -91,14 +91,15 @@ def test_SgrAstar(self, tmp_path, alma):
9191
9292 assert '2013.1.00857.S' in result_s ['Project code' ]
9393
94+ @pytest .mark .skipif ("SKIP_SLOW" )
9495 def test_freq (self , alma ):
9596 payload = {'frequency' : '85..86' }
9697 result = alma .query (payload )
9798 assert len (result ) > 0
9899 for row in result :
99100 # returned em_min and em_max are in m
100101 assert row ['frequency' ] >= 85
101- assert row ['frequency' ] <= 100
102+ assert row ['frequency' ] <= 86
102103 assert '3' in row ['band_list' ]
103104
104105 def test_bands (self , alma ):
@@ -216,10 +217,7 @@ def test_data_info(self, tmp_path, alma):
216217 trimmed_access_url_list = [e for e in data_info_tar ['access_url' ].data if len (e ) > 0 ]
217218 trimmed_access_urls = (trimmed_access_url_list ,)
218219 mock_calls = download_files_mock .mock_calls [0 ][1 ]
219- print (f"\n \n Comparing { mock_calls } to { trimmed_access_urls } \n \n " )
220- # comparison = download_files_mock.mock_calls[0][1] == data_info_tar['access_url']
221220 assert mock_calls == trimmed_access_urls
222- # assert comparison.all()
223221
224222 def test_download_data (self , tmp_path , alma ):
225223 # test only fits files from a program
@@ -239,9 +237,8 @@ def test_download_data(self, tmp_path, alma):
239237 alma ._download_file .call_count == len (results )
240238 assert len (results ) == len (urls )
241239
240+ @pytest .mark .skipif ("SKIP_SLOW" )
242241 def test_download_and_extract (self , tmp_path , alma ):
243- # TODO: slowish, runs for ~90s
244-
245242 alma .cache_location = tmp_path
246243 alma ._cycle0_tarfile_content_table = {'ID' : '' }
247244
@@ -345,16 +342,18 @@ def test_misc(self, alma):
345342
346343 result = alma .query_object ('M83' , public = True , science = True )
347344 assert len (result ) > 0
348- result = alma .query (payload = {'pi_name' : '*Bally*' }, public = False ,
349- maxrec = 10 )
345+ with pytest .warns (expected_warning = DALOverflowWarning ,
346+ match = "Partial result set. Potential causes MAXREC, async storage space, etc." ):
347+ result = alma .query (payload = {'pi_name' : 'Bally*' }, public = True ,
348+ maxrec = 10 )
350349 assert result
351350 # Add overwrite=True in case the test previously died unexpectedly
352351 # and left the temp file.
353352 result .write ('/tmp/alma-onerow.txt' , format = 'ascii' , overwrite = True )
354353 for row in result :
355- assert 'Bally' in row ['obs_creator_name ' ]
354+ assert 'Bally' in row ['pi_name ' ]
356355 result = alma .query (payload = dict (project_code = '2016.1.00165.S' ),
357- public = False )
356+ public = True )
358357 assert result
359358 for row in result :
360359 assert '2016.1.00165.S' == row ['proposal_id' ]
@@ -398,8 +397,9 @@ def test_misc(self, alma):
398397 assert result
399398 for row in result :
400399 assert '6' == row ['band_list' ]
401- assert 'ginsburg' in row ['obs_creator_name ' ].lower ()
400+ assert 'ginsburg' in row ['pi_name ' ].lower ()
402401
402+ @pytest .mark .skip ("Not sure what this is supposed to do" )
403403 def test_user (self , alma ):
404404 # miscellaneous set of tests from current users
405405 rslt = alma .query ({'band_list' : [6 ], 'project_code' : '2012.1.*' },
@@ -561,6 +561,36 @@ def test_big_download_regression(alma):
561561 alma .download_files ([files ['access_url' ][3 ]])
562562
563563
564+ @pytest .mark .remote_data
565+ def test_tap_upload ():
566+ tmp_table = StringIO ('''<?xml version="1.0" encoding="UTF-8"?>
567+ <VOTABLE xmlns="http://www.ivoa.net/xml/VOTable/v1.3"
568+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3">
569+ <RESOURCE>
570+ <TABLE>
571+ <FIELD name="prop_id" datatype="char" arraysize="*">
572+ <DESCRIPTION>external URI for the physical artifact</DESCRIPTION>
573+ </FIELD>
574+ <DATA>
575+ <TABLEDATA>
576+ <TR>
577+ <TD>2013.1.01365.S</TD>
578+ </TR>
579+ </TABLEDATA>
580+ </DATA>
581+ </TABLE>
582+ </RESOURCE>
583+ </VOTABLE>''' )
584+
585+ alma = Alma ()
586+ res = alma .query_tap (
587+ 'select top 3 proposal_id from ivoa.ObsCore oc join TAP_UPLOAD.proj_codes pc on oc.proposal_id=pc.prop_id' ,
588+ uploads = {'proj_codes' : tmp_table })
589+ assert len (res ) == 3
590+ for row in res :
591+ assert row ['proposal_id' ] == '2013.1.01365.S'
592+
593+
564594@pytest .mark .remote_data
565595def test_download_html_file (alma , tmp_path ):
566596 alma .cache_location = tmp_path
0 commit comments