99
1010"""
1111import os .path
12+ import shutil
13+ import tempfile
1214from unittest .mock import patch , Mock
1315
1416import astroquery .esa .utils .utils as esautils
@@ -55,6 +57,16 @@ def close_files(file_list):
5557 close_file (file ['fits' ])
5658
5759
60+ def create_temp_folder ():
61+ return tempfile .TemporaryDirectory ()
62+
63+
64+ def copy_to_temporal_path (data_path , temp_folder , filename ):
65+ temp_data_dir = os .path .join (temp_folder .name , filename )
66+ shutil .copy (data_path , temp_data_dir )
67+ return temp_data_dir
68+
69+
5870class TestIntegralTap :
5971
6072 @patch ('pyvo.auth.authsession.AuthSession._request' )
@@ -203,18 +215,23 @@ def test_download_cache(self, mock_get, tmp_cwd):
203215 assert not os .path .exists (filename )
204216 assert os .path .exists (esautils .get_cache_filepath (filename = filename , cache_path = cache_folder ))
205217
206- def test_read_tar (self , tmp_cwd ):
207- tar_file = data_path ('tar_file.tar' )
218+ def test_read_tar (self ):
219+ temp_path = create_temp_folder ()
220+ tar_file = copy_to_temporal_path (data_path = data_path ('tar_file.tar' ), temp_folder = temp_path ,
221+ filename = 'tar_file.tar' )
208222
209223 files = esautils .read_downloaded_fits ([tar_file ])
210224
211225 assert len (files ) == 1
212226 assert files [0 ]['filename' ] == 'test.fits'
213227
214228 close_files (files )
229+ temp_path .cleanup ()
215230
216- def test_read_tar_gz (self , tmp_cwd ):
217- tar_gz_file = data_path ('tar_gz_file.tar.gz' )
231+ def test_read_tar_gz (self ):
232+ temp_path = create_temp_folder ()
233+ tar_gz_file = copy_to_temporal_path (data_path = data_path ('tar_gz_file.tar.gz' ), temp_folder = temp_path ,
234+ filename = 'tar_gz_file.tar.gz' )
218235
219236 files = esautils .read_downloaded_fits ([tar_gz_file ])
220237
@@ -223,16 +240,20 @@ def test_read_tar_gz(self, tmp_cwd):
223240 assert files [0 ]['filename' ] == 'test.fits'
224241
225242 close_files (files )
243+ temp_path .cleanup ()
226244
227- def test_read_zip (self , tmp_cwd ):
228- zip_file = data_path ('tar_file.tar' )
245+ def test_read_zip (self ):
246+ temp_path = create_temp_folder ()
247+ zip_file = copy_to_temporal_path (data_path = data_path ('zip_file.zip' ), temp_folder = temp_path ,
248+ filename = 'zip_file.zip' )
229249
230250 files = esautils .read_downloaded_fits ([zip_file ])
231251
232252 assert len (files ) == 1
233253 assert files [0 ]['filename' ] == 'test.fits'
234254
235255 close_files (files )
256+ temp_path .cleanup ()
236257
237258 def test_read_uncompressed (self , tmp_cwd ):
238259 uncompressed_file = data_path ('test.fits' )
0 commit comments