1515from astropy .io .fits .hdu .hdulist import HDUList
1616from astropy .io .votable .tree import VOTableFile , Resource , Table , Field
1717from astropy .io .votable import parse
18+ from astropy .utils .diff import report_diff_values
1819from astroquery .utils .commons import parse_coordinates , FileContainer
1920from astropy import units as u
2021import pytest
21- import tempfile
2222import requests
2323
2424from pyvo .auth import securitymethods
@@ -348,7 +348,7 @@ def __init__(self, **param_dict):
348348
349349@patch ('astroquery.cadc.core.get_access_url' ,
350350 Mock (side_effect = lambda x , y = None : 'https://some.url' ))
351- def test_exec_sync ():
351+ def test_exec_sync (tmp_path ):
352352 # save results in a file
353353 # create the VOTable result
354354 # example from http://docs.astropy.org/en/stable/io/votable/
@@ -369,20 +369,29 @@ def test_exec_sync():
369369 response = Mock ()
370370 response .to_table .return_value = table .to_table ()
371371 cadc .cadctap .search = Mock (return_value = response )
372- output_file = '{}/test_vooutput.xml' .format (tempfile .tempdir )
373- cadc .exec_sync ('some query' , output_file = output_file )
374-
375- actual = parse (output_file )
376- assert len (votable .resources ) == len (actual .resources ) == 1
377- assert len (votable .resources [0 ].tables ) == \
378- len (actual .resources [0 ].tables ) == 1
379- actual_table = actual .resources [0 ].tables [0 ]
380- try :
381- # TODO remove when astropy LTS upgraded
382- from astropy .utils .diff import report_diff_values
372+
373+ output_files = [os .path .join (tmp_path , 'test_vooutput.xml' ),
374+ Path (tmp_path , 'test_path_vooutput.xml' )]
375+
376+ for output_file in output_files :
377+ cadc .exec_sync ('some query' , output_file = output_file )
378+
379+ actual = parse (output_file )
380+ assert len (votable .resources ) == len (actual .resources ) == 1
381+ assert len (votable .resources [0 ].tables ) == \
382+ len (actual .resources [0 ].tables ) == 1
383+ actual_table = actual .resources [0 ].tables [0 ]
384+
385+ assert report_diff_values (table , actual_table , fileobj = sys .stdout )
386+
387+ # check file handlers, but skip on windows as it has issues with
388+ # context managers and open files
389+ if not sys .platform .startswith ('win' ):
390+ with open (os .path .join (tmp_path , 'test_open_file_handler.xml' ), 'w+b' ) as open_file :
391+ cadc .exec_sync ('some query' , output_file = open_file )
392+
393+ actual = parse (os .path .join (tmp_path , 'test_open_file_handler.xml' ))
383394 assert report_diff_values (table , actual_table , fileobj = sys .stdout )
384- except ImportError :
385- pass
386395
387396
388397@patch ('astroquery.cadc.core.CadcClass.exec_sync' , Mock ())
0 commit comments