Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/galaxy/tool_util/verify/script.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 #!/usr/bin/env python | |
| 2 from __future__ import print_function | |
| 3 | |
| 4 import argparse | |
| 5 import json | |
| 6 import sys | |
| 7 | |
| 8 from .interactor import ( | |
| 9 GalaxyInteractorApi, | |
| 10 verify_tool, | |
| 11 ) | |
| 12 | |
| 13 DESCRIPTION = """Script to quickly run a tool test against a running Galaxy instance.""" | |
| 14 ALL_TESTS = "*all_tests*" | |
| 15 | |
| 16 | |
| 17 def main(argv=None): | |
| 18 if argv is None: | |
| 19 argv = sys.argv[1:] | |
| 20 | |
| 21 args = _arg_parser().parse_args(argv) | |
| 22 galaxy_interactor_kwds = { | |
| 23 "galaxy_url": args.galaxy_url, | |
| 24 "master_api_key": args.admin_key, | |
| 25 "api_key": args.key, | |
| 26 "keep_outputs_dir": args.output, | |
| 27 } | |
| 28 tool_id = args.tool_id | |
| 29 tool_version = args.tool_version | |
| 30 | |
| 31 galaxy_interactor = GalaxyInteractorApi(**galaxy_interactor_kwds) | |
| 32 raw_test_index = args.test_index | |
| 33 if raw_test_index == ALL_TESTS: | |
| 34 tool_test_dicts = galaxy_interactor.get_tool_tests(tool_id, tool_version=tool_version) | |
| 35 test_indices = list(range(len(tool_test_dicts))) | |
| 36 else: | |
| 37 test_indices = [int(raw_test_index)] | |
| 38 | |
| 39 test_results = [] | |
| 40 | |
| 41 if args.append: | |
| 42 with open(args.output_json, "r") as f: | |
| 43 previous_results = json.load(f) | |
| 44 test_results = previous_results["tests"] | |
| 45 | |
| 46 exceptions = [] | |
| 47 verbose = args.verbose | |
| 48 for test_index in test_indices: | |
| 49 if tool_version: | |
| 50 tool_id_and_version = "%s/%s" % (tool_id, tool_version) | |
| 51 else: | |
| 52 tool_id_and_version = tool_id | |
| 53 | |
| 54 test_identifier = "tool %s test # %d" % (tool_id_and_version, test_index) | |
| 55 | |
| 56 def register(job_data): | |
| 57 test_results.append({ | |
| 58 'id': tool_id + "-" + str(test_index), | |
| 59 'has_data': True, | |
| 60 'data': job_data, | |
| 61 }) | |
| 62 | |
| 63 try: | |
| 64 verify_tool( | |
| 65 tool_id, galaxy_interactor, test_index=test_index, tool_version=tool_version, | |
| 66 register_job_data=register, quiet=not verbose, force_path_paste=args.force_path_paste | |
| 67 ) | |
| 68 | |
| 69 if verbose: | |
| 70 print("%s passed" % test_identifier) | |
| 71 | |
| 72 except Exception as e: | |
| 73 if verbose: | |
| 74 print("%s failed, %s" % (test_identifier, e)) | |
| 75 exceptions.append(e) | |
| 76 | |
| 77 report_obj = { | |
| 78 'version': '0.1', | |
| 79 'tests': test_results, | |
| 80 } | |
| 81 output_json = args.output_json | |
| 82 if output_json: | |
| 83 if args.output_json == "-": | |
| 84 assert not args.append | |
| 85 print(json.dumps(report_obj)) | |
| 86 else: | |
| 87 with open(args.output_json, "w") as f: | |
| 88 json.dump(report_obj, f) | |
| 89 | |
| 90 if exceptions: | |
| 91 raise exceptions[0] | |
| 92 | |
| 93 | |
| 94 def _arg_parser(): | |
| 95 parser = argparse.ArgumentParser(description=DESCRIPTION) | |
| 96 parser.add_argument('-u', '--galaxy-url', default="http://localhost:8080", help='Galaxy URL') | |
| 97 parser.add_argument('-k', '--key', default=None, help='Galaxy User API Key') | |
| 98 parser.add_argument('-a', '--admin-key', default=None, help='Galaxy Admin API Key') | |
| 99 parser.add_argument('--force_path_paste', default=False, action="store_true", help='This requires Galaxy-side config option "allow_path_paste" enabled. Allows for fetching test data locally. Only for admins.') | |
| 100 parser.add_argument('-t', '--tool-id', default=None, help='Tool ID') | |
| 101 parser.add_argument('--tool-version', default=None, help='Tool Version') | |
| 102 parser.add_argument('-i', '--test-index', default=ALL_TESTS, help='Tool Test Index (starting at 0) - by default all tests will run.') | |
| 103 parser.add_argument('-o', '--output', default=None, help='directory to dump outputs to') | |
| 104 parser.add_argument('--append', default=False, action="store_true", help="Extend a test record json (created with --output-json) with additional tests.") | |
| 105 parser.add_argument('-j', '--output-json', default=None, help='output metadata json') | |
| 106 parser.add_argument('--verbose', default=False, action="store_true", help="Verbose logging.") | |
| 107 return parser | |
| 108 | |
| 109 | |
| 110 if __name__ == "__main__": | |
| 111 main() |
