Skip to content

Commit

Permalink
Fix correctness of assertion validation in new linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Nov 25, 2024
1 parent 78aa6f9 commit 2c66985
Show file tree
Hide file tree
Showing 6 changed files with 1,545 additions and 14 deletions.
7 changes: 3 additions & 4 deletions lib/galaxy/tool_util/linters/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from galaxy.tool_util.lint import Linter
from galaxy.tool_util.parameters import validate_test_cases_for_tool_source
from galaxy.tool_util.verify.assertion_models import assertion_list
from galaxy.tool_util.verify.asserts import parse_xml_assertions
from galaxy.util import asbool
from ._util import is_datasource

Expand Down Expand Up @@ -150,11 +151,9 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
# TODO: validate command, command_version, element tests. What about children?
for output in test["outputs"]:
asserts_raw = output.get("attributes", {}).get("assert_list") or []
to_yaml_assertions = []
for raw_assert in asserts_raw:
to_yaml_assertions.append({"that": raw_assert["tag"], **raw_assert.get("attributes", {})})
as_python_dicts = parse_xml_assertions(asserts_raw)
try:
assertion_list.model_validate(to_yaml_assertions)
assertion_list.model_validate(as_python_dicts)
except Exception as e:
error_str = _cleanup_pydantic_error(e)
lint_ctx.warn(
Expand Down
14 changes: 7 additions & 7 deletions lib/galaxy/tool_util/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,10 @@ def _test_elem_to_dict(test_elem, i, profile=None) -> ToolSourceTest:
output_collections=__parse_output_collection_elems(test_elem, profile=profile),
inputs=__parse_input_elems(test_elem, i),
expect_num_outputs=test_elem.get("expect_num_outputs"),
command=__parse_assert_list_from_elem(test_elem.find("assert_command")),
command_version=__parse_assert_list_from_elem(test_elem.find("assert_command_version")),
stdout=__parse_assert_list_from_elem(test_elem.find("assert_stdout")),
stderr=__parse_assert_list_from_elem(test_elem.find("assert_stderr")),
command=parse_assert_list_from_elem(test_elem.find("assert_command")),
command_version=parse_assert_list_from_elem(test_elem.find("assert_command_version")),
stdout=parse_assert_list_from_elem(test_elem.find("assert_stdout")),
stderr=parse_assert_list_from_elem(test_elem.find("assert_stderr")),
expect_exit_code=test_elem.get("expect_exit_code"),
expect_failure=string_as_bool(test_elem.get("expect_failure", False)),
expect_test_failure=string_as_bool(test_elem.get("expect_test_failure", False)),
Expand Down Expand Up @@ -783,7 +783,7 @@ def __parse_output_elem(output_elem):

def __parse_command_elem(test_elem):
assert_elem = test_elem.find("command")
return __parse_assert_list_from_elem(assert_elem)
return parse_assert_list_from_elem(assert_elem)


def __parse_output_collection_elems(test_elem, profile=None):
Expand Down Expand Up @@ -918,10 +918,10 @@ def __parse_test_attributes(

def __parse_assert_list(output_elem) -> AssertionList:
assert_elem = output_elem.find("assert_contents")
return __parse_assert_list_from_elem(assert_elem)
return parse_assert_list_from_elem(assert_elem)


def __parse_assert_list_from_elem(assert_elem) -> AssertionList:
def parse_assert_list_from_elem(assert_elem) -> AssertionList:
assert_list = None

def convert_elem(elem):
Expand Down
Loading

0 comments on commit 2c66985

Please sign in to comment.