Skip to content

Commit 1368992

Browse files
authored
Merge pull request #2361 from lvalerom/fix-string-formatting-in-dummy-handler
Fix string formatting in "dummy handlers"
2 parents 82136f4 + 80883cf commit 1368992

File tree

6 files changed

+29
-59
lines changed

6 files changed

+29
-59
lines changed

astroquery/esa/hsa/tests/dummy_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ def check_parameters(self, parameters, method_name):
4040
f"Expected:'{parameters[key]}'")
4141
else:
4242
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")
43-
return True

astroquery/esa/hubble/tests/dummy_tap_handler.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,37 @@
1818
class DummyHubbleTapHandler:
1919

2020
def __init__(self, method, parameters):
21-
self.__invokedMethod = method
21+
self._invokedMethod = method
2222
self._parameters = parameters
2323

2424
def reset(self):
2525
self._parameters = {}
26-
self.__invokedMethod = None
26+
self._invokedMethod = None
2727

2828
def check_call(self, method_name, parameters):
2929
self.check_method(method_name)
3030
self.check_parameters(parameters, method_name)
3131

3232
def check_method(self, method):
33-
if method != self.__invokedMethod:
34-
raise Exception("Method '" + str(method) + ""
35-
"' not invoked. (Invoked method is '"
36-
"" + str(self.__invokedMethod)+"')")
33+
if method != self._invokedMethod:
34+
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
35+
f"is '{self._invokedMethod}').")
3736

3837
def check_parameters(self, parameters, method_name):
3938
if parameters is None:
4039
return len(self._parameters) == 0
4140
if len(parameters) != len(self._parameters):
42-
raise Exception("Wrong number of parameters for method '%s'. "
43-
"Found: %d. Expected %d",
44-
(method_name,
45-
len(self._parameters),
46-
len(parameters)))
41+
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
42+
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
4743
for key in parameters:
4844
if key in self._parameters:
4945
# check value
5046
if self._parameters[key] != parameters[key]:
51-
raise Exception("Wrong '%s' parameter value for method '%s'. \
52-
Found: '%s'. Expected: '%s'", (
53-
method_name,
54-
key,
55-
self._parameters[key],
56-
parameters[key]))
47+
raise ValueError(f"Wrong '{key}' parameter "
48+
f"value for method '{method_name}'. "
49+
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
5750
else:
58-
raise Exception("Parameter '%s' not found for method '%s'",
59-
(str(key), method_name))
60-
return False
51+
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")
6152

6253
def launch_job(self, query, name=None, output_file=None,
6354
output_format="votable", verbose=False, dump_to_file=False,

astroquery/esa/iso/tests/dummy_handler.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,21 @@ def check_method(self, method):
3030
if method == self._invokedMethod:
3131
return
3232
else:
33-
raise ValueError("Method '{}' is not invoked. (Invoked method \
34-
is '{}'.)").format(method, self_invokedMethod)
33+
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
34+
f"is '{self._invokedMethod}').")
3535

3636
def check_parameters(self, parameters, method_name):
3737
if parameters is None:
3838
return len(self._parameters) == 0
3939
if len(parameters) != len(self._parameters):
40-
raise ValueError("Wrong number of parameters for method '{}'. \
41-
Found: {}. Expected {}").format(
42-
method_name,
43-
len(self._parameters),
44-
len(parameters))
40+
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
41+
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
4542
for key in parameters:
4643
if key in self._parameters:
4744
# check value
4845
if self._parameters[key] != parameters[key]:
49-
raise ValueError("Wrong '{}' parameter \
50-
value for method '{}'. \
51-
Found:'{}'. Expected:'{}'").format(
52-
method_name,
53-
key,
54-
self._parameters[key],
55-
parameters[key])
46+
raise ValueError(f"Wrong '{key}' parameter "
47+
f"value for method '{method_name}'. "
48+
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
5649
else:
57-
raise ValueError("Parameter '%s' not found in method '%s'",
58-
(str(key), method_name))
59-
return True
50+
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")

astroquery/esa/jwst/tests/DummyDataHandler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ def check_parameters(self, parameters, method_name):
4545
if key in self.__parameters:
4646
# check value
4747
if self.__parameters[key] != parameters[key]:
48-
raise ValueError(f"Wrong '{method_name}' parameter "
49-
f"value for method '{key}'. "
48+
raise ValueError(f"Wrong '{key}' parameter "
49+
f"value for method '{method_name}'. "
5050
f"Found: '{self.__parameters[key]}'. "
5151
f"Expected: '{parameters[key]}'")
5252
else:
5353
raise ValueError(f"Parameter '{str(key)}' not found for "
5454
f"method '{method_name}'")
55-
return False
5655

5756
def download_file(self, url=None):
5857
self.__invokedMethod = 'download_file'

astroquery/esa/jwst/tests/DummyTapHandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def check_parameters(self, parameters, method_name):
7575
else:
7676
raise ValueError(f"Parameter '{str(key)}' not found "
7777
f"for method '{method_name}'")
78-
return False
7978

8079
def load_tables(self, only_names=False, include_shared_tables=False,
8180
verbose=False):

astroquery/esa/xmm_newton/tests/dummy_handler.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,21 @@ def check_method(self, method):
3131
if method == self._invokedMethod:
3232
return
3333
else:
34-
raise ValueError("Method '{}' is not invoked. (Invoked method \
35-
is '{}'.)").format(method, self._invokedMethod)
34+
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
35+
f"is '{self._invokedMethod}').")
3636

3737
def check_parameters(self, parameters, method_name):
3838
if parameters is None:
3939
return len(self._parameters) == 0
4040
if len(parameters) != len(self._parameters):
41-
raise ValueError("Wrong number of parameters for method '{}'. \
42-
Found: {}. Expected {}").format(
43-
method_name,
44-
len(self._parameters),
45-
len(parameters))
41+
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
42+
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
4643
for key in parameters:
4744
if key in self._parameters:
4845
# check value
4946
if self._parameters[key] != parameters[key]:
50-
raise ValueError("Wrong '{}' parameter \
51-
value for method '{}'. \
52-
Found:'{}'. Expected:'{}'").format(
53-
method_name,
54-
key,
55-
self._parameters[key],
56-
parameters[key])
47+
raise ValueError(f"Wrong '{key}' parameter "
48+
f"value for method '{method_name}'. "
49+
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
5750
else:
58-
raise ValueError("Parameter '%s' not found in method '%s'",
59-
(str(key), method_name))
60-
return True
51+
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")

0 commit comments

Comments
 (0)