Skip to content

Commit

Permalink
Reorganize galaxy.tool_util.verify package/types for reuse outside mo…
Browse files Browse the repository at this point in the history
…dule.

Add explicit exports to package galaxy.tool_util.verify.
  • Loading branch information
jmchilton committed Aug 5, 2024
1 parent 0e7a33f commit 42994be
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
15 changes: 15 additions & 0 deletions lib/galaxy/tool_util/verify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
]
36 changes: 36 additions & 0 deletions lib/galaxy/tool_util/verify/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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]]
31 changes: 4 additions & 27 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
RequiredDataTablesT,
RequiredFilesT,
RequiredLocFileT,
ToolTestDescriptionDict,
)
from .asserts import verify_assertions
from .wait import wait_on
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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 = []
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/verify/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
FetchDataFormPayload,
FetchDataPayload,
)
from galaxy.tool_util.verify.interactor import ToolTestDescriptionDict
from galaxy.tool_util.verify import ToolTestDescriptionDict
from galaxy.tools.evaluation import global_tool_errors
from galaxy.util.zipstream import ZipstreamWrapper
from galaxy.web import (
Expand Down

0 comments on commit 42994be

Please sign in to comment.