From 680b95ae0a0ad671c5ceac82eccdea71d8a7e5fc Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 13 Dec 2022 11:24:16 -0500 Subject: [PATCH] A bit more typing in interactor.py. Again pulled from the tool state branch - trying to bisect these converter test failures. --- lib/galaxy/tool_util/verify/interactor.py | 66 ++++++++++++----------- lib/galaxy_test/api/test_tools.py | 7 ++- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/lib/galaxy/tool_util/verify/interactor.py b/lib/galaxy/tool_util/verify/interactor.py index fc9e43db7b3..0667f0fc85f 100644 --- a/lib/galaxy/tool_util/verify/interactor.py +++ b/lib/galaxy/tool_util/verify/interactor.py @@ -33,6 +33,7 @@ from requests import Response from requests.cookies import RequestsCookieJar from typing_extensions import ( Literal, + NotRequired, Protocol, TypedDict, ) @@ -85,30 +86,29 @@ class OutputsDict(dict): JobDataT = Dict[str, Any] JobDataCallbackT = Callable[[JobDataT], None] -ValidToolTestDict = TypedDict( - "ValidToolTestDict", - { - "inputs": Any, - "outputs": Any, - "output_collections": List[Dict[str, Any]], - "stdout": AssertionList, - "stderr": AssertionList, - "expect_exit_code": Optional[int], - "expect_failure": bool, - "expect_test_failure": bool, - "maxseconds": Optional[int], - "num_outputs": Optional[int], - "command_line": AssertionList, - "command_version": AssertionList, - "required_files": List[Any], - "required_data_tables": List[Any], - "required_loc_files": List[str], - "error": Literal[False], - "tool_id": str, - "tool_version": str, - "test_index": int, - }, -) + + +class ValidToolTestDict(TypedDict): + inputs: Any + outputs: Any + output_collections: List[Dict[str, Any]] + stdout: NotRequired[AssertionList] + stderr: NotRequired[AssertionList] + expect_exit_code: NotRequired[int] + expect_failure: NotRequired[bool] + expect_test_failure: NotRequired[bool] + maxseconds: NotRequired[int] + num_outputs: NotRequired[int] + command_line: NotRequired[AssertionList] + command_version: NotRequired[AssertionList] + required_files: NotRequired[List[Any]] + required_data_tables: NotRequired[List[Any]] + required_loc_files: NotRequired[List[str]] + error: Literal[False] + tool_id: str + tool_version: str + test_index: int + InvalidToolTestDict = TypedDict( "InvalidToolTestDict", @@ -1598,15 +1598,21 @@ class ToolTestDescription: doing dynamic tests in this way allows better integration) """ - def __init__(self, processed_test_dict): + 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}") - maxseconds = processed_test_dict.get("maxseconds", DEFAULT_TOOL_TEST_WAIT) - if maxseconds is not None: - maxseconds = int(maxseconds) + error_in_test_definition = processed_test_dict["error"] + if not error_in_test_definition: + processed_test_dict = cast(ValidToolTestDict, processed_test_dict) + maxseconds = int(processed_test_dict.get("maxseconds") or DEFAULT_TOOL_TEST_WAIT or 86400) + output_collections = processed_test_dict.get("output_collections", []) + else: + processed_test_dict = cast(InvalidToolTestDict, processed_test_dict) + maxseconds = DEFAULT_TOOL_TEST_WAIT + output_collections = [] self.test_index = test_index assert ( @@ -1635,9 +1641,7 @@ class ToolTestDescription: self.error = processed_test_dict.get("error", False) self.exception = processed_test_dict.get("exception", None) - self.output_collections = [ - TestCollectionOutputDef.from_dict(d) for d in processed_test_dict.get("output_collections", []) - ] + 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) diff --git a/lib/galaxy_test/api/test_tools.py b/lib/galaxy_test/api/test_tools.py index 0c0ef834c77..d5776b73f82 100644 --- a/lib/galaxy_test/api/test_tools.py +++ b/lib/galaxy_test/api/test_tools.py @@ -7,6 +7,7 @@ from io import BytesIO from typing import ( Any, Dict, + List, ) import pytest @@ -15,6 +16,7 @@ from requests import ( put, ) +from galaxy.tool_util.verify.interactor import ValidToolTestDict from galaxy.util import galaxy_root_path from galaxy.util.unittest_utils import skip_if_github_down from galaxy_test.base import rules_test_data @@ -1449,16 +1451,17 @@ class TestToolsApi(ApiTestCase, TestsTools): def register_job_data(job_data): job_data_list.append(job_data) - def tool_test_case_list(inputs, required_files): + def tool_test_case_list(inputs, required_files) -> List[ValidToolTestDict]: return [ { "inputs": inputs, "outputs": {}, "required_files": required_files, - "name": "dbkey_output_action-0", + "output_collections": [], "test_index": 0, "tool_version": "0.1.0", "tool_id": "dbkey_output_action", + "error": False, } ]