Skip to content

Commit

Permalink
Some additional typing for test stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jan 31, 2024
1 parent 6f7f8b0 commit 1bfed8f
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {}
Expand All @@ -1700,27 +1736,27 @@ 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):
"""
Iterator over metadata representing the required files for upload.
"""
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"):
Expand Down

0 comments on commit 1bfed8f

Please sign in to comment.