From 3f8554d26b2addce4bcefe3fdd0f59312c139cce Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 30 Nov 2021 11:19:08 +0100 Subject: [PATCH] full test coverage for stdio --- lib/galaxy/tool_util/linters/stdio.py | 4 ++ test/unit/tool_util/test_tool_linters.py | 63 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/galaxy/tool_util/linters/stdio.py b/lib/galaxy/tool_util/linters/stdio.py index f22d544e9a07..0c40fbc04318 100644 --- a/lib/galaxy/tool_util/linters/stdio.py +++ b/lib/galaxy/tool_util/linters/stdio.py @@ -42,9 +42,13 @@ def _lint_exit_code(tool_xml, child, lint_ctx): for key in child.attrib.keys(): if key not in ["description", "level", "range"]: lint_ctx.warn(f"Unknown attribute [{key}] encountered on exit_code tag.", line=child.sourceline, xpath=tool_xml.getpath(child)) + # TODO lint range, or is regexp in xsd sufficient? + # TODO lint required attributes def _lint_regex(tool_xml, child, lint_ctx): for key in child.attrib.keys(): if key not in ["description", "level", "match", "source"]: lint_ctx.warn(f"Unknown attribute [{key}] encountered on regex tag.", line=child.sourceline, xpath=tool_xml.getpath(child)) + # TODO lint match (re.compile) + # TODO lint required attributes diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index 065e890070f6..70c05fdd5f4b 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -8,6 +8,7 @@ help, inputs, outputs, + stdio, tests, ) from galaxy.tool_util.parser.xml import XmlToolSource @@ -365,6 +366,34 @@ """ +# tool xml for stdio linter +STDIO_DEFAULT_FOR_DEFAULT_PROFILE = """ + + +""" + +STDIO_DEFAULT_FOR_NONLEGACY_PROFILE = """ + + +""" + +STDIO_MULTIPLE_STDIO = """ + + + + +""" + +STDIO_INVALID_CHILD_OR_ATTRIB = """ + + + + + + + +""" + # check that linter does complain about tests wo assumptions TESTS_WO_EXPECTATIONS = """ @@ -632,6 +661,36 @@ lambda x: len(x.warn_messages) == 0 and len(x.error_messages) == 0 ), + ( + STDIO_DEFAULT_FOR_DEFAULT_PROFILE, stdio.lint_stdio, + lambda x: + "No stdio definition found, tool indicates error conditions with output written to stderr." in x.info_messages + and len(x.info_messages) == 1 and len(x.warn_messages) == 0 and len(x.error_messages) == 0 + + ), + ( + STDIO_DEFAULT_FOR_NONLEGACY_PROFILE, stdio.lint_stdio, + lambda x: + "No stdio definition found, tool indicates error conditions with non-zero exit codes." in x.info_messages + and len(x.info_messages) == 1 and len(x.warn_messages) == 0 and len(x.error_messages) == 0 + + ), + ( + STDIO_MULTIPLE_STDIO, stdio.lint_stdio, + lambda x: + "More than one stdio tag found, behavior undefined." in x.error_messages + and len(x.info_messages) == 0 and len(x.warn_messages) == 0 and len(x.error_messages) == 1 + + ), + ( + STDIO_INVALID_CHILD_OR_ATTRIB, stdio.lint_stdio, + lambda x: + "Unknown stdio child tag discovered [reqex]. Valid options are exit_code and regex." in x.warn_messages + and "Unknown attribute [descriptio] encountered on exit_code tag." in x.warn_messages + and "Unknown attribute [descriptio] encountered on regex tag." in x.warn_messages + and len(x.info_messages) == 0 and len(x.warn_messages) == 3 and len(x.error_messages) == 0 + + ), ( TESTS_WO_EXPECTATIONS, tests.lint_tsts, lambda x: @@ -682,6 +741,10 @@ 'repeats', 'outputs collection static elements with format_source', 'outputs discover datatsets with tool provided metadata', + 'stdio: default for default profile', + 'stdio: default for non-legacy profile', + 'stdio: multiple stdio', + 'stdio: invalid tag or attribute', 'test without expectations', 'test param missing from inputs', 'test expecting failure with outputs',