Skip to content

Commit 044442b

Browse files
authored
Merge pull request #20511 from mvdbeek/fix_too_strict_validation
[24.2] Relax validation of XML test assertion parsing
2 parents dcd4cdc + 9523afb commit 044442b

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/galaxy/tool_util/linters/tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
from galaxy.tool_util.lint import Linter
1414
from galaxy.tool_util.parameters import validate_test_cases_for_tool_source
15-
from galaxy.tool_util.verify.assertion_models import assertion_list
15+
from galaxy.tool_util.verify.assertion_models import (
16+
assertion_list,
17+
relaxed_assertion_list,
18+
)
19+
from galaxy.tool_util.verify.parse import tag_structure_to_that_structure
1620
from galaxy.util import asbool
1721
from ._util import is_datasource
1822

@@ -148,15 +152,17 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
148152
lint_ctx.warn("Failed to parse test dictionaries from tool - cannot lint assertions")
149153
return
150154
assert "tests" in raw_tests_dict
155+
# This really only allows coercion from strings, the values themselves will still be validated
156+
assert_list_model = relaxed_assertion_list if tool_source.language == "xml" else assertion_list
151157
for test_idx, test in enumerate(raw_tests_dict["tests"], start=1):
152158
# TODO: validate command, command_version, element tests. What about children?
153159
for output in test["outputs"]:
154160
asserts_raw = output.get("attributes", {}).get("assert_list") or []
155-
to_yaml_assertions = []
161+
processed_assertions = []
156162
for raw_assert in asserts_raw:
157-
to_yaml_assertions.append({"that": raw_assert["tag"], **raw_assert.get("attributes", {})})
163+
processed_assertions.append(tag_structure_to_that_structure(raw_assert))
158164
try:
159-
assertion_list.model_validate(to_yaml_assertions)
165+
assert_list_model.model_validate(processed_assertions)
160166
except Exception as e:
161167
error_str = _cleanup_pydantic_error(e)
162168
lint_ctx.warn(

test/unit/tool_util/test_tool_linters.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,23 @@
850850
</tests>
851851
</tool>
852852
"""
853+
ASSERTS_STRING_COERCION = """
854+
<tool id="id" name="name">
855+
<outputs>
856+
<data name="data_name" format="ome.tiff"/>
857+
</outputs>
858+
<tests>
859+
<test>
860+
<output name="data_name">
861+
<assert_contents>
862+
<!-- channels is defined as an integer, so coercion from string must be applied on validation -->
863+
<has_image_channels channels="3" />
864+
</assert_contents>
865+
</output>
866+
</test>
867+
</tests>
868+
</tool>
869+
"""
853870
TESTS_VALID = """
854871
<tool id="id" name="name">
855872
<outputs>
@@ -1945,6 +1962,12 @@ def test_tests_asserts(lint_ctx):
19451962
assert len(lint_ctx.error_messages) == 9
19461963

19471964

1965+
def test_tests_asserts_string_coercion(lint_ctx):
1966+
tool_source = get_xml_tool_source(ASSERTS_STRING_COERCION)
1967+
run_lint_module(lint_ctx, tests, tool_source)
1968+
assert len(lint_ctx.warn_messages) == 0, lint_ctx.warn_messages
1969+
1970+
19481971
def test_tests_assertion_models_valid(lint_ctx):
19491972
tool_source = get_xml_tool_source(VALID_CENTER_OF_MASS)
19501973
run_lint_module(lint_ctx, tests, tool_source)

0 commit comments

Comments
 (0)