Skip to content

Commit ec61ab1

Browse files
committed
TST: adding regression test for issue 2540
1 parent 4b4af55 commit ec61ab1

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

astroquery/cadc/tests/test_cadctap.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
from pathlib import Path
1111
import os
1212
import sys
13+
from pathlib import Path
1314

1415
from astropy.table import Table as AstroTable
1516
from astropy.io.fits.hdu.hdulist import HDUList
1617
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field
1718
from astropy.io.votable import parse
19+
from astropy.utils.diff import report_diff_values
1820
from astroquery.utils.commons import parse_coordinates, FileContainer
1921
from astropy import units as u
2022
import pytest
21-
import tempfile
2223
import requests
2324

2425
from pyvo.auth import securitymethods
@@ -348,7 +349,7 @@ def __init__(self, **param_dict):
348349

349350
@patch('astroquery.cadc.core.get_access_url',
350351
Mock(side_effect=lambda x, y=None: 'https://some.url'))
351-
def test_exec_sync():
352+
def test_exec_sync(tmp_path):
352353
# save results in a file
353354
# create the VOTable result
354355
# example from http://docs.astropy.org/en/stable/io/votable/
@@ -369,20 +370,27 @@ def test_exec_sync():
369370
response = Mock()
370371
response.to_table.return_value = table.to_table()
371372
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+
383386
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)
386394

387395

388396
@patch('astroquery.cadc.core.CadcClass.exec_sync', Mock())

0 commit comments

Comments
 (0)