comparison env/lib/python3.9/site-packages/galaxy/tool_util/linters/tests.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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 test_expect = ("expect_failure", "expect_exit_code", "expect_num_outputs")
19 for te in test_expect:
20 if te in test.attrib:
21 has_test = True
22 break
23 test_assert = ("assert_stdout", "assert_stderr", "assert_command")
24 for ta in test_assert:
25 if len(test.findall(ta)) > 0:
26 has_test = True
27 break
28
29 output_data_names, output_collection_names = _collect_output_names(tool_xml)
30 found_output_test = False
31 for output in test.findall("output"):
32 found_output_test = True
33 name = output.attrib.get("name", None)
34 if not name:
35 lint_ctx.warn("Found output tag without a name defined.")
36 else:
37 if name not in output_data_names:
38 lint_ctx.error(f"Found output tag with unknown name [{name}], valid names [{output_data_names}]")
39
40 for output_collection in test.findall("output_collection"):
41 found_output_test = True
42 name = output_collection.attrib.get("name", None)
43 if not name:
44 lint_ctx.warn("Found output_collection tag without a name defined.")
45 else:
46 if name not in output_collection_names:
47 lint_ctx.warn(f"Found output_collection tag with unknown name [{name}], valid names [{output_collection_names}]")
48
49 has_test = has_test or found_output_test
50 if not has_test:
51 lint_ctx.warn("No outputs or expectations defined for tests, this test is likely invalid.")
52 else:
53 num_valid_tests += 1
54
55 if num_valid_tests or datasource:
56 lint_ctx.valid("%d test(s) found.", num_valid_tests)
57 else:
58 lint_ctx.warn("No valid test(s) found.")
59
60
61 def _collect_output_names(tool_xml):
62 output_data_names = []
63 output_collection_names = []
64
65 outputs = tool_xml.findall("./outputs")
66 if len(outputs) == 1:
67 for output in list(outputs[0]):
68 name = output.attrib.get("name", None)
69 if not name:
70 continue
71 if output.tag == "data":
72 output_data_names.append(name)
73 elif output.tag == "collection":
74 output_collection_names.append(name)
75
76 return output_data_names, output_collection_names