Skip to content

Commit fdafb06

Browse files
committed
Relax validation of XML test assertion parsing
when tool source is XML. We can't really encode these attributes as JSON in XML, and while we could make it work it doesn't feel great to force tool authors to use such a hypothetical syntax. I think we still keep all the nice validation here, it's just a little more lenient.
1 parent 539441d commit fdafb06

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/galaxy/tool_util/linters/tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
148148
lint_ctx.warn("Failed to parse test dictionaries from tool - cannot lint assertions")
149149
return
150150
assert "tests" in raw_tests_dict
151+
# This really only allows coercion from strings, the values themselves will still be validated
152+
strict_validation = tool_source.language != "xml"
151153
for test_idx, test in enumerate(raw_tests_dict["tests"], start=1):
152154
# TODO: validate command, command_version, element tests. What about children?
153155
for output in test["outputs"]:
@@ -156,7 +158,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
156158
for raw_assert in asserts_raw:
157159
to_yaml_assertions.append({"that": raw_assert["tag"], **raw_assert.get("attributes", {})})
158160
try:
159-
assertion_list.model_validate(to_yaml_assertions)
161+
assertion_list.model_validate(to_yaml_assertions, strict=strict_validation)
160162
except Exception as e:
161163
error_str = _cleanup_pydantic_error(e)
162164
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)