9
9
10
10
"""
11
11
import os .path
12
+ import shutil
13
+ import tempfile
12
14
from unittest .mock import patch , Mock
13
15
14
16
import astroquery .esa .utils .utils as esautils
@@ -55,6 +57,16 @@ def close_files(file_list):
55
57
close_file (file ['fits' ])
56
58
57
59
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
+
58
70
class TestIntegralTap :
59
71
60
72
@patch ('pyvo.auth.authsession.AuthSession._request' )
@@ -203,18 +215,23 @@ def test_download_cache(self, mock_get, tmp_cwd):
203
215
assert not os .path .exists (filename )
204
216
assert os .path .exists (esautils .get_cache_filepath (filename = filename , cache_path = cache_folder ))
205
217
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' )
208
222
209
223
files = esautils .read_downloaded_fits ([tar_file ])
210
224
211
225
assert len (files ) == 1
212
226
assert files [0 ]['filename' ] == 'test.fits'
213
227
214
228
close_files (files )
229
+ temp_path .cleanup ()
215
230
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' )
218
235
219
236
files = esautils .read_downloaded_fits ([tar_gz_file ])
220
237
@@ -223,16 +240,20 @@ def test_read_tar_gz(self, tmp_cwd):
223
240
assert files [0 ]['filename' ] == 'test.fits'
224
241
225
242
close_files (files )
243
+ temp_path .cleanup ()
226
244
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' )
229
249
230
250
files = esautils .read_downloaded_fits ([zip_file ])
231
251
232
252
assert len (files ) == 1
233
253
assert files [0 ]['filename' ] == 'test.fits'
234
254
235
255
close_files (files )
256
+ temp_path .cleanup ()
236
257
237
258
def test_read_uncompressed (self , tmp_cwd ):
238
259
uncompressed_file = data_path ('test.fits' )
0 commit comments