1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
3
3
import os
4
- import shutil
5
4
import pytest
5
+ import tempfile
6
6
import astropy .units as u
7
7
from astropy .table import Table
8
8
from astropy .coordinates import SkyCoord
@@ -83,6 +83,7 @@ def test_query_region_cone(self, coordinates):
83
83
spatial = "cone" ,
84
84
columns = "*" ,
85
85
radius = 1 * u .arcmin ,
86
+ add_offset = True
86
87
)
87
88
assert isinstance (result , Table )
88
89
assert len (result ) == 3
@@ -95,11 +96,12 @@ def test_query_columns_radius(self):
95
96
"""
96
97
result = Heasarc .query_region (
97
98
"NGC 4151" , catalog = "suzamaster" , columns = "ra,dec,obsid" ,
98
- radius = 10 * u .arcmin
99
+ radius = 10 * u .arcmin ,
100
+ add_offset = True
99
101
)
100
102
assert len (result ) == 4
101
103
# assert only selected columns are returned
102
- assert result .colnames == ["ra" , "dec" , "obsid" , "search_offset_ " ]
104
+ assert result .colnames == ["ra" , "dec" , "obsid" , "search_offset " ]
103
105
104
106
def test_query_region_box (self ):
105
107
result = Heasarc .query_region (
@@ -196,9 +198,9 @@ def test_download_data__heasarc_file(self):
196
198
f"data/archive/{ filename } " )
197
199
]
198
200
})
199
- Heasarc . download_data ( tab , host = "heasarc" , location = "." )
200
- assert os . path . exists ( filename )
201
- os .remove ( filename )
201
+ with tempfile . TemporaryDirectory () as tmpdir :
202
+ Heasarc . download_data ( tab , host = "heasarc" , location = tmpdir )
203
+ assert os .path . exists ( f' { tmpdir } / { filename } ' )
202
204
203
205
def test_download_data__heasarc_folder (self ):
204
206
tab = Table ({
@@ -207,21 +209,22 @@ def test_download_data__heasarc_folder(self):
207
209
"AO10/P91129/91129-01-68-00A/stdprod" )
208
210
]
209
211
})
210
- Heasarc . download_data ( tab , host = "heasarc" , location = "." )
211
- assert os . path . exists ( "stdprod" )
212
- assert os .path .exists ("stdprod/FHed_1791a7b9-1791a931.gz " )
213
- assert os .path .exists (" stdprod/FHee_1791a7b9-1791a92f .gz" )
214
- assert os .path .exists (" stdprod/FHef_1791a7b9 -1791a92f.gz" )
215
- shutil . rmtree ( " stdprod" )
212
+ with tempfile . TemporaryDirectory () as tmpdir :
213
+ Heasarc . download_data ( tab , host = "heasarc" , location = tmpdir )
214
+ assert os .path .exists (f" { tmpdir } /stdprod " )
215
+ assert os .path .exists (f" { tmpdir } / stdprod/FHed_1791a7b9-1791a931 .gz" )
216
+ assert os .path .exists (f" { tmpdir } / stdprod/FHee_1791a7b9 -1791a92f.gz" )
217
+ assert os . path . exists ( f" { tmpdir } / stdprod/FHef_1791a7b9-1791a92f.gz " )
216
218
217
219
def test_download_data__s3_file (self ):
218
220
filename = "00README"
219
221
tab = Table (
220
222
{"aws" : [f"s3://nasa-heasarc/rxte/data/archive/{ filename } " ]}
221
223
)
222
- Heasarc .download_data (tab , host = "aws" , location = "." )
223
- assert os .path .exists (filename )
224
- os .remove (filename )
224
+ with tempfile .TemporaryDirectory () as tmpdir :
225
+ Heasarc .enable_cloud (provider = 'aws' , profile = None )
226
+ Heasarc .download_data (tab , host = "aws" , location = tmpdir )
227
+ assert os .path .exists (f'{ tmpdir } /{ filename } ' )
225
228
226
229
@pytest .mark .parametrize ("slash" , ["" , "/" ])
227
230
def test_download_data__s3_folder (self , slash ):
@@ -233,12 +236,13 @@ def test_download_data__s3_folder(self, slash):
233
236
]
234
237
}
235
238
)
236
- Heasarc .download_data (tab , host = "aws" , location = "." )
237
- assert os .path .exists ("stdprod" )
238
- assert os .path .exists ("stdprod/FHed_1791a7b9-1791a931.gz" )
239
- assert os .path .exists ("stdprod/FHee_1791a7b9-1791a92f.gz" )
240
- assert os .path .exists ("stdprod/FHef_1791a7b9-1791a92f.gz" )
241
- shutil .rmtree ("stdprod" )
239
+ with tempfile .TemporaryDirectory () as tmpdir :
240
+ Heasarc .enable_cloud (provider = 'aws' , profile = None )
241
+ Heasarc .download_data (tab , host = "aws" , location = tmpdir )
242
+ assert os .path .exists (f"{ tmpdir } /stdprod" )
243
+ assert os .path .exists (f"{ tmpdir } /stdprod/FHed_1791a7b9-1791a931.gz" )
244
+ assert os .path .exists (f"{ tmpdir } /stdprod/FHee_1791a7b9-1791a92f.gz" )
245
+ assert os .path .exists (f"{ tmpdir } /stdprod/FHef_1791a7b9-1791a92f.gz" )
242
246
243
247
def test_query_mission_columns (self ):
244
248
with pytest .warns (AstropyDeprecationWarning ):
0 commit comments