TST: adding regression test for issue 2540
@@ -10,15 +10,16 @@ from urllib.parse import urlsplit, parse_qs
from pathlib import Path
import os
import sys
+from pathlib import Path
from astropy.table import Table as AstroTable
from astropy.io.fits.hdu.hdulist import HDUList
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field
from astropy.io.votable import parse
+from astropy.utils.diff import report_diff_values
from astroquery.utils.commons import parse_coordinates, FileContainer
from astropy import units as u
import pytest
-import tempfile
import requests
from pyvo.auth import securitymethods
@@ -348,7 +349,7 @@ def test_get_image_list():
@patch('astroquery.cadc.core.get_access_url',
Mock(side_effect=lambda x, y=None: 'https://some.url'))
-def test_exec_sync():
+def test_exec_sync(tmp_path):
# save results in a file
# create the VOTable result
# example from http://docs.astropy.org/en/stable/io/votable/
@@ -369,7 +370,11 @@ def test_exec_sync():
response = Mock()
response.to_table.return_value = table.to_table()
cadc.cadctap.search = Mock(return_value=response)
- output_file = '{}/test_vooutput.xml'.format(tempfile.tempdir)
+
+ output_files = [os.path.join(tmp_path, 'test_vooutput.xml'),
+ Path(tmp_path, 'test_path_vooutput.xml')]
+
+ for output_file in output_files:
cadc.exec_sync('some query', output_file=output_file)
actual = parse(output_file)
@@ -377,12 +382,15 @@ def test_exec_sync():
assert len(votable.resources[0].tables) ==\
len(actual.resources[0].tables) == 1
actual_table = actual.resources[0].tables[0]
- try:
- # TODO remove when astropy LTS upgraded
- from astropy.utils.diff import report_diff_values
+
+ assert report_diff_values(table, actual_table, fileobj=sys.stdout)
+
+ # check file handlers, too
+ with open(os.path.join(tmp_path, 'test_open_file_handler.xml'), 'w+b') as open_file:
+ cadc.exec_sync('some query', output_file=open_file)
+
+ actual = parse(os.path.join(tmp_path, 'test_open_file_handler.xml'))
assert report_diff_values(table, actual_table, fileobj=sys.stdout)
- except ImportError:
- pass
@patch('astroquery.cadc.core.CadcClass.exec_sync', Mock())
