Skip to content

Commit

Permalink
Merge pull request #19384 from mvdbeek/fix_maxseconds_parsing
Browse files Browse the repository at this point in the history
[24.2] Fix timeout handling for planemo / galaxy-tool-util
  • Loading branch information
mvdbeek authored Jan 8, 2025
2 parents fe1bf1e + 05ede4a commit e251c07
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
58 changes: 27 additions & 31 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ def adapt_tool_source_dict(processed_dict: ToolTestDict) -> ToolTestDescriptionD

if not error_in_test_definition:
processed_test_dict = cast(ValidToolTestDict, processed_dict)
maxseconds = _get_maxseconds(processed_test_dict)
maxseconds = processed_test_dict.get("maxseconds")
output_collections = processed_test_dict.get("output_collections", [])
if "num_outputs" in processed_test_dict and processed_test_dict["num_outputs"]:
num_outputs = int(processed_test_dict["num_outputs"])
Expand Down Expand Up @@ -1750,10 +1750,6 @@ def _get_test_name(test_dict: Union[ToolTestDict, ToolTestDescriptionDict], test
return name


def _get_maxseconds(test_dict: Union[ToolTestDict, ToolTestDescriptionDict]) -> int:
return int(cast(Union[str, int], test_dict.get("maxseconds") or DEFAULT_TOOL_TEST_WAIT or 86400))


def expanded_inputs_from_json(expanded_inputs_json: ExpandedToolInputsJsonified) -> ExpandedToolInputs:
loaded_inputs: ExpandedToolInputs = {}
for key, value in expanded_inputs_json.items():
Expand Down Expand Up @@ -1829,7 +1825,7 @@ def __init__(self, json_dict: ToolTestDescriptionDict):
self.inputs = expanded_inputs_from_json(json_dict.get("inputs", {}))
self.tool_id = json_dict["tool_id"]
self.tool_version = json_dict.get("tool_version")
self.maxseconds = _get_maxseconds(json_dict)
self.maxseconds = json_dict.get("maxseconds")

def test_data(self):
"""
Expand All @@ -1839,31 +1835,31 @@ def test_data(self):

def to_dict(self) -> ToolTestDescriptionDict:
inputs = expanded_inputs_to_json(self.inputs)
return ToolTestDescriptionDict(
{
"inputs": inputs,
"outputs": self.outputs,
"output_collections": [_.to_dict() for _ in self.output_collections],
"num_outputs": self.num_outputs,
"command_line": self.command_line,
"command_version": self.command_version,
"stdout": self.stdout,
"stderr": self.stderr,
"expect_exit_code": self.expect_exit_code,
"expect_failure": self.expect_failure,
"expect_test_failure": self.expect_test_failure,
"name": self.name,
"test_index": self.test_index,
"tool_id": self.tool_id,
"tool_version": self.tool_version,
"required_files": self.required_files,
"required_data_tables": self.required_data_tables,
"required_loc_files": self.required_loc_files,
"error": self.error,
"exception": self.exception,
"maxseconds": self.maxseconds,
}
)
test_description_def: ToolTestDescriptionDict = {
"inputs": inputs,
"outputs": self.outputs,
"output_collections": [_.to_dict() for _ in self.output_collections],
"num_outputs": self.num_outputs,
"command_line": self.command_line,
"command_version": self.command_version,
"stdout": self.stdout,
"stderr": self.stderr,
"expect_exit_code": self.expect_exit_code,
"expect_failure": self.expect_failure,
"expect_test_failure": self.expect_test_failure,
"name": self.name,
"test_index": self.test_index,
"tool_id": self.tool_id,
"tool_version": self.tool_version,
"required_files": self.required_files,
"required_data_tables": self.required_data_tables,
"required_loc_files": self.required_loc_files,
"error": self.error,
"exception": self.exception,
}
if self.maxseconds is not None:
test_description_def["maxseconds"] = self.maxseconds
return ToolTestDescriptionDict(**test_description_def)


def test_data_iter(required_files):
Expand Down
15 changes: 15 additions & 0 deletions test/unit/tool_util/test_test_definition_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ def _init_tool_for_path(self, path):
tool_source = get_tool_source(path)
self.tool_source = tool_source

def test_maxseconds_not_filled_with_default(self):
self._init_tool_for_path(functional_test_tool_path("simple_constructs.xml"))
test_dicts = list(self._parse_tests())
assert test_dicts[0].maxseconds is None
assert "maxseconds" not in test_dicts[0].to_dict()

def test_maxseconds_parsed(self):
self._init_tool_for_path(functional_test_tool_path("maxseconds.xml"))
test_def = next(iter(self._parse_tests()))
assert test_def.maxseconds == 5
test_dict = test_def.to_dict()
print(test_dict)
assert "maxseconds" in test_dict
assert test_dict["maxseconds"] == 5

def test_simple_state_parsing(self):
self._init_tool_for_path(functional_test_tool_path("simple_constructs.xml"))
test_dicts = self._parse_tests()
Expand Down

0 comments on commit e251c07

Please sign in to comment.