15
15
from astropy .io .fits .hdu .hdulist import HDUList
16
16
from astropy .io .votable .tree import VOTableFile , Resource , Table , Field
17
17
from astropy .io .votable import parse
18
+ from astropy .utils .diff import report_diff_values
18
19
from astroquery .utils .commons import parse_coordinates , FileContainer
19
20
from astropy import units as u
20
21
import pytest
21
- import tempfile
22
22
import requests
23
23
24
24
from pyvo .auth import securitymethods
@@ -348,7 +348,7 @@ def __init__(self, **param_dict):
348
348
349
349
@patch ('astroquery.cadc.core.get_access_url' ,
350
350
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
351
- def test_exec_sync ():
351
+ def test_exec_sync (tmp_path ):
352
352
# save results in a file
353
353
# create the VOTable result
354
354
# example from http://docs.astropy.org/en/stable/io/votable/
@@ -369,20 +369,29 @@ def test_exec_sync():
369
369
response = Mock ()
370
370
response .to_table .return_value = table .to_table ()
371
371
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' ))
383
394
assert report_diff_values (table , actual_table , fileobj = sys .stdout )
384
- except ImportError :
385
- pass
386
395
387
396
388
397
@patch ('astroquery.cadc.core.CadcClass.exec_sync' , Mock ())
0 commit comments