Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/commands/cmd_test.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 """Module describing the planemo ``test`` command.""" | |
| 2 import click | |
| 3 | |
| 4 from planemo import options | |
| 5 from planemo.cli import command_function | |
| 6 from planemo.engine import ( | |
| 7 engine_context, | |
| 8 ) | |
| 9 from planemo.galaxy import galaxy_config | |
| 10 from planemo.galaxy.config import _find_test_data | |
| 11 from planemo.galaxy.test import ( | |
| 12 handle_reports_and_summary, | |
| 13 run_in_config, | |
| 14 ) | |
| 15 from planemo.io import temp_directory | |
| 16 from planemo.runnable import ( | |
| 17 for_paths, | |
| 18 RunnableType, | |
| 19 ) | |
| 20 | |
| 21 | |
| 22 @click.command('test') | |
| 23 @options.optional_tools_arg(multiple=True) | |
| 24 @click.option( | |
| 25 "--failed", | |
| 26 is_flag=True, | |
| 27 help="Re-run only failed tests. This command will read " | |
| 28 "tool_test_output.json to determine which tests failed so this " | |
| 29 "file must have been produced with the same set of tool ids " | |
| 30 "previously.", | |
| 31 default=False, | |
| 32 ) | |
| 33 @click.option( | |
| 34 "--polling_backoff", | |
| 35 type=int, | |
| 36 help="Poll resources with an increasing interval between requests. " | |
| 37 "Useful when testing against remote and/or production " | |
| 38 "instances to limit generated traffic.", | |
| 39 default="0", | |
| 40 ) | |
| 41 @click.option( | |
| 42 "--history_name", | |
| 43 help="Name for history (if a history is generated as part of testing.)" | |
| 44 ) | |
| 45 @options.galaxy_target_options() | |
| 46 @options.galaxy_config_options() | |
| 47 @options.test_options() | |
| 48 @options.engine_options() | |
| 49 @command_function | |
| 50 def cli(ctx, paths, **kwds): | |
| 51 """Run specified tool's tests within Galaxy. | |
| 52 | |
| 53 All referenced tools (by default all the tools in the current working | |
| 54 directory) will be tested and the results quickly summarized. | |
| 55 | |
| 56 To run these tests planemo needs a Galaxy instance to utilize, planemo | |
| 57 will search parent directories to see if any is a Galaxy instance | |
| 58 - but one can pick the Galaxy instance to use with the --galaxy_root | |
| 59 option or force planemo to download a disposable instance with the | |
| 60 ``--install_galaxy`` flag. | |
| 61 | |
| 62 In additon to to quick summary printed to the console - various detailed | |
| 63 output summaries can be configured. ``tool_test_output.html`` (settable | |
| 64 via ``--test_output``) will contain a human consumable HTML report | |
| 65 describing the test run. A JSON file (settable via ``--test_output_json`` | |
| 66 and defaulting to ``tool_test_output.json``) will also be created. These | |
| 67 files can can be disabled by passing in empty arguments or globally by | |
| 68 setting the values ``default_test_output`` and/or | |
| 69 ``default_test_output_json`` in ``~/.planemo.yml`` to ``null``. For | |
| 70 continuous integration testing a xUnit-style report can be confiured using | |
| 71 the ``--test_output_xunit``. | |
| 72 | |
| 73 planemo uses temporarily generated config files and environment variables | |
| 74 to attempt to shield this execution of Galaxy from manually launched runs | |
| 75 against that same Galaxy root - but this may not be bullet proof yet so | |
| 76 please careful and do not try this against production Galaxy instances. | |
| 77 """ | |
| 78 with temp_directory(dir=ctx.planemo_directory) as temp_path: | |
| 79 # Create temp dir(s) outside of temp, docker can't mount $TEMPDIR on OSX | |
| 80 runnables = for_paths(paths, temp_path=temp_path) | |
| 81 is_cwl = all(r.type in {RunnableType.cwl_tool, RunnableType.cwl_workflow} for r in runnables) | |
| 82 if kwds.get("engine") is None: | |
| 83 kwds["engine"] = "galaxy" if not is_cwl else "cwltool" | |
| 84 | |
| 85 engine_type = kwds["engine"] | |
| 86 test_engine_testable = {RunnableType.galaxy_tool, RunnableType.galaxy_datamanager, RunnableType.directory} | |
| 87 enable_test_engines = any(r.type not in test_engine_testable for r in runnables) | |
| 88 enable_test_engines = enable_test_engines or engine_type != "galaxy" | |
| 89 if enable_test_engines: | |
| 90 ctx.vlog("Using test engine type %s" % engine_type) | |
| 91 with engine_context(ctx, **kwds) as engine: | |
| 92 test_data = engine.test(runnables) | |
| 93 return_value = handle_reports_and_summary(ctx, test_data.structured_data, kwds=kwds) | |
| 94 else: | |
| 95 ctx.vlog("Running traditional Galaxy tool tests using run_tests.sh in Galaxy root %s" % engine_type) | |
| 96 kwds["for_tests"] = True | |
| 97 if kwds.get('update_test_data'): | |
| 98 non_copied_runnables = for_paths(paths) | |
| 99 kwds['test_data_target_dir'] = _find_test_data(non_copied_runnables, **kwds) | |
| 100 with galaxy_config(ctx, runnables, **kwds) as config: | |
| 101 return_value = run_in_config(ctx, config, **kwds) | |
| 102 | |
| 103 ctx.exit(return_value) |
