Skip to content

Commit

Permalink
full test coverage for stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Nov 30, 2021
1 parent 4d1f557 commit 3f8554d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/galaxy/tool_util/linters/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 63 additions & 0 deletions test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
help,
inputs,
outputs,
stdio,
tests,
)
from galaxy.tool_util.parser.xml import XmlToolSource
Expand Down Expand Up @@ -365,6 +366,34 @@
</tool>
"""

# tool xml for stdio linter
STDIO_DEFAULT_FOR_DEFAULT_PROFILE = """
<tool>
</tool>
"""

STDIO_DEFAULT_FOR_NONLEGACY_PROFILE = """
<tool profile="21.09">
</tool>
"""

STDIO_MULTIPLE_STDIO = """
<tool profile="21.09">
<stdio/>
<stdio/>
</tool>
"""

STDIO_INVALID_CHILD_OR_ATTRIB = """
<tool profile="21.09">
<stdio>
<reqex/>
<regex descriptio="blah" level="fatal" match="error" source="stdio"/>
<exit_code descriptio="blah" level="fatal" range="1:"/>
</stdio>
</tool>
"""

# check that linter does complain about tests wo assumptions
TESTS_WO_EXPECTATIONS = """
<tool>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 3f8554d

Please sign in to comment.