From 2147c50c944a7e0cb5a7c5d55f25f2df85de710b Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 27 Jul 2024 16:25:35 -0400 Subject: [PATCH] Reorganize galaxy.tool_util.verify package/types for reuse outside module. Add explicit exports to package galaxy.tool_util.verify. --- lib/galaxy/tool_util/verify/__init__.py | 15 ++++++++++ lib/galaxy/tool_util/verify/_types.py | 36 +++++++++++++++++++++++ lib/galaxy/tool_util/verify/interactor.py | 31 +++---------------- lib/galaxy/tool_util/verify/script.py | 2 +- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/lib/galaxy/tool_util/verify/__init__.py b/lib/galaxy/tool_util/verify/__init__.py index 2bcb31106bfb..4096c4c9d865 100644 --- a/lib/galaxy/tool_util/verify/__init__.py +++ b/lib/galaxy/tool_util/verify/__init__.py @@ -48,6 +48,10 @@ from galaxy.tool_util.parser.yaml import to_test_assert_list from galaxy.util import unicodify from galaxy.util.compression_utils import get_fileobj +from ._types import ( + ExpandedToolInputsJsonified, + ToolTestDescriptionDict, +) from .asserts import verify_assertions from .test_data import TestDataResolver @@ -641,3 +645,14 @@ def verify_file_contents_against_dict( keep_outputs_dir=test_data_target_dir, verify_extra_files=None, ) + + +__all__ = [ + "DEFAULT_TEST_DATA_RESOLVER", + "ExpandedToolInputsJsonified", + "GetFilenameT", + "GetLocationT", + "ToolTestDescriptionDict", + "verify", + "verify_file_contents_against_dict", +] diff --git a/lib/galaxy/tool_util/verify/_types.py b/lib/galaxy/tool_util/verify/_types.py index 26bb7161715d..e5aa85f1ddb7 100644 --- a/lib/galaxy/tool_util/verify/_types.py +++ b/lib/galaxy/tool_util/verify/_types.py @@ -4,9 +4,21 @@ Any, Dict, List, + Optional, Tuple, ) +from typing_extensions import ( + NotRequired, + TypedDict, +) + +from galaxy.tool_util.parser.interface import ( + AssertionList, + TestSourceTestOutputColllection, + ToolSourceTestOutputs, +) + # inputs that have been processed with parse.py and expanded out ExpandedToolInputs = Dict[str, Any] # ExpandedToolInputs where any model objects have been json-ified with to_dict() @@ -16,3 +28,27 @@ RequiredFilesT = List[RequiredFileTuple] RequiredDataTablesT = List[str] RequiredLocFileT = List[str] + + +class ToolTestDescriptionDict(TypedDict): + tool_id: str + tool_version: Optional[str] + name: str + test_index: int + inputs: ExpandedToolInputsJsonified + outputs: ToolSourceTestOutputs + output_collections: List[TestSourceTestOutputColllection] + 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 + exception: Optional[str] + maxseconds: NotRequired[Optional[int]] diff --git a/lib/galaxy/tool_util/verify/interactor.py b/lib/galaxy/tool_util/verify/interactor.py index e403d08fa1aa..e8971a0ec4f5 100644 --- a/lib/galaxy/tool_util/verify/interactor.py +++ b/lib/galaxy/tool_util/verify/interactor.py @@ -55,6 +55,7 @@ RequiredDataTablesT, RequiredFilesT, RequiredLocFileT, + ToolTestDescriptionDict, ) from .asserts import verify_assertions from .wait import wait_on @@ -234,7 +235,7 @@ def get_tests_summary(self): assert response.status_code == 200, f"Non 200 response from tool tests available API. [{response.content}]" return response.json() - def get_tool_tests(self, tool_id: str, tool_version: Optional[str] = None) -> List["ToolTestDescriptionDict"]: + def get_tool_tests(self, tool_id: str, tool_version: Optional[str] = None) -> List[ToolTestDescriptionDict]: url = f"tools/{tool_id}/test_data" params = {"tool_version": tool_version} if tool_version else None response = self._get(url, data=params) @@ -1314,7 +1315,7 @@ def verify_tool( client_test_config: Optional[TestConfig] = None, skip_with_reference_data: bool = False, skip_on_dynamic_param_errors: bool = False, - _tool_test_dicts: Optional[List["ToolTestDescriptionDict"]] = None, # extension point only for tests + _tool_test_dicts: Optional[List[ToolTestDescriptionDict]] = None, # extension point only for tests ): if resource_parameters is None: resource_parameters = {} @@ -1633,30 +1634,6 @@ def __init__(self, output_exceptions, job_stdio): self.output_exceptions = output_exceptions -class ToolTestDescriptionDict(TypedDict): - tool_id: str - tool_version: Optional[str] - name: str - test_index: int - inputs: ExpandedToolInputsJsonified - outputs: ToolSourceTestOutputs - output_collections: List[TestSourceTestOutputColllection] - 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 - exception: Optional[str] - maxseconds: NotRequired[Optional[int]] - - DEFAULT_NUM_OUTPUTS: Optional[int] = None DEFAULT_OUTPUT_COLLECTIONS: List[TestSourceTestOutputColllection] = [] DEFAULT_REQUIRED_FILES: RequiredFilesT = [] @@ -1673,7 +1650,7 @@ class ToolTestDescriptionDict(TypedDict): DEFAULT_EXCEPTION: Optional[str] = None -def adapt_tool_source_dict(processed_dict: ToolTestDict) -> "ToolTestDescriptionDict": +def adapt_tool_source_dict(processed_dict: ToolTestDict) -> ToolTestDescriptionDict: """Convert the dictionaries parsed from tool sources (ToolTestDict) to a ToolTestDescriptionDict. ToolTestDescription is used inside and outside of Galaxy, so convert the dictionaries to the format diff --git a/lib/galaxy/tool_util/verify/script.py b/lib/galaxy/tool_util/verify/script.py index fbb67fc11b37..fca086cf1325 100644 --- a/lib/galaxy/tool_util/verify/script.py +++ b/lib/galaxy/tool_util/verify/script.py @@ -23,10 +23,10 @@ import yaml +from galaxy.tool_util.verify import ToolTestDescriptionDict from galaxy.tool_util.verify.interactor import ( DictClientTestConfig, GalaxyInteractorApi, - ToolTestDescriptionDict, verify_tool, )