comparison planemo/lib/python3.7/site-packages/galaxy/tool_util/linters/tests.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 """This module contains a linting functions for tool tests."""
2 from ._util import is_datasource
3
4
5 # Misspelled so as not be picked up by nosetests.
6 def lint_tsts(tool_xml, lint_ctx):
7 tests = tool_xml.findall("./tests/test")
8 datasource = is_datasource(tool_xml)
9
10 if not tests and not datasource:
11 lint_ctx.warn("No tests found, most tools should define test cases.")
12 elif datasource:
13 lint_ctx.info("No tests found, that should be OK for data_sources.")
14
15 num_valid_tests = 0
16 for test in tests:
17 has_test = False
18 if "expect_failure" in test.attrib or "expect_exit_code" in test.attrib:
19 has_test = True
20 if len(test.findall("assert_stdout")) > 0:
21 has_test = True
22 if len(test.findall("assert_stderr")) > 0:
23 has_test = True
24 if len(test.findall("assert_command")) > 0:
25 has_test = True
26
27 output_data_names, output_collection_names = _collect_output_names(tool_xml)
28 found_output_test = False
29 for output in test.findall("output"):
30 found_output_test = True
31 name = output.attrib.get("name", None)
32 if not name:
33 lint_ctx.warn("Found output tag without a name defined.")
34 else:
35 if name not in output_data_names:
36 lint_ctx.error("Found output tag with unknown name [%s], valid names [%s]" % (name, output_data_names))
37
38 for output_collection in test.findall("output_collection"):
39 found_output_test = True
40 name = output_collection.attrib.get("name", None)
41 if not name:
42 lint_ctx.warn("Found output_collection tag without a name defined.")
43 else:
44 if name not in output_collection_names:
45 lint_ctx.warn("Found output_collection tag with unknown name [%s], valid names [%s]" % (name, output_collection_names))
46
47 has_test = has_test or found_output_test
48 if not has_test:
49 lint_ctx.warn("No outputs or expectations defined for tests, this test is likely invalid.")
50 else:
51 num_valid_tests += 1
52
53 if num_valid_tests or datasource:
54 lint_ctx.valid("%d test(s) found.", num_valid_tests)
55 else:
56 lint_ctx.warn("No valid test(s) found.")
57
58
59 def _collect_output_names(tool_xml):
60 output_data_names = []
61 output_collection_names = []
62
63 outputs = tool_xml.findall("./outputs")
64 if len(outputs) == 1:
65 for output in list(outputs[0]):
66 name = output.attrib.get("name", None)
67 if not name:
68 continue
69 if output.tag == "data":
70 output_data_names.append(name)
71 elif output.tag == "collection":
72 output_collection_names.append(name)
73
74 return output_data_names, output_collection_names