Skip to content

Commit

Permalink
Merge pull request #2361 from lvalerom/fix-string-formatting-in-dummy…
Browse files Browse the repository at this point in the history
…-handler

Fix string formatting in "dummy handlers"
  • Loading branch information
bsipocz authored Apr 15, 2022
2 parents 82136f4 + 80883cf commit 1368992
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 59 deletions.
1 change: 0 additions & 1 deletion astroquery/esa/hsa/tests/dummy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ def check_parameters(self, parameters, method_name):
f"Expected:'{parameters[key]}'")
else:
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")
return True
31 changes: 11 additions & 20 deletions astroquery/esa/hubble/tests/dummy_tap_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,37 @@
class DummyHubbleTapHandler:

def __init__(self, method, parameters):
self.__invokedMethod = method
self._invokedMethod = method
self._parameters = parameters

def reset(self):
self._parameters = {}
self.__invokedMethod = None
self._invokedMethod = None

def check_call(self, method_name, parameters):
self.check_method(method_name)
self.check_parameters(parameters, method_name)

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

def check_parameters(self, parameters, method_name):
if parameters is None:
return len(self._parameters) == 0
if len(parameters) != len(self._parameters):
raise Exception("Wrong number of parameters for method '%s'. "
"Found: %d. Expected %d",
(method_name,
len(self._parameters),
len(parameters)))
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
for key in parameters:
if key in self._parameters:
# check value
if self._parameters[key] != parameters[key]:
raise Exception("Wrong '%s' parameter value for method '%s'. \
Found: '%s'. Expected: '%s'", (
method_name,
key,
self._parameters[key],
parameters[key]))
raise ValueError(f"Wrong '{key}' parameter "
f"value for method '{method_name}'. "
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
else:
raise Exception("Parameter '%s' not found for method '%s'",
(str(key), method_name))
return False
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")

def launch_job(self, query, name=None, output_file=None,
output_format="votable", verbose=False, dump_to_file=False,
Expand Down
25 changes: 8 additions & 17 deletions astroquery/esa/iso/tests/dummy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,21 @@ def check_method(self, method):
if method == self._invokedMethod:
return
else:
raise ValueError("Method '{}' is not invoked. (Invoked method \
is '{}'.)").format(method, self_invokedMethod)
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
f"is '{self._invokedMethod}').")

def check_parameters(self, parameters, method_name):
if parameters is None:
return len(self._parameters) == 0
if len(parameters) != len(self._parameters):
raise ValueError("Wrong number of parameters for method '{}'. \
Found: {}. Expected {}").format(
method_name,
len(self._parameters),
len(parameters))
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
for key in parameters:
if key in self._parameters:
# check value
if self._parameters[key] != parameters[key]:
raise ValueError("Wrong '{}' parameter \
value for method '{}'. \
Found:'{}'. Expected:'{}'").format(
method_name,
key,
self._parameters[key],
parameters[key])
raise ValueError(f"Wrong '{key}' parameter "
f"value for method '{method_name}'. "
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
else:
raise ValueError("Parameter '%s' not found in method '%s'",
(str(key), method_name))
return True
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")
5 changes: 2 additions & 3 deletions astroquery/esa/jwst/tests/DummyDataHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ def check_parameters(self, parameters, method_name):
if key in self.__parameters:
# check value
if self.__parameters[key] != parameters[key]:
raise ValueError(f"Wrong '{method_name}' parameter "
f"value for method '{key}'. "
raise ValueError(f"Wrong '{key}' parameter "
f"value for method '{method_name}'. "
f"Found: '{self.__parameters[key]}'. "
f"Expected: '{parameters[key]}'")
else:
raise ValueError(f"Parameter '{str(key)}' not found for "
f"method '{method_name}'")
return False

def download_file(self, url=None):
self.__invokedMethod = 'download_file'
Expand Down
1 change: 0 additions & 1 deletion astroquery/esa/jwst/tests/DummyTapHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def check_parameters(self, parameters, method_name):
else:
raise ValueError(f"Parameter '{str(key)}' not found "
f"for method '{method_name}'")
return False

def load_tables(self, only_names=False, include_shared_tables=False,
verbose=False):
Expand Down
25 changes: 8 additions & 17 deletions astroquery/esa/xmm_newton/tests/dummy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,21 @@ def check_method(self, method):
if method == self._invokedMethod:
return
else:
raise ValueError("Method '{}' is not invoked. (Invoked method \
is '{}'.)").format(method, self._invokedMethod)
raise ValueError(f"Method '{method}' is not invoked. (Invoked method "
f"is '{self._invokedMethod}').")

def check_parameters(self, parameters, method_name):
if parameters is None:
return len(self._parameters) == 0
if len(parameters) != len(self._parameters):
raise ValueError("Wrong number of parameters for method '{}'. \
Found: {}. Expected {}").format(
method_name,
len(self._parameters),
len(parameters))
raise ValueError(f"Wrong number of parameters for method '{method_name}'. "
f"Found: {len(self._parameters)}. Expected {len(parameters)}")
for key in parameters:
if key in self._parameters:
# check value
if self._parameters[key] != parameters[key]:
raise ValueError("Wrong '{}' parameter \
value for method '{}'. \
Found:'{}'. Expected:'{}'").format(
method_name,
key,
self._parameters[key],
parameters[key])
raise ValueError(f"Wrong '{key}' parameter "
f"value for method '{method_name}'. "
f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'")
else:
raise ValueError("Parameter '%s' not found in method '%s'",
(str(key), method_name))
return True
raise ValueError(f"Parameter '{key}' not found in method '{method_name}'")

0 comments on commit 1368992

Please sign in to comment.