def cli(ctx, path): """Create files to use GitHub/TravisCI testing. Setup files in a github tool repository to enable continuous integration testing.:: % planemo travis_init . % # setup Ubuntu 12.04 w/ dependencies in % vim .travis/setup_custom_dependencies.bash % git add .travis.yml .travis % git commit -m "Add Travis CI testing infrastructure for tools." % git push # and register repository @ http://travis-ci.org/ These tests were inspired by work original done and documented by Peter C**k here http://bit.ly/gxtravisci. """ # TODO: Option --verbose_travis_yaml to unroll travis_test.sh line by line # and place all but last in 'install' section and last in 'script'. Would # require a yaml dependency though. shell("mkdir -p '%s/.travis'" % path) travis_yml = os.path.join(path, ".travis.yml") setup_sh = os.path.join(path, ".travis", "setup_custom_dependencies.bash") if not os.path.exists(travis_yml): open(travis_yml, "w").write(TRAVIS_YML) else: warn(".travis.yml file already exists, not overwriting.") if not os.path.exists(setup_sh): open(setup_sh, "w").write(TRAVIS_SETUP) else: warn( ".travis/setup_custom_dependencies.bash already exists, not overwriting." ) info(PREPARE_MESSAGE)
def cli(ctx, path): """Create files to use GitHub/TravisCI testing. Setup files in a github tool repository to enable continuous integration testing.:: % planemo travis_init . % # setup Ubuntu 12.04 w/ dependencies in % vim .travis/setup_custom_dependencies.bash % git add .travis.yml .travis % git commit -m "Add Travis CI testing infrastructure for tools." % git push # and register repository @ http://travis-ci.org/ These tests were inspired by work original done and documented by Peter C**k here http://bit.ly/gxtravisci. """ # TODO: Option --verbose_travis_yaml to unroll travis_test.sh line by line # and place all but last in 'install' section and last in 'script'. Would # require a yaml dependency though. shell("mkdir -p '%s/.travis'" % path) travis_yml = os.path.join(path, ".travis.yml") setup_sh = os.path.join(path, ".travis", "setup_custom_dependencies.bash") if not os.path.exists(travis_yml): open(travis_yml, "w").write(TRAVIS_YML) else: warn(".travis.yml file already exists, not overwriting.") if not os.path.exists(setup_sh): open(setup_sh, "w").write(TRAVIS_SETUP) else: warn(".travis/setup_custom_dependencies.bash already exists, not overwriting.") info(PREPARE_MESSAGE)
def run_in_config(ctx, config, **kwds): config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() cmd = "; ".join([ cd_to_galaxy_command, galaxy_run.ACTIVATE_COMMAND, # TODO: this should be moved to # run_tests.sh to match run.sh. test_cmd, ]) action = "Testing tools" return_code = galaxy_run.run_galaxy_command(ctx, cmd, config.env, action) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) try: test_data = test_results.structured_data new_report = build_report.build_report(test_data) open(test_results.output_html_path, "w").write(new_report) except Exception: pass __handle_summary(test_results, **kwds) return return_code
def shell(cmds, **kwds): if isinstance(cmds, list): cmd_string = commands.argv_to_str(cmds) else: cmd_string = cmds info(cmd_string) return commands.shell(cmds, **kwds)
def run_galaxy_command(ctx, command, env, action, daemon=False): message = "%s with command [%s]" % (action, command) info(message) ctx.vlog("With environment variables:") ctx.vlog("============================") for key, value in env.items(): ctx.vlog('%s="%s"' % (key, value)) ctx.vlog("============================") return shell(command, env=env)
def run_galaxy_command(ctx, command, env, action): """Run Galaxy command with informative verbose logging.""" message = "%s with command [%s]" % (action, command) info(message) ctx.vlog("With environment variables:") ctx.vlog("============================") for key, value in env.items(): ctx.vlog('%s="%s"' % (key, value)) ctx.vlog("============================") exit_code = shell(command, env=env) ctx.vlog("run command exited with return code %s" % exit_code) return exit_code
def __xunit_state(kwds, config): xunit_supported = True if shell("grep -q xunit '%s'/run_tests.sh" % config.galaxy_root): xunit_supported = False xunit_report_file = kwds.get("test_output_xunit", None) if xunit_report_file is None and xunit_supported: xunit_report_file = os.path.join(config.config_directory, "xunit.xml") elif xunit_report_file is not None and not xunit_supported: warn(XUNIT_UPGRADE_MESSAGE) xunit_report_file = None return xunit_supported, xunit_report_file
def __structured_report_file(kwds, config): structured_data_supported = True if shell("grep -q structured_data '%s'/run_tests.sh" % config.galaxy_root): structured_data_supported = False structured_report_file = None structured_report_file = kwds.get("test_output_json", None) if structured_report_file is None and structured_data_supported: conf_dir = config.config_directory structured_report_file = os.path.join(conf_dir, "structured_data.json") elif structured_report_file is not None and not structured_data_supported: warn(NO_JSON_MESSAGE) structured_report_file = None return structured_report_file
def shell(cmds, **kwds): info(cmds) return commands.shell(cmds, **kwds)
def run_in_config(ctx, config, **kwds): config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() setup_common_startup_args = "" if kwds.get("skip_venv", False): setup_common_startup_args = ( 'COMMON_STARTUP_ARGS=--skip-venv; ' 'export COMMON_STARTUP_ARGS; ' 'echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"' ) setup_venv_command = setup_venv(ctx, kwds) cmd = shell_join( cd_to_galaxy_command, setup_common_startup_args, setup_venv_command, test_cmd, ) action = "Testing tools" return_code = run_galaxy_command( ctx, cmd, config.env, action ) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) test_data = test_results.structured_data handle_reports(ctx, test_data, kwds) __handle_summary( test_results, **kwds ) return return_code
def run_in_config(ctx, config, **kwds): config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() setup_common_startup_args = "" if kwds.get("skip_venv", False): setup_common_startup_args = ( 'COMMON_STARTUP_ARGS=--skip-venv; ' 'export COMMON_STARTUP_ARGS; ' 'echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"') setup_venv_command = setup_venv(ctx, kwds) cmd = shell_join( cd_to_galaxy_command, setup_common_startup_args, setup_venv_command, test_cmd, ) action = "Testing tools" return_code = run_galaxy_command(ctx, cmd, config.env, action) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) test_data = test_results.structured_data handle_reports(ctx, test_data, kwds) __handle_summary(test_results, **kwds) return return_code
def shell(cmds, **kwds): cmd_string = args_to_str(cmds) info(cmd_string) return commands.shell(cmds, **kwds)
def run_in_config(ctx, config, run=run_galaxy_command, **kwds): """Run Galaxy tests with the run_tests.sh command. The specified `config` object describes the context for tool execution. """ config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_report_file = _xunit_state(kwds, config) xunit_report_file_tracker = _FileChangeTracker(xunit_report_file) structured_report_file = _structured_report_file(kwds, config) structured_report_file_tracker = _FileChangeTracker(structured_report_file) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() setup_common_startup_args = "" if kwds.get("skip_venv", False): setup_common_startup_args = ( 'COMMON_STARTUP_ARGS=--skip-venv; ' 'export COMMON_STARTUP_ARGS; ' 'echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"' ) setup_venv_command = setup_venv(ctx, kwds) cmd = shell_join( cd_to_galaxy_command, setup_common_startup_args, setup_venv_command, test_cmd, ) action = "Testing tools" return_code = run( ctx, cmd, config.env, action ) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) _check_test_outputs(xunit_report_file_tracker, structured_report_file_tracker) test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) structured_data = test_results.structured_data return handle_reports_and_summary( ctx, structured_data, exit_code=test_results.exit_code, kwds=kwds )
def run_in_config(ctx, config, **kwds): config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() cmd = "; ".join([ cd_to_galaxy_command, galaxy_run.ACTIVATE_COMMAND, # TODO: this should be moved to # run_tests.sh to match run.sh. test_cmd, ]) action = "Testing tools" return_code = galaxy_run.run_galaxy_command( ctx, cmd, config.env, action ) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) try: test_data = test_results.structured_data if 'test_output' in kwds: output_path = kwds['test_output'] if output_path is not None: with open(output_path, 'w') as handle: handle.write(build_report.build_report(test_data)) for kw_name in ('markdown', 'text'): if 'test_output_%s' % kw_name in kwds: output_path = kwds['test_output_%s' % kw_name] if output_path is None: continue with open(output_path, 'w') as handle: handle.write(build_report.build_report(test_data, report_type=kw_name)) except Exception: ctx.vlog("Problem producing test output.", exception=True) __handle_summary( test_results, **kwds ) return return_code
def run_in_config(ctx, config, run=run_galaxy_command, **kwds): """Run Galaxy tests with the run_tests.sh command. The specified `config` object describes the context for tool execution. """ config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_report_file = _xunit_state(kwds, config) xunit_report_file_tracker = _FileChangeTracker(xunit_report_file) structured_report_file = _structured_report_file(kwds, config) structured_report_file_tracker = _FileChangeTracker(structured_report_file) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root test_cmd = test_structures.GalaxyTestCommand( html_report_file, xunit_report_file, structured_report_file, failed=kwds.get("failed", False), installed=kwds.get("installed", False), ).build() setup_common_startup_args = "" if kwds.get("skip_venv", False): setup_common_startup_args = ( 'COMMON_STARTUP_ARGS=--skip-venv; ' 'export COMMON_STARTUP_ARGS; ' 'echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"') setup_venv_command = setup_venv(ctx, kwds) cmd = shell_join( cd_to_galaxy_command, setup_common_startup_args, setup_venv_command, test_cmd, ) action = "Testing tools" return_code = run(ctx, cmd, config.env, action) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) _check_test_outputs(xunit_report_file_tracker, structured_report_file_tracker) test_results = test_structures.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) structured_data = test_results.structured_data return handle_reports_and_summary(ctx, structured_data, exit_code=test_results.exit_code, kwds=kwds)
def cli(ctx, path, **kwds): """Run the tests in the specified tool tests in a Galaxy instance. All referenced tools (by default all the tools in the current working directory) will be tested and the results quickly summarized. To run these tests planemo needs a Galaxy instance to utilize, planemo will search parent directories to see if any is a Galaxy instance - but one can pick the Galaxy instance to use with the --galaxy_root option or force planemo to download a disposable instance with the ``--install_galaxy`` flag. In additon to to quick summary printed to the console - various detailed output summaries can be configured. ``tool_test_output.html`` (settable via ``--test_output``) will contain a human consumable HTML report describing the test run. A JSON file (settable via ``--test_output_json`` and defaulting to ``tool_test_output.json``) will also be created. These files can can be disabled by passing in empty arguments or globally by setting the values ``default_test_output`` and/or ``default_test_output_json`` in ``~/.planemo.yml`` to ``null``. For continuous integration testing a xUnit-style report can be confiured using the ``--test_output_xunit``. planemo uses temporarily generated config files and environment variables to attempt to shield this execution of Galaxy from manually launched runs against that same Galaxy root - but this may not be bullet proof yet so please careful and do not try this against production Galaxy instances. """ for name, default in OUTPUT_DFEAULTS.items(): __populate_default_output(ctx, name, kwds, default) kwds["for_tests"] = True with galaxy_config.galaxy_config(ctx, path, **kwds) as config: config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root cmd = "; ".join([ cd_to_galaxy_command, galaxy_run.ACTIVATE_COMMAND, # TODO: this should be moved to # run_tests.sh to match run.sh. __run_tests_cmd( html_report_file, xunit_report_file, structured_report_file, ), ]) action = "Testing tools" return_code = galaxy_run.run_galaxy_command( ctx, cmd, config.env, action ) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = galaxy_test.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) try: test_data = test_results.structured_data new_report = build_report.build_report(test_data) open(test_results.output_html_path, "w").write(new_report) except Exception: pass __handle_summary( test_results, **kwds ) if return_code: sys.exit(1)
def cli(ctx, path, **kwds): """Run the tests in the specified tool tests in a Galaxy instance. All referenced tools (by default all the tools in the current working directory) will be tested and the results quickly summarized. To run these tests planemo needs a Galaxy instance to utilize, planemo will search parent directories to see if any is a Galaxy instance - but one can pick the Galaxy instance to use with the --galaxy_root option or force planemo to download a disposable instance with the ``--install_galaxy`` flag. In additon to to quick summary printed to the console - various detailed output summaries can be configured. ``tool_test_output.html`` (settable via ``--test_output``) will contain a human consumable HTML report describing the test run. A JSON file (settable via ``--test_output_json`` and defaulting to ``tool_test_output.json``) will also be created. These files can can be disabled by passing in empty arguments or globally by setting the values ``default_test_output`` and/or ``default_test_output_json`` in ``~/.planemo.yml`` to ``null``. For continuous integration testing a xUnit-style report can be confiured using the ``--test_output_xunit``. planemo uses temporarily generated config files and environment variables to attempt to shield this execution of Galaxy from manually launched runs against that same Galaxy root - but this may not be bullet proof yet so please careful and do not try this against production Galaxy instances. """ for name, default in OUTPUT_DFEAULTS.items(): __populate_default_output(ctx, name, kwds, default) kwds["for_tests"] = True with galaxy_config.galaxy_config(ctx, path, **kwds) as config: config_directory = config.config_directory html_report_file = kwds["test_output"] job_output_files = kwds.get("job_output_files", None) if job_output_files is None: job_output_files = os.path.join(config_directory, "jobfiles") xunit_supported, xunit_report_file = __xunit_state(kwds, config) structured_report_file = __structured_report_file(kwds, config) info("Testing using galaxy_root %s", config.galaxy_root) # TODO: Allow running dockerized Galaxy here instead. server_ini = os.path.join(config_directory, "galaxy.ini") config.env["GALAXY_CONFIG_FILE"] = server_ini config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true" config.env["GALAXY_TEST_SAVE"] = job_output_files cd_to_galaxy_command = "cd %s" % config.galaxy_root cmd = "; ".join([ cd_to_galaxy_command, galaxy_run.ACTIVATE_COMMAND, # TODO: this should be moved to # run_tests.sh to match run.sh. __run_tests_cmd( html_report_file, xunit_report_file, structured_report_file, ), ]) action = "Testing tools" return_code = galaxy_run.run_galaxy_command(ctx, cmd, config.env, action) if kwds.get('update_test_data', False): update_cp_args = (job_output_files, config.test_data_dir) shell('cp -r "%s"/* "%s"' % update_cp_args) if xunit_report_file and (not os.path.exists(xunit_report_file)): warn(NO_XUNIT_MESSAGE) xunit_report_file = None test_results = galaxy_test.GalaxyTestResults( structured_report_file, xunit_report_file, html_report_file, return_code, ) try: test_data = test_results.structured_data new_report = build_report.build_report(test_data) open(test_results.output_html_path, "w").write(new_report) except Exception: pass __handle_summary(test_results, **kwds) if return_code: sys.exit(1)