3
3
import tarfile
4
4
5
5
import pytest
6
- from requests .exceptions import ChunkedEncodingError
7
6
8
7
from ..core import HSAClass
9
8
20
19
21
20
@pytest .mark .remote_data
22
21
class TestHSARemote :
23
- retries = 2
24
-
25
- def access_archive_with_retries (self , f , params ):
26
- for _ in range (self .retries ):
27
- try :
28
- res = f (** params )
29
- return res
30
- except ChunkedEncodingError :
31
- pass
32
- return None
33
22
34
23
def test_download_data_observation_pacs (self , tmp_path ):
35
24
obs_id = "1342191813"
@@ -41,9 +30,7 @@ def test_download_data_observation_pacs(self, tmp_path):
41
30
'download_dir' : tmp_path }
42
31
expected_res = Path (tmp_path , obs_id + ".tar" )
43
32
hsa = HSAClass ()
44
- res = self .access_archive_with_retries (hsa .download_data , parameters )
45
- if res is None :
46
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
33
+ res = hsa .download_data (** parameters )
47
34
assert Path (res ) == expected_res
48
35
assert Path (res ).is_file ()
49
36
with tarfile .open (res ) as tar :
@@ -64,9 +51,7 @@ def test_download_data_observation_pacs_filename(self, tmp_path):
64
51
'download_dir' : tmp_path }
65
52
expected_res = Path (tmp_path , fname + ".tar" )
66
53
hsa = HSAClass ()
67
- res = self .access_archive_with_retries (hsa .download_data , parameters )
68
- if res is None :
69
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
54
+ res = hsa .download_data (** parameters )
70
55
assert Path (res ) == expected_res
71
56
assert Path (res ).is_file ()
72
57
with tarfile .open (res ) as tar :
@@ -86,9 +71,7 @@ def test_download_data_observation_pacs_compressed(self, tmp_path):
86
71
'download_dir' : tmp_path }
87
72
expected_res = Path (tmp_path , obs_id + ".tgz" )
88
73
hsa = HSAClass ()
89
- res = self .access_archive_with_retries (hsa .download_data , parameters )
90
- if res is None :
91
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
74
+ res = hsa .download_data (** parameters )
92
75
assert Path (res ) == expected_res
93
76
assert Path (res ).is_file ()
94
77
with tarfile .open (res ) as tar :
@@ -107,9 +90,7 @@ def test_download_data_observation_spire(self, tmp_path):
107
90
'download_dir' : tmp_path }
108
91
expected_res = Path (tmp_path , obs_id + ".tar" )
109
92
hsa = HSAClass ()
110
- res = self .access_archive_with_retries (hsa .download_data , parameters )
111
- if res is None :
112
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
93
+ res = hsa .download_data (** parameters )
113
94
assert Path (res ) == expected_res
114
95
assert Path (res ).is_file ()
115
96
with tarfile .open (res ) as tar :
@@ -127,9 +108,7 @@ def test_download_data_postcard_pacs(self, tmp_path):
127
108
'download_dir' : tmp_path }
128
109
expected_res = Path (tmp_path , obs_id + ".jpg" )
129
110
hsa = HSAClass ()
130
- res = self .access_archive_with_retries (hsa .download_data , parameters )
131
- if res is None :
132
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
111
+ res = hsa .download_data (** parameters )
133
112
assert Path (res ) == expected_res
134
113
assert Path (res ).is_file ()
135
114
@@ -144,9 +123,7 @@ def test_download_data_postcard_pacs_filename(self, tmp_path):
144
123
'download_dir' : tmp_path }
145
124
expected_res = Path (tmp_path , fname + ".jpg" )
146
125
hsa = HSAClass ()
147
- res = self .access_archive_with_retries (hsa .download_data , parameters )
148
- if res is None :
149
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
126
+ res = hsa .download_data (** parameters )
150
127
assert Path (res ) == expected_res
151
128
assert Path (res ).is_file ()
152
129
@@ -159,9 +136,7 @@ def test_get_observation(self, tmp_path):
159
136
'download_dir' : tmp_path }
160
137
expected_res = Path (tmp_path , obs_id + ".tar" )
161
138
hsa = HSAClass ()
162
- res = self .access_archive_with_retries (hsa .get_observation , parameters )
163
- if res is None :
164
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
139
+ res = hsa .get_observation (** parameters )
165
140
assert Path (res ) == expected_res
166
141
assert Path (res ).is_file ()
167
142
with tarfile .open (res ) as tar :
@@ -178,8 +153,6 @@ def test_get_postcard(self, tmp_path):
178
153
'download_dir' : tmp_path }
179
154
expected_res = Path (tmp_path , obs_id + ".jpg" )
180
155
hsa = HSAClass ()
181
- res = self .access_archive_with_retries (hsa .get_postcard , parameters )
182
- if res is None :
183
- pytest .xfail (f"Archive broke the connection { self .retries } times, unable to test" )
156
+ res = hsa .get_postcard (** parameters )
184
157
assert Path (res ) == expected_res
185
158
assert Path (res ).is_file ()
0 commit comments