Skip to content

Commit 9143453

Browse files
committed
fix string formatting, and change skip to xfail
1 parent aa4078c commit 9143453

File tree

4 files changed

+39
-53
lines changed

4 files changed

+39
-53
lines changed

astroquery/esa/hsa/core.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def download_data(self, *, retrieval_type="OBSERVATION", observation_id=None,
9292
if product_level is not None:
9393
params['product_level'] = product_level
9494

95-
link = self.data_url + "".join("&{0}={1}".format(key, val) for key, val in params.items())
95+
link = self.data_url + "".join(f"&{key}={val}" for key, val in params.items())
9696

97-
link += "".join("&{0}={1}".format(key, val) for key, val in kwargs.items())
97+
link += "".join(f"&{key}={val}" for key, val in kwargs.items())
9898

9999
if verbose:
100100
log.info(link)
@@ -128,7 +128,7 @@ def download_data(self, *, retrieval_type="OBSERVATION", observation_id=None,
128128
self._download_file(link, filename, head_safe=True, cache=cache)
129129

130130
if verbose:
131-
log.info("Wrote {0} to {1}".format(link, filename))
131+
log.info(f"Wrote {link} to {filename}")
132132

133133
return filename
134134

@@ -191,9 +191,9 @@ def get_observation(self, observation_id, instrument_name, *, filename=None,
191191
if product_level is not None:
192192
params['product_level'] = product_level
193193

194-
link = self.data_url + "".join("&{0}={1}".format(key, val) for key, val in params.items())
194+
link = self.data_url + "".join(f"&{key}={val}" for key, val in params.items())
195195

196-
link += "".join("&{0}={1}".format(key, val) for key, val in kwargs.items())
196+
link += "".join(f"&{key}={val}" for key, val in kwargs.items())
197197

198198
if verbose:
199199
log.info(link)
@@ -220,7 +220,7 @@ def get_observation(self, observation_id, instrument_name, *, filename=None,
220220
self._download_file(link, filename, head_safe=True, cache=cache)
221221

222222
if verbose:
223-
log.info("Wrote {0} to {1}".format(link, filename))
223+
log.info(f"Wrote {link} to {filename}")
224224

225225
return filename
226226

@@ -268,9 +268,9 @@ def get_postcard(self, observation_id, instrument_name, *, filename=None,
268268
'observation_id': observation_id,
269269
'instrument_name': instrument_name}
270270

271-
link = self.data_url + "".join("&{0}={1}".format(key, val) for key, val in params.items())
271+
link = self.data_url + "".join(f"&{key}={val}" for key, val in params.items())
272272

273-
link += "".join("&{0}={1}".format(key, val) for key, val in kwargs.items())
273+
link += "".join(f"&{key}={val}" for key, val in kwargs.items())
274274

275275
if verbose:
276276
log.info(link)
@@ -292,7 +292,7 @@ def get_postcard(self, observation_id, instrument_name, *, filename=None,
292292
shutil.move(local_filepath, filename)
293293

294294
if verbose:
295-
log.info("Wrote {0} to {1}".format(link, filename))
295+
log.info(f"Wrote {link} to {filename}")
296296

297297
return filename
298298

@@ -401,10 +401,10 @@ def query_observations(self, coordinate, radius, *, n_obs=10):
401401
r = radius*u.deg
402402
coord = commons.parse_coordinates(coordinate).icrs
403403

404-
query = ("select top {} observation_id from hsa.v_active_observation "
405-
"where contains(point('ICRS', hsa.v_active_observation.ra, "
406-
"hsa.v_active_observation.dec), circle('ICRS', {},{},{}))=1")\
407-
.format(n_obs, coord.ra.degree, coord.dec.degree, r.to(u.deg).value)
404+
query = (f"select top {n_obs} observation_id from hsa.v_active_observation "
405+
f"where contains("
406+
f"point('ICRS', hsa.v_active_observation.ra, hsa.v_active_observation.dec), "
407+
f"circle('ICRS', {coord.ra.degree},{coord.dec.degree},{r.to(u.deg).value}))=1")
408408
return self.query_hsa_tap(query)
409409

410410

astroquery/esa/hsa/tests/dummy_handler.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,23 @@ def check_method(self, method):
2121
if method == self._invokedMethod:
2222
return
2323
else:
24-
raise ValueError("Method '{}' is not invoked. (Invoked method "
25-
"is '{}'.)".format(method, self._invokedMethod))
24+
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
25+
f"is '{self._invokedMethod}'.")
2626

2727
def check_parameters(self, parameters, method_name):
2828
if parameters is None:
2929
return len(self._parameters) == 0
3030
if len(parameters) != len(self._parameters):
31-
raise ValueError("Wrong number of parameters for method '{}'. "
32-
"Found: {}. Expected {}".format(
33-
method_name,
34-
len(self._parameters),
35-
len(parameters)))
31+
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
32+
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
3633
for key in parameters:
3734
if key in self._parameters:
3835
# check value
3936
if self._parameters[key] != parameters[key]:
40-
raise ValueError("Wrong '{}' parameter "
41-
"value for method '{}'. "
42-
"Found:'{}'. Expected:'{}'".format(
43-
method_name,
44-
key,
45-
self._parameters[key],
46-
parameters[key]))
37+
raise ValueError(f"Wrong '{key}' parameter "
38+
f"value for method '{method_name}'. "
39+
f"Found:'{self._parameters[key]}'. "
40+
f"Expected:'{parameters[key]}'")
4741
else:
48-
raise ValueError("Parameter '{}' not found in method '{}'"
49-
.format(str(key), method_name))
42+
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")
5043
return True

astroquery/esa/hsa/tests/dummy_tap_handler.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,25 @@ def check_call(self, method_name, parameters):
2020

2121
def check_method(self, method):
2222
if method != self.__invokedMethod:
23-
raise Exception("Method '" + str(method) + ""
24-
"' not invoked. (Invoked method is '"
25-
"" + str(self.__invokedMethod)+"')")
23+
raise Exception(f"Method '{method}' "
24+
f"not invoked. (Invoked method is "
25+
f"'{self.__invokedMethod}')")
2626

2727
def check_parameters(self, parameters, method_name):
2828
if parameters is None:
2929
return len(self._parameters) == 0
3030
if len(parameters) != len(self._parameters):
31-
raise Exception("Wrong number of parameters for method '%s'. \
32-
Found: %d. Expected %d",
33-
(method_name,
34-
len(self._parameters),
35-
len(parameters)))
31+
raise Exception(f"Wrong number of parameters for method '{method_name}'. "
32+
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
3633
for key in parameters:
3734
if key in self._parameters:
3835
# check value
3936
if self._parameters[key] != parameters[key]:
40-
raise Exception("Wrong '%s' parameter value for method '%s'. \
41-
Found: '%s'. Expected: '%s'", (
42-
method_name,
43-
key,
44-
self._parameters[key],
45-
parameters[key]))
37+
raise Exception(f"Wrong '{key}' parameter value for method "
38+
f"'{method_name}'. "
39+
f"Found: '{self._parameters[key]}'. Expected: '{parameters[key]}'")
4640
else:
47-
raise Exception("Parameter '%s' not found for method '%s'",
48-
(str(key), method_name))
41+
raise Exception("Parameter '{key}' not found for method 'method_name'")
4942
return False
5043

5144
def launch_job(self, query, name=None, output_file=None,

astroquery/esa/hsa/tests/test_hsa_remote.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_download_data_observation_pacs(self):
3939
hsa = HSAClass()
4040
res = self.access_archive_with_retries(hsa.download_data, parameters)
4141
if res is None:
42-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
42+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
4343
assert res == expected_res
4444
assert os.path.isfile(res)
4545
tar = tarfile.open(res)
@@ -61,7 +61,7 @@ def test_download_data_observation_pacs_filename(self):
6161
hsa = HSAClass()
6262
res = self.access_archive_with_retries(hsa.download_data, parameters)
6363
if res is None:
64-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
64+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
6565
assert res == expected_res
6666
assert os.path.isfile(res)
6767
tar = tarfile.open(res)
@@ -82,7 +82,7 @@ def test_download_data_observation_pacs_compressed(self):
8282
hsa = HSAClass()
8383
res = self.access_archive_with_retries(hsa.download_data, parameters)
8484
if res is None:
85-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
85+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
8686
assert res == expected_res
8787
assert os.path.isfile(res)
8888
tar = tarfile.open(res)
@@ -102,7 +102,7 @@ def test_download_data_observation_spire(self):
102102
hsa = HSAClass()
103103
res = self.access_archive_with_retries(hsa.download_data, parameters)
104104
if res is None:
105-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
105+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
106106
assert res == expected_res
107107
assert os.path.isfile(res)
108108
tar = tarfile.open(res)
@@ -121,7 +121,7 @@ def test_download_data_postcard_pacs(self):
121121
hsa = HSAClass()
122122
res = self.access_archive_with_retries(hsa.download_data, parameters)
123123
if res is None:
124-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
124+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
125125
assert res == expected_res
126126
assert os.path.isfile(res)
127127
os.remove(res)
@@ -139,7 +139,7 @@ def test_download_data_postcard_pacs_filename(self):
139139
hsa = HSAClass()
140140
res = self.access_archive_with_retries(hsa.download_data, parameters)
141141
if res is None:
142-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
142+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
143143
assert res == expected_res
144144
assert os.path.isfile(res)
145145
os.remove(res)
@@ -155,7 +155,7 @@ def test_get_observation(self):
155155
hsa = HSAClass()
156156
res = self.access_archive_with_retries(hsa.get_observation, parameters)
157157
if res is None:
158-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
158+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
159159
assert res == expected_res
160160
assert os.path.isfile(res)
161161
tar = tarfile.open(res)
@@ -173,7 +173,7 @@ def test_get_postcard(self):
173173
hsa = HSAClass()
174174
res = self.access_archive_with_retries(hsa.get_postcard, parameters)
175175
if res is None:
176-
pytest.skip("Archive broke the connection {} times, unable to test".format(self.retries))
176+
pytest.xfail(f"Archive broke the connection {self.retries} times, unable to test")
177177
assert res == expected_res
178178
assert os.path.isfile(res)
179179
os.remove(res)

0 commit comments

Comments
 (0)