Commit 0eeb71e1 authored by John Chilton's avatar John Chilton
Browse files

Revise assertion relaxation to use better test models.

This was supposed to be part of https://github.com/galaxyproject/galaxy/pull/19715 but clearly I missed the last mile as always.
parent fdafb065
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@ from packaging.version import Version

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.assertion_models import assertion_list, relaxed_assertion_list
from galaxy.tool_util.verify.parse import tag_structure_to_that_structure
from galaxy.util import asbool
from ._util import is_datasource

@@ -149,16 +150,16 @@ class TestsAssertionValidation(Linter):
            return
        assert "tests" in raw_tests_dict
        # This really only allows coercion from strings, the values themselves will still be validated
        strict_validation = tool_source.language != "xml"
        assert_list_model = relaxed_assertion_list if tool_source.language == "xml" else assertion_list
        for test_idx, test in enumerate(raw_tests_dict["tests"], start=1):
            # 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 = []
                processed_assertions = []
                for raw_assert in asserts_raw:
                    to_yaml_assertions.append({"that": raw_assert["tag"], **raw_assert.get("attributes", {})})
                    processed_assertions.append(tag_structure_to_that_structure(raw_assert))
                try:
                    assertion_list.model_validate(to_yaml_assertions, strict=strict_validation)
                    assert_list_model.model_validate(processed_assertions)
                except Exception as e:
                    error_str = _cleanup_pydantic_error(e)
                    lint_ctx.warn(