10
10
from pathlib import Path
11
11
import os
12
12
import sys
13
+ from pathlib import Path
13
14
14
15
from astropy .table import Table as AstroTable
15
16
from astropy .io .fits .hdu .hdulist import HDUList
16
17
from astropy .io .votable .tree import VOTableFile , Resource , Table , Field
17
18
from astropy .io .votable import parse
19
+ from astropy .utils .diff import report_diff_values
18
20
from astroquery .utils .commons import parse_coordinates , FileContainer
19
21
from astropy import units as u
20
22
import pytest
21
- import tempfile
22
23
import requests
23
24
24
25
from pyvo .auth import securitymethods
@@ -348,7 +349,7 @@ def __init__(self, **param_dict):
348
349
349
350
@patch ('astroquery.cadc.core.get_access_url' ,
350
351
Mock (side_effect = lambda x , y = None : 'https://some.url' ))
351
- def test_exec_sync ():
352
+ def test_exec_sync (tmp_path ):
352
353
# save results in a file
353
354
# create the VOTable result
354
355
# example from http://docs.astropy.org/en/stable/io/votable/
@@ -369,20 +370,27 @@ def test_exec_sync():
369
370
response = Mock ()
370
371
response .to_table .return_value = table .to_table ()
371
372
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
373
+
374
+ output_files = [os .path .join (tmp_path , 'test_vooutput.xml' ),
375
+ Path (tmp_path , 'test_path_vooutput.xml' )]
376
+
377
+ for output_file in output_files :
378
+ cadc .exec_sync ('some query' , output_file = output_file )
379
+
380
+ actual = parse (output_file )
381
+ assert len (votable .resources ) == len (actual .resources ) == 1
382
+ assert len (votable .resources [0 ].tables ) == \
383
+ len (actual .resources [0 ].tables ) == 1
384
+ actual_table = actual .resources [0 ].tables [0 ]
385
+
383
386
assert report_diff_values (table , actual_table , fileobj = sys .stdout )
384
- except ImportError :
385
- pass
387
+
388
+ # check file handlers, too
389
+ with open (os .path .join (tmp_path , 'test_open_file_handler.xml' ), 'w+b' ) as open_file :
390
+ cadc .exec_sync ('some query' , output_file = open_file )
391
+
392
+ actual = parse (os .path .join (tmp_path , 'test_open_file_handler.xml' ))
393
+ assert report_diff_values (table , actual_table , fileobj = sys .stdout )
386
394
387
395
388
396
@patch ('astroquery.cadc.core.CadcClass.exec_sync' , Mock ())
0 commit comments