From 4689e37a537dc695c3b9db6c47b65c7df92a8aea Mon Sep 17 00:00:00 2001 From: lvalerom Date: Fri, 15 Apr 2022 20:17:12 +0200 Subject: [PATCH 1/4] fix string formatting in "dummy handlers" --- .../esa/hubble/tests/dummy_tap_handler.py | 32 +++++++------------ astroquery/esa/iso/tests/dummy_handler.py | 24 +++++--------- astroquery/esa/jwst/tests/DummyDataHandler.py | 6 ++-- .../esa/xmm_newton/tests/dummy_handler.py | 24 +++++--------- 4 files changed, 31 insertions(+), 55 deletions(-) diff --git a/astroquery/esa/hubble/tests/dummy_tap_handler.py b/astroquery/esa/hubble/tests/dummy_tap_handler.py index 8a0c7a7ab8..0b33f917ef 100644 --- a/astroquery/esa/hubble/tests/dummy_tap_handler.py +++ b/astroquery/esa/hubble/tests/dummy_tap_handler.py @@ -18,46 +18,38 @@ 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}'") + return True def launch_job(self, query, name=None, output_file=None, output_format="votable", verbose=False, dump_to_file=False, diff --git a/astroquery/esa/iso/tests/dummy_handler.py b/astroquery/esa/iso/tests/dummy_handler.py index 367d9a9635..f11739b2d2 100644 --- a/astroquery/esa/iso/tests/dummy_handler.py +++ b/astroquery/esa/iso/tests/dummy_handler.py @@ -30,30 +30,22 @@ 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)) + raise ValueError(f"Parameter '{key}' not found in method '{method_name}'") return True diff --git a/astroquery/esa/jwst/tests/DummyDataHandler.py b/astroquery/esa/jwst/tests/DummyDataHandler.py index f82ac9d576..400a643098 100644 --- a/astroquery/esa/jwst/tests/DummyDataHandler.py +++ b/astroquery/esa/jwst/tests/DummyDataHandler.py @@ -45,14 +45,14 @@ 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 + return True def download_file(self, url=None): self.__invokedMethod = 'download_file' diff --git a/astroquery/esa/xmm_newton/tests/dummy_handler.py b/astroquery/esa/xmm_newton/tests/dummy_handler.py index 0f0bd932af..8a99700d0f 100644 --- a/astroquery/esa/xmm_newton/tests/dummy_handler.py +++ b/astroquery/esa/xmm_newton/tests/dummy_handler.py @@ -31,30 +31,22 @@ 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)) + raise ValueError(f"Parameter '{key}' not found in method '{method_name}'") return True From b2d1bf6670f20779d2e8d752ee6c4b41bf829fd7 Mon Sep 17 00:00:00 2001 From: lvalerom Date: Fri, 15 Apr 2022 22:56:09 +0200 Subject: [PATCH 2/4] remove 'return' statement --- astroquery/esa/hubble/tests/dummy_tap_handler.py | 1 - astroquery/esa/iso/tests/dummy_handler.py | 1 - astroquery/esa/jwst/tests/DummyTapHandler.py | 1 - astroquery/esa/xmm_newton/tests/dummy_handler.py | 1 - 4 files changed, 4 deletions(-) diff --git a/astroquery/esa/hubble/tests/dummy_tap_handler.py b/astroquery/esa/hubble/tests/dummy_tap_handler.py index 0b33f917ef..3f5c65c6a5 100644 --- a/astroquery/esa/hubble/tests/dummy_tap_handler.py +++ b/astroquery/esa/hubble/tests/dummy_tap_handler.py @@ -49,7 +49,6 @@ def check_parameters(self, parameters, method_name): f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'") else: raise ValueError(f"Parameter '{key}' not found in method '{method_name}'") - return True def launch_job(self, query, name=None, output_file=None, output_format="votable", verbose=False, dump_to_file=False, diff --git a/astroquery/esa/iso/tests/dummy_handler.py b/astroquery/esa/iso/tests/dummy_handler.py index f11739b2d2..a39a49f2f6 100644 --- a/astroquery/esa/iso/tests/dummy_handler.py +++ b/astroquery/esa/iso/tests/dummy_handler.py @@ -48,4 +48,3 @@ def check_parameters(self, parameters, method_name): f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'") else: raise ValueError(f"Parameter '{key}' not found in method '{method_name}'") - return True diff --git a/astroquery/esa/jwst/tests/DummyTapHandler.py b/astroquery/esa/jwst/tests/DummyTapHandler.py index b0f1084220..c5c69cc876 100644 --- a/astroquery/esa/jwst/tests/DummyTapHandler.py +++ b/astroquery/esa/jwst/tests/DummyTapHandler.py @@ -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): diff --git a/astroquery/esa/xmm_newton/tests/dummy_handler.py b/astroquery/esa/xmm_newton/tests/dummy_handler.py index 8a99700d0f..4ad405d535 100644 --- a/astroquery/esa/xmm_newton/tests/dummy_handler.py +++ b/astroquery/esa/xmm_newton/tests/dummy_handler.py @@ -49,4 +49,3 @@ def check_parameters(self, parameters, method_name): f"Found:'{self._parameters[key]}'. Expected:'{parameters[key]}'") else: raise ValueError(f"Parameter '{key}' not found in method '{method_name}'") - return True From f7230b90ee553858a8ec2115f0dd0d9a0b7db4ae Mon Sep 17 00:00:00 2001 From: lvalerom Date: Fri, 15 Apr 2022 23:00:31 +0200 Subject: [PATCH 3/4] remove 'return' statement from hsa 'dummy_handler' --- astroquery/esa/hsa/tests/dummy_handler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astroquery/esa/hsa/tests/dummy_handler.py b/astroquery/esa/hsa/tests/dummy_handler.py index 05bfcc982f..cb2ce83e0f 100644 --- a/astroquery/esa/hsa/tests/dummy_handler.py +++ b/astroquery/esa/hsa/tests/dummy_handler.py @@ -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 From 80883cf0cf7003f16011649d4f43a8e4980a5e7d Mon Sep 17 00:00:00 2001 From: lvalerom Date: Fri, 15 Apr 2022 23:05:03 +0200 Subject: [PATCH 4/4] remove 'return' in 'DummyDataHandler' --- astroquery/esa/jwst/tests/DummyDataHandler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astroquery/esa/jwst/tests/DummyDataHandler.py b/astroquery/esa/jwst/tests/DummyDataHandler.py index 400a643098..81715b43d4 100644 --- a/astroquery/esa/jwst/tests/DummyDataHandler.py +++ b/astroquery/esa/jwst/tests/DummyDataHandler.py @@ -52,7 +52,6 @@ def check_parameters(self, parameters, method_name): else: raise ValueError(f"Parameter '{str(key)}' not found for " f"method '{method_name}'") - return True def download_file(self, url=None): self.__invokedMethod = 'download_file'