From 1bfed8f5f73eb30ca00979733687fa11c46d3cec Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 30 Jan 2024 21:36:38 -0500 Subject: [PATCH] Some additional typing for test stuff. --- lib/galaxy/tool_util/verify/interactor.py | 64 ++++++++++++++++++----- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/lib/galaxy/tool_util/verify/interactor.py b/lib/galaxy/tool_util/verify/interactor.py index 94cdb25a8efd..16c1229d14b1 100644 --- a/lib/galaxy/tool_util/verify/interactor.py +++ b/lib/galaxy/tool_util/verify/interactor.py @@ -1655,19 +1655,55 @@ def __init__(self, output_exceptions, job_stdio): self.output_exceptions = output_exceptions +class ToolTestDescriptionDict(TypedDict): + name: str + inputs: Any + outputs: Any + output_collections: List[Dict[str, Any]] + stdout: Optional[AssertionList] + stderr: Optional[AssertionList] + expect_exit_code: Optional[int] + expect_failure: bool + expect_test_failure: bool + num_outputs: Optional[int] + command_line: Optional[AssertionList] + command_version: Optional[AssertionList] + required_files: List[Any] + required_data_tables: List[Any] + required_loc_files: List[str] + error: bool + tool_id: str + tool_version: Optional[str] + test_index: int + exception: Optional[str] + + class ToolTestDescription: """ Encapsulates information about a tool test, and allows creation of a dynamic TestCase class (the unittest framework is very class oriented, doing dynamic tests in this way allows better integration) """ + name: str + num_outputs: Optional[int] + stdout: Optional[AssertionList] + stderr: Optional[AssertionList] + command_line: Optional[AssertionList] + command_version: Optional[AssertionList] + required_files: List[Any] + required_data_tables: List[Any] + required_loc_files: List[str] + expect_exit_code: Optional[int] + expect_failure: bool + expect_test_failure: bool + exception: Optional[str] def __init__(self, processed_test_dict: ToolTestDict): assert ( "test_index" in processed_test_dict ), "Invalid processed test description, must have a 'test_index' for naming, etc.." test_index = processed_test_dict["test_index"] - name = processed_test_dict.get("name", f"Test-{test_index + 1}") + name = cast(str, processed_test_dict.get("name", f"Test-{test_index + 1}")) error_in_test_definition = processed_test_dict["error"] if not error_in_test_definition: processed_test_dict = cast(ValidToolTestDict, processed_test_dict) @@ -1686,9 +1722,9 @@ def __init__(self, processed_test_dict: ToolTestDict): self.tool_version = processed_test_dict.get("tool_version") self.name = name self.maxseconds = maxseconds - self.required_files = processed_test_dict.get("required_files", []) - self.required_data_tables = processed_test_dict.get("required_data_tables", []) - self.required_loc_files = processed_test_dict.get("required_loc_files", []) + self.required_files = cast(List[Any], processed_test_dict.get("required_files", [])) + self.required_data_tables = cast(List[Any], processed_test_dict.get("required_data_tables", [])) + self.required_loc_files = cast(List[str], processed_test_dict.get("required_loc_files", [])) inputs = processed_test_dict.get("inputs", {}) loaded_inputs = {} @@ -1700,19 +1736,19 @@ def __init__(self, processed_test_dict: ToolTestDict): self.inputs = loaded_inputs self.outputs = processed_test_dict.get("outputs", []) - self.num_outputs = processed_test_dict.get("num_outputs", None) + self.num_outputs = cast(Optional[int], processed_test_dict.get("num_outputs", None)) self.error = processed_test_dict.get("error", False) - self.exception = processed_test_dict.get("exception", None) + self.exception = cast(Optional[str], processed_test_dict.get("exception", None)) self.output_collections = [TestCollectionOutputDef.from_dict(d) for d in output_collections] - self.command_line = processed_test_dict.get("command_line", None) - self.command_version = processed_test_dict.get("command_version", None) - self.stdout = processed_test_dict.get("stdout", None) - self.stderr = processed_test_dict.get("stderr", None) - self.expect_exit_code = processed_test_dict.get("expect_exit_code", None) - self.expect_failure = processed_test_dict.get("expect_failure", False) - self.expect_test_failure = processed_test_dict.get("expect_test_failure", False) + self.command_line = cast(Optional[AssertionList], processed_test_dict.get("command_line", None)) + self.command_version = cast(Optional[AssertionList], processed_test_dict.get("command_version", None)) + self.stdout = cast(Optional[AssertionList], processed_test_dict.get("stdout", None)) + self.stderr = cast(Optional[AssertionList], processed_test_dict.get("stderr", None)) + self.expect_exit_code = cast(Optional[int], processed_test_dict.get("expect_exit_code", None)) + self.expect_failure = cast(bool, processed_test_dict.get("expect_failure", False)) + self.expect_test_failure = cast(bool, processed_test_dict.get("expect_test_failure", False)) def test_data(self): """ @@ -1720,7 +1756,7 @@ def test_data(self): """ return test_data_iter(self.required_files) - def to_dict(self): + def to_dict(self) -> ToolTestDescriptionDict: inputs_dict = {} for key, value in self.inputs.items(): if hasattr(value, "to_dict"):