9
9
10
10
"""
11
11
import os
12
+ import shutil
13
+ import tempfile
12
14
13
15
from astropy .coordinates import SkyCoord
14
16
from astroquery .esa .integral import IntegralClass
@@ -30,6 +32,16 @@ def data_path(filename):
30
32
return os .path .join (data_dir , filename )
31
33
32
34
35
+ def create_temp_folder ():
36
+ return tempfile .TemporaryDirectory ()
37
+
38
+
39
+ def copy_to_temporal_path (data_path , temp_folder , filename ):
40
+ temp_data_dir = os .path .join (temp_folder .name , filename )
41
+ shutil .copy (data_path , temp_data_dir )
42
+ return temp_data_dir
43
+
44
+
33
45
def close_file (file ):
34
46
file .close ()
35
47
@@ -325,7 +337,6 @@ def test_download_science_windows_error(self, instrument_band_mock, download_moc
325
337
@patch ('astroquery.esa.integral.core.IntegralClass.get_instrument_band_map' )
326
338
def test_download_science_windows (self , instrument_band_mock , download_mock ):
327
339
instrument_band_mock .return_value = mocks .get_instrument_bands ()
328
- download_mock .return_value = 'file.test'
329
340
330
341
isla = IntegralClass ()
331
342
with pytest .raises (ValueError ) as err :
@@ -336,11 +347,19 @@ def test_download_science_windows(self, instrument_band_mock, download_mock):
336
347
isla .download_science_windows (science_windows = 'sc' , observation_id = 'obs' )
337
348
assert 'Only one parameter can be provided at a time.' in err .value .args [0 ]
338
349
339
- isla .download_science_windows (science_windows = 'sc' )
350
+ temp_path = create_temp_folder ()
351
+ temp_file = copy_to_temporal_path (data_path = data_path ('zip_file.zip' ), temp_folder = temp_path ,
352
+ filename = 'zip_file.zip' )
353
+ download_mock .return_value = temp_file
354
+
355
+ sc = isla .download_science_windows (science_windows = 'sc' )
340
356
341
357
args , kwargs = download_mock .call_args
342
358
assert kwargs ['params' ]['RETRIEVAL_TYPE' ] == 'SCW'
343
359
360
+ close_files (sc )
361
+ temp_path .cleanup ()
362
+
344
363
@patch ('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities' , [])
345
364
@patch ('astroquery.esa.utils.utils.execute_servlet_request' )
346
365
@patch ('astroquery.esa.integral.core.IntegralClass.get_instrument_band_map' )
@@ -349,7 +368,8 @@ def test_get_timeline(self, instrument_band_mock, servlet_mock):
349
368
servlet_mock .return_value = mocks .get_mock_timeline ()
350
369
351
370
isla = IntegralClass ()
352
- timeline = isla .get_timeline (coordinates = '83.63320922851562 22.01447105407715' )
371
+ coords = SkyCoord (ra = 83.63320922851562 , dec = 22.01447105407715 , unit = "deg" )
372
+ timeline = isla .get_timeline (coordinates = coords )
353
373
354
374
assert len (timeline ['timeline' ]['scwRevs' ]) > 0
355
375
@@ -412,7 +432,11 @@ def test_get_long_term_timeseries_exception(self, instrument_band_mock, log_mock
412
432
@patch ('astroquery.esa.integral.core.IntegralClass.get_instrument_band_map' )
413
433
def test_get_long_term_timeseries (self , instrument_band_mock , download_mock ):
414
434
instrument_band_mock .return_value = mocks .get_instrument_bands ()
415
- download_mock .return_value = data_path ('zip_file.zip' )
435
+
436
+ temp_path = create_temp_folder ()
437
+ temp_file = copy_to_temporal_path (data_path = data_path ('zip_file.zip' ), temp_folder = temp_path ,
438
+ filename = 'zip_file.zip' )
439
+ download_mock .return_value = temp_file
416
440
417
441
isla = IntegralClass ()
418
442
mock_instrument_bands (isla_module = isla )
@@ -423,6 +447,7 @@ def test_get_long_term_timeseries(self, instrument_band_mock, download_mock):
423
447
read_fits = False )
424
448
assert type (lt_timeseries_list_compressed ) is str
425
449
close_files (lt_timeseries_list_extracted )
450
+ temp_path .cleanup ()
426
451
427
452
@patch ('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities' , [])
428
453
@patch ('astroquery.esa.integral.core.log' )
@@ -482,7 +507,10 @@ def test_get_short_term_timeseries(self, instrument_band_mock, epoch_mock, downl
482
507
483
508
instrument_band_mock .return_value = mocks .get_instrument_bands ()
484
509
epoch_mock .return_value = {'epoch' : ['time' ]}
485
- download_mock .return_value = data_path ('tar_file.tar' )
510
+ temp_path = create_temp_folder ()
511
+ temp_file = copy_to_temporal_path (data_path = data_path ('tar_file.tar' ), temp_folder = temp_path ,
512
+ filename = 'tar_file.tar' )
513
+ download_mock .return_value = temp_file
486
514
487
515
isla = IntegralClass ()
488
516
mock_instrument_bands (isla_module = isla )
@@ -495,6 +523,7 @@ def test_get_short_term_timeseries(self, instrument_band_mock, epoch_mock, downl
495
523
assert type (st_timeseries_list_compressed ) is str
496
524
497
525
close_files (st_timeseries_list_extracted )
526
+ temp_path .cleanup ()
498
527
499
528
@patch ('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities' , [])
500
529
@patch ('astroquery.esa.integral.core.log' )
@@ -558,7 +587,10 @@ def test_get_spectra(self, instrument_band_mock, servlet_mock, epoch_mock, downl
558
587
instrument_band_mock .return_value = mocks .get_instrument_bands ()
559
588
servlet_mock .return_value = mocks .get_mock_spectra ()
560
589
epoch_mock .return_value = {'epoch' : ['today' ]}
561
- download_mock .return_value = data_path ('tar_file.tar' )
590
+ temp_path = create_temp_folder ()
591
+ temp_file = copy_to_temporal_path (data_path = data_path ('tar_file.tar' ), temp_folder = temp_path ,
592
+ filename = 'tar_file.tar' )
593
+ download_mock .return_value = temp_file
562
594
563
595
isla = IntegralClass ()
564
596
mock_instrument_bands (isla_module = isla )
@@ -571,6 +603,7 @@ def test_get_spectra(self, instrument_band_mock, servlet_mock, epoch_mock, downl
571
603
assert type (spectra_list_compressed ) is list
572
604
573
605
close_files (spectra_list_extracted )
606
+ temp_path .cleanup ()
574
607
575
608
@patch ('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities' , [])
576
609
@patch ('astroquery.esa.integral.core.log' )
@@ -614,7 +647,10 @@ def test_get_mosaic(self, instrument_band_mock, servlet_mock, epoch_mock, downlo
614
647
instrument_band_mock .return_value = mocks .get_instrument_bands ()
615
648
servlet_mock .return_value = mocks .get_mock_mosaic ()
616
649
epoch_mock .return_value = {'epoch' : ['today' ]}
617
- download_mock .return_value = data_path ('tar_gz_file.gz' )
650
+ temp_path = create_temp_folder ()
651
+ temp_file = copy_to_temporal_path (data_path = data_path ('tar_gz_file.gz' ), temp_folder = temp_path ,
652
+ filename = 'tar_gz_file.gz' )
653
+ download_mock .return_value = temp_file
618
654
619
655
isla = IntegralClass ()
620
656
mock_instrument_bands (isla_module = isla )
@@ -625,6 +661,7 @@ def test_get_mosaic(self, instrument_band_mock, servlet_mock, epoch_mock, downlo
625
661
626
662
assert type (mosaics_compressed ) is list
627
663
close_files (mosaics_extracted )
664
+ temp_path .cleanup ()
628
665
629
666
@patch ('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities' , [])
630
667
@patch ('astroquery.esa.utils.utils.execute_servlet_request' )
0 commit comments