From 3e9f99c67610673215364aae3950d40e0f4b1c06 Mon Sep 17 00:00:00 2001 From: Simon Bray Date: Wed, 13 Oct 2021 11:03:13 +0200 Subject: [PATCH] tmp --- tests/test_allure.py | 0 tests/test_build_and_lint.py | 123 ----- tests/test_cmd_autoupdate.py | 115 ----- tests/test_cmd_dockstore_init.py | 24 - tests/test_cmd_merge_reports.py | 11 - tests/test_cmd_test.py | 242 ---------- tests/test_cmd_test_conda.py | 87 ---- tests/test_cmd_test_reports.py | 20 - tests/test_cmd_training_fill_data_library.py | 81 ---- tests/test_cmd_training_generate_from_wf.py | 92 ---- tests/test_cmd_training_init.py | 131 ------ tests/test_cmd_workflow_convert.py | 38 -- tests/test_cmd_workflow_job_init.py | 43 -- tests/test_cmd_workflow_lint.py | 138 ------ tests/test_cmd_workflow_test_init.py | 55 --- tests/test_cmds_with_workflow_id.py | 78 ---- tests/test_command_io.py | 138 ------ tests/test_conda_lint.py | 25 -- tests/test_config_init.py | 24 - tests/test_database_commands.py | 34 -- tests/test_engines.py | 57 --- tests/test_external_galaxy_commands.py | 78 ---- tests/test_galaxy_config.py | 68 --- tests/test_galaxy_test.py | 168 ------- tests/test_git.py | 70 --- tests/test_github_create_release.py | 115 ----- tests/test_init_and_test.py | 23 - tests/test_io.py | 44 -- tests/test_lint.py | 110 ----- tests/test_normalize.py | 22 - tests/test_planemo.py | 46 -- tests/test_profile_commands.py | 32 -- tests/test_run.py | 113 ----- tests/test_shed.py | 78 ---- tests/test_shed_create.py | 61 --- tests/test_shed_diff.py | 160 ------- tests/test_shed_diff_xml.py | 10 - tests/test_shed_download.py | 36 -- tests/test_shed_expansion.py | 33 -- tests/test_shed_init.py | 93 ---- tests/test_shed_lint.py | 75 ---- tests/test_shed_operations.py | 90 ---- tests/test_shed_test.py | 35 -- tests/test_shed_upload.py | 445 ------------------- tests/test_test_checker.py | 88 ---- tests/test_test_engines.py | 208 --------- tests/test_training.py | 261 ----------- tests/test_training_tool_input.py | 289 ------------ tests/test_training_topic.py | 149 ------- tests/test_training_tutorial.py | 444 ------------------ tests/test_validation.py | 67 --- tests/test_workflow_lint.py | 20 - tests/test_xml_diff.py | 49 -- 53 files changed, 5136 deletions(-) delete mode 100644 tests/test_allure.py delete mode 100644 tests/test_build_and_lint.py delete mode 100644 tests/test_cmd_autoupdate.py delete mode 100644 tests/test_cmd_dockstore_init.py delete mode 100644 tests/test_cmd_merge_reports.py delete mode 100644 tests/test_cmd_test.py delete mode 100644 tests/test_cmd_test_conda.py delete mode 100644 tests/test_cmd_test_reports.py delete mode 100644 tests/test_cmd_training_fill_data_library.py delete mode 100644 tests/test_cmd_training_generate_from_wf.py delete mode 100644 tests/test_cmd_training_init.py delete mode 100644 tests/test_cmd_workflow_convert.py delete mode 100644 tests/test_cmd_workflow_job_init.py delete mode 100644 tests/test_cmd_workflow_lint.py delete mode 100644 tests/test_cmd_workflow_test_init.py delete mode 100644 tests/test_cmds_with_workflow_id.py delete mode 100644 tests/test_command_io.py delete mode 100644 tests/test_conda_lint.py delete mode 100644 tests/test_config_init.py delete mode 100644 tests/test_database_commands.py delete mode 100644 tests/test_engines.py delete mode 100644 tests/test_external_galaxy_commands.py delete mode 100644 tests/test_galaxy_config.py delete mode 100644 tests/test_galaxy_test.py delete mode 100644 tests/test_git.py delete mode 100644 tests/test_github_create_release.py delete mode 100644 tests/test_init_and_test.py delete mode 100644 tests/test_io.py delete mode 100644 tests/test_lint.py delete mode 100644 tests/test_normalize.py delete mode 100644 tests/test_planemo.py delete mode 100644 tests/test_profile_commands.py delete mode 100644 tests/test_run.py delete mode 100644 tests/test_shed.py delete mode 100644 tests/test_shed_create.py delete mode 100644 tests/test_shed_diff.py delete mode 100644 tests/test_shed_diff_xml.py delete mode 100644 tests/test_shed_download.py delete mode 100644 tests/test_shed_expansion.py delete mode 100644 tests/test_shed_init.py delete mode 100644 tests/test_shed_lint.py delete mode 100644 tests/test_shed_operations.py delete mode 100644 tests/test_shed_test.py delete mode 100644 tests/test_shed_upload.py delete mode 100644 tests/test_test_checker.py delete mode 100644 tests/test_test_engines.py delete mode 100644 tests/test_training.py delete mode 100644 tests/test_training_tool_input.py delete mode 100644 tests/test_training_topic.py delete mode 100644 tests/test_training_tutorial.py delete mode 100644 tests/test_validation.py delete mode 100644 tests/test_workflow_lint.py delete mode 100644 tests/test_xml_diff.py diff --git a/tests/test_allure.py b/tests/test_allure.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/test_build_and_lint.py b/tests/test_build_and_lint.py deleted file mode 100644 index 83a42470b..000000000 --- a/tests/test_build_and_lint.py +++ /dev/null @@ -1,123 +0,0 @@ -import os - -import yaml - -from .test_utils import CliTestCase, skip_if_environ - - -class BuildAndLintTestCase(CliTestCase): - - def test_build_and_lint(self): - with self._isolate(): - self._check_exit_code(_init_command()) - self._check_lint(exit_code=0) - - def test_build_and_lint_with_macros(self): - with self._isolate() as f: - self._check_exit_code(_init_command(macros=True)) - self._check_lint(exit_code=0) - macros_file = os.path.join(f, "macros.xml") - assert os.path.exists(macros_file) - - def test_lint_fails_if_no_help(self): - with self._isolate(): - self._check_exit_code(_init_command(help_text=False)) - self._check_lint(exit_code=1) - - def test_lint_fails_if_no_test(self): - with self._isolate(): - self._check_exit_code(_init_command(test_case=False)) - self._check_lint(exit_code=1) - - def test_lint_fails_if_no_doi(self): - with self._isolate(): - self._check_exit_code(_init_command(doi=False)) - self._check_lint(exit_code=1) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_cwl(self): - with self._isolate() as f: - self._check_exit_code(_cwl_init_command()) - self._check_lint(filename="seqtk_seq.cwl", exit_code=0) - - with open(os.path.join(f, "seqtk_seq.cwl")) as stream: - process_dict = yaml.safe_load(stream) - assert process_dict["id"] == "seqtk_seq" - assert process_dict["label"] == "Convert to FASTA (seqtk)" - assert process_dict["baseCommand"] == ["seqtk", "seq"] - input0 = process_dict["inputs"]["input1"] - assert input0["inputBinding"]["position"] == 1 - assert input0["inputBinding"]["prefix"] == "-a" - assert input0["type"] == "File" - output = process_dict["outputs"]["output1"] - assert output["type"] == "File" - assert output["outputBinding"]["glob"] == "out" - assert process_dict["stdout"] == "out" - - with open(os.path.join(f, "seqtk_seq_tests.yml")) as stream: - test_dict = yaml.safe_load(stream) - assert test_dict - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_cwl_fail_on_empty_help(self): - with self._isolate(): - self._check_exit_code(_cwl_init_command(help_text=False)) - self._check_lint(filename="seqtk_seq.cwl", exit_code=1) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_cwl_fail_on_no_docker(self): - with self._isolate(): - self._check_exit_code(_cwl_init_command(help_text=False)) - self._check_lint(filename="seqtk_seq.cwl", exit_code=1) - - def _check_lint(self, filename="seqtk_seq.xml", exit_code=0): - lint_cmd = ["lint", "--fail_level", "warn", filename] - try: - self._check_exit_code(lint_cmd, exit_code=exit_code) - except Exception: - with open(filename, "r") as f: - print("Failing file contents are [%s]." % f.read()) - raise - - -def _cwl_init_command(help_text=True, container=True, test_case=True): - command = [ - "tool_init", "--force", "--cwl", - "--id", "seqtk_seq", - "--name", "Convert to FASTA (seqtk)", - "--name", "Convert to FASTA (seqtk)", - "--example_command", "seqtk seq -a 2.fastq > 2.fasta", - "--example_input", "2.fastq", - "--example_output", "2.fasta" - ] - if container: - command.extend(["--container", "quay.io/biocontainers/seqtk:1.2--0"]) - if help_text: - command.extend(["--help_text", "The help text."]) - if test_case: - command.append("--test_case") - - return command - - -def _init_command(test_case=True, help_text=True, doi=True, macros=False): - command = [ - "tool_init", "--force", - "--id", "seqtk_seq", - "--name", "Convert to FASTA (seqtk)", - "--requirement", "seqtk@1.0-r68", - "--example_command", "seqtk seq -a 2.fastq > 2.fasta", - "--example_input", "2.fastq", - "--example_output", "2.fasta" - ] - if test_case: - command.append("--test_case") - if help_text: - command.extend(["--help_text", "The help text."]) - if doi: - command.extend(["--doi", "10.1101/014043"]) - command.extend(["--cite_url", "https://github.com/ekg/vcflib"]) - command.extend(["--cite_url", "http://wiki.hpc.ufl.edu/doc/Seqtk"]) - if macros: - command.append("--macros") - return command diff --git a/tests/test_cmd_autoupdate.py b/tests/test_cmd_autoupdate.py deleted file mode 100644 index 503c323e3..000000000 --- a/tests/test_cmd_autoupdate.py +++ /dev/null @@ -1,115 +0,0 @@ -"""Tests for the ``autoupdate`` command.""" -import json -import os -import tempfile - -import yaml - -from .test_utils import ( - CliTestCase -) - - -def create_tmp_test_tool_file(tool_version): - """ - Note that to ensure this test is stable, we use packages that have - been migrated from bioconda to conda-forge and test with --conda_channels bioconda - so that the versions are guaranteed not to increase in future. - """ - xml_str = f""" - - {tool_version} - 1 - - - xopen - smina - - - """ - t = tempfile.NamedTemporaryFile(suffix='.xml', delete=False, mode='w') - t.write(xml_str) - return t.name - - -class CmdAutoupdateTestCase(CliTestCase): - """Container class defining test cases for the ``autoupdate`` command.""" - - def setUp(self): - super(CmdAutoupdateTestCase, self).setUp() - - def test_autoupdate_dry_run(self): - """Test autoupdate command with dry run flag.""" - with self._isolate(): - xmlfile = create_tmp_test_tool_file('0.6.0') - autoupdate_command = [ - "autoupdate", - xmlfile, - "--conda_channels", "bioconda", - "--dry-run" - ] - result = self._runner.invoke(self._cli.planemo, autoupdate_command) - assert f"Update required to {xmlfile}!" in result.output - assert "Tool main requirement has version 0.6.0, newest conda version is 0.7.3" in result.output - - def test_autoupdate(self): - """Test autoupdate command.""" - with self._isolate(): - xmlfile = create_tmp_test_tool_file('0.6.0') - autoupdate_command = [ - "autoupdate", - xmlfile, - "--conda_channels", "bioconda" - ] - result = self._runner.invoke(self._cli.planemo, autoupdate_command) - assert f'Updating {xmlfile.split("/")[-1]} from version 0.6.0 to 0.7.3' in result.output - assert f'Tool {xmlfile} successfully updated.' in result.output - with open(xmlfile) as f: - xmlfile_contents = f.read() - assert "2017.11.9" in xmlfile_contents - - def test_autoupdate_no_update_needed(self): - """Test autoupdate command when no update is needed.""" - with self._isolate(): - xmlfile = create_tmp_test_tool_file('0.7.3') - autoupdate_command = [ - "autoupdate", - xmlfile, - "--conda_channels", "bioconda" - ] - result = self._runner.invoke(self._cli.planemo, autoupdate_command) - assert f'No updates required or made to {xmlfile}.' in result.output - - def test_autoupdate_workflow(self): - """Test autoupdate command for a workflow is needed.""" - with self._isolate_with_test_data("wf_repos/autoupdate_tests") as f: - wf_file = os.path.join(f, "diff-refactor-test.ga") - autoupdate_command = [ - "autoupdate", - wf_file, - "--galaxy_branch", - "dev" # need >= 21.05 - ] - result = self._runner.invoke(self._cli.planemo, autoupdate_command) - - assert f'Auto-updating workflow {wf_file}' in result.output - with open(wf_file) as g: - wf = json.load(g) - # check tool within parent wf has updated - assert wf["steps"]["1"]["tool_version"] == "3.7+galaxy0" - # check tool within subworkflow has updated - assert wf["steps"]["2"]["subworkflow"]["steps"]["1"]["tool_version"] == "3.7+galaxy0" - assert wf["version"] == 1 - - result = self._runner.invoke(self._cli.planemo, autoupdate_command) # rerun on already updated WF - assert 'No newer tool versions were found, so the workflow was not updated.' in result.output - - wf_file = os.path.join(f, "diff-refactor-test.gxwf.yml") - autoupdate_command[1] = wf_file - result = self._runner.invoke(self._cli.planemo, autoupdate_command) - assert f'Auto-updating workflow {wf_file}' in result.output - - with open(wf_file) as f: - wf = yaml.safe_load(f) - assert wf["steps"][0]["tool_version"] == "3.7+galaxy0" - assert wf['steps'][1]['run']['steps'][0]['tool_version'] == "3.7+galaxy0" diff --git a/tests/test_cmd_dockstore_init.py b/tests/test_cmd_dockstore_init.py deleted file mode 100644 index 391af06cd..000000000 --- a/tests/test_cmd_dockstore_init.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Tests for the ``dockstore_init`` command.""" -import os - -import yaml - -from .test_utils import ( - CliTestCase, -) - - -class CmdDockstoreInitTestCase(CliTestCase): - - def test_plain_init(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["dockstore_init"] - self._check_exit_code(init_cmd) - assert os.path.exists(".dockstore.yml") - with open(".dockstore.yml", "r") as fh: - dockstore_config = yaml.safe_load(fh) - assert str(dockstore_config["version"]) == "1.2" - assert "workflows" in dockstore_config - assert len(dockstore_config["workflows"]) == 1 - workflow_lint_cmd = ["workflow_lint", '--fail_level', 'error', f] - self._check_exit_code(workflow_lint_cmd) diff --git a/tests/test_cmd_merge_reports.py b/tests/test_cmd_merge_reports.py deleted file mode 100644 index d904aad9a..000000000 --- a/tests/test_cmd_merge_reports.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -from .test_utils import CliTestCase, TEST_DATA_DIR - - -class CmdMergeReportsTestCase(CliTestCase): - - def test_merge_reports(self): - with self._isolate(): - json_path = os.path.join(TEST_DATA_DIR, "issue381.json") - self._check_exit_code(["merge_test_reports", json_path, json_path, json_path, "out.json"], exit_code=0) diff --git a/tests/test_cmd_test.py b/tests/test_cmd_test.py deleted file mode 100644 index 6d8c2eecb..000000000 --- a/tests/test_cmd_test.py +++ /dev/null @@ -1,242 +0,0 @@ -"""Module contains :class:`CmdTestTestCase` - integration tests for the ``test`` command.""" -import json -import os -from tempfile import NamedTemporaryFile - -from .test_utils import ( - assert_exists, - CliTestCase, - PROJECT_TEMPLATES_DIR, - run_verbosely, - skip_if_environ, - skip_unless_module, - TEST_DATA_DIR, -) - -DATA_MANAGER_TEST_PATH = "data_manager/data_manager_fetch_genome_dbkeys_all_fasta/data_manager/data_manager_fetch_genome_all_fasta_dbkeys.xml" - - -class CmdTestTestCase(CliTestCase): - """Integration tests for the ``test`` command.""" - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_data_manager(self): - """Test testing a data manager test.""" - with self._isolate(), NamedTemporaryFile(prefix="data_manager_test_json") as json_out: - test_artifact = os.path.join(TEST_DATA_DIR, DATA_MANAGER_TEST_PATH) - test_command = self._test_command( - "--test_output_json", - json_out.name - ) - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - test_artifact, - ] - self._check_exit_code(test_command, exit_code=0) - with open(json_out.name, 'r') as fh: - assert json.load(fh)['summary']['num_tests'] == 1 - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_simple_yaml(self): - """Test testing a simple YAML workflow with Galaxy.""" - with self._isolate(): - random_lines = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "randomlines.xml") - cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") - test_artifact = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - "--extra_tools", random_lines, - "--extra_tools", cat, - test_artifact, - ] - self._check_exit_code(test_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_simple_ga(self): - """Test testing a simple GA workflow with Galaxy.""" - with self._isolate(): - cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") - test_artifact = os.path.join(TEST_DATA_DIR, "wf2.ga") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - "--extra_tools", cat, - test_artifact, - ] - # try: - self._check_exit_code(test_command, exit_code=0) - # except Exception: - # with open(os.path.join(f, "tool_test_output.json"), "r") as o: - # print(o.read()) - # raise - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_distro_tool(self): - """Test testing a workflow that uses distro tools.""" - with self._isolate(): - test_artifact = os.path.join(TEST_DATA_DIR, "wf4-distro-tools.gxwf.yml") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - test_artifact, - ] - # try: - self._check_exit_code(test_command, exit_code=0) - # except Exception: - # with open(os.path.join(f, "tool_test_output.json"), "r") as o: - # print(o.read()) - # raise - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_composite(self): - """Test testing a workflow that uses composite inputs.""" - with self._isolate(): - test_artifact = os.path.join(TEST_DATA_DIR, "wf6-composite-inputs.gxwf.yml") - composite_input_imzml = os.path.join(TEST_DATA_DIR, "composite_input_imzml.xml") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - "--extra_tools", composite_input_imzml, - test_artifact, - ] - self._check_exit_code(test_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_collection_inputs(self): - """Test testing a workflow with collection inputs Galaxy.""" - with self._isolate(): - test_artifact = os.path.join(TEST_DATA_DIR, "wf5-collection-input.gxwf.yml") - cat_list = os.path.join(TEST_DATA_DIR, "cat_list.xml") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--no_dependency_resolution", - "--extra_tools", cat_list, - test_artifact, - ] - # try: - self._check_exit_code(test_command, exit_code=0) - # except Exception: - # with open(os.path.join(f, "tool_test_output.json"), "r") as o: - # print(o.read()) - # raise - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_workflow_test_repository_installation_gxformat2(self): - """Test testing a workflow with collection inputs Galaxy.""" - with self._isolate(): - test_artifact = os.path.join(TEST_DATA_DIR, "wf13_tool_shed_repository_gxformat2.yml") - test_command = self._test_command() - test_command = self.append_profile_argument_if_needed(test_command) - test_command += [ - "--biocontainers", - test_artifact, - ] - self._check_exit_code(test_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_cwltool_tool_test(self): - """Test testing a CWL tool with cwltool.""" - with self._isolate() as f: - test_artifact = os.path.join(TEST_DATA_DIR, "int_tool.cwl") - test_command = self._test_command(test_artifact) - self._check_exit_code(test_command, exit_code=0) - assert_exists(os.path.join(f, "tool_test_output.json")) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_cwltool_tool_url_inputs_test(self): - """Test testing a CWL tool with cwltool.""" - with self._isolate() as f: - test_artifact = os.path.join(TEST_DATA_DIR, "cat_tool_url.cwl") - test_command = self._test_command( - "--no-container", - test_artifact, - ) - self._check_exit_code(test_command, exit_code=0) - assert_exists(os.path.join(f, "tool_test_output.json")) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - @skip_unless_module("toil") - def test_toil_tool_test(self): - """Test testing a CWL tool with cwltool.""" - with self._isolate() as f: - test_artifact = os.path.join(TEST_DATA_DIR, "int_tool.cwl") - test_command = self._test_command( - "--engine", "toil", - test_artifact, - ) - self._check_exit_code(test_command, exit_code=0) - assert_exists(os.path.join(f, "tool_test_output.json")) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_output_checks_cwltool(self): - """Test output assertions with a CWL tool with cwltool.""" - self._output_checks([]) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - @skip_unless_module("toil") - def test_output_checks_toil(self): - """Test output assertions with a CWL tool with toil.""" - self._output_checks(["--engine", "toil"]) - - def _test_command(self, *args): - test_cmd = ["--verbose"] if run_verbosely() else [] - test_cmd.append("test") - test_cmd.extend(args) - return test_cmd - - def _output_checks(self, extra_args): - with self._isolate() as f: - test_artifact = os.path.join(TEST_DATA_DIR, "output_tests_tool.cwl") - test_command = [ - "test", - "--no-container", - ] - test_command.extend(extra_args) - test_command.append(test_artifact) - self._check_exit_code(test_command, exit_code=1) - output_json_path = os.path.join(f, "tool_test_output.json") - with open(output_json_path, "r") as f: - output = json.load(f) - assert "tests" in output - tests = output["tests"] - # check out tests/data/output_tests_tool_test.yml - expected_statuses = [ - "success", - "failure", - "success", - "success", - "failure", - "success", - "failure", - "success", - "failure", - "success", - "failure", - ] - for i in range(len(expected_statuses)): - test_i = tests[i] - data = test_i["data"] - expected_status = expected_statuses[i] - assert data["status"] == expected_status - - def append_profile_argument_if_needed(self, command): - # Hook into tests to allow leveraging postgres databases to prevent Galaxy locking errors - # while running tests. - profile_name = os.getenv("PLANEMO_TEST_WORKFLOW_RUN_PROFILE", None) - - if profile_name: - command += ["--profile", profile_name] - - database_type = os.getenv("PLANEMO_TEST_WORKFLOW_RUN_PROFILE_DATABASE_TYPE", None) - if database_type: - command += ["--database_type", database_type] - - return command diff --git a/tests/test_cmd_test_conda.py b/tests/test_cmd_test_conda.py deleted file mode 100644 index 1d6991440..000000000 --- a/tests/test_cmd_test_conda.py +++ /dev/null @@ -1,87 +0,0 @@ -"""Module contains :class:`CmdTestTestCase` - integration tests for the ``test`` command.""" -import os - -from .test_utils import ( - CliTestCase, - mark, - PROJECT_TEMPLATES_DIR, - skip_if_environ, - target_galaxy_branch, - TEST_REPOS_DIR, - TEST_TOOLS_DIR, -) - - -class CmdTestCondaTestCase(CliTestCase): - """Integration tests for the ``test`` command.""" - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_conda_dependencies_by_default(self): - with self._isolate(): - bwa_test = os.path.join(PROJECT_TEMPLATES_DIR, "conda_testing", "bwa.xml") - test_command = [ - "--verbose", - "test", - "--galaxy_branch", target_galaxy_branch(), - bwa_test, - ] - self._check_exit_code(test_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_REDUNDANT_TESTS") # same code path as test above. - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_conda_dependencies_explicit_resolution(self): - with self._isolate(): - bwa_test = os.path.join(PROJECT_TEMPLATES_DIR, "conda_testing", "bwa.xml") - test_command = [ - "--verbose", - "test", - "--conda_dependency_resolution", - "--conda_auto_install", - "--conda_auto_init", - bwa_test, - ] - self._check_exit_code(test_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_conda_dependencies_version(self): - """Test tool with wrong version and ensure it fails.""" - with self._isolate(): - # Try a failing test to ensure the primary test above isn't just passing spuriously. - bwa_test = os.path.join(TEST_TOOLS_DIR, "bwa_wrong_version.xml") - test_command = [ - "--verbose", - "test", - "--galaxy_branch", target_galaxy_branch(), - "--conda_dependency_resolution", - "--conda_auto_install", - "--conda_auto_init", - bwa_test, - ] - self._check_exit_code(test_command, exit_code=1) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_local_conda_dependencies_version(self): - """Test a tool that requires local package builds.""" - with self._isolate(): - fleeqtk_recipe = os.path.join(PROJECT_TEMPLATES_DIR, "conda_answers", "exercise_2", "fleeqtk") - build_command = [ - "conda_build", - fleeqtk_recipe, - ] - self._check_exit_code(build_command) - fleeqtk_tool = os.path.join(TEST_REPOS_DIR, "conda_exercises_fleeqtk", "fleeqtk_seq.xml") - conda_install_command = [ - "conda_install", - "--conda_use_local", - fleeqtk_tool, - ] - self._check_exit_code(conda_install_command) - test_command = [ - "test", - "--galaxy_branch", target_galaxy_branch(), - fleeqtk_tool, - ] - self._check_exit_code(test_command) diff --git a/tests/test_cmd_test_reports.py b/tests/test_cmd_test_reports.py deleted file mode 100644 index c93febe18..000000000 --- a/tests/test_cmd_test_reports.py +++ /dev/null @@ -1,20 +0,0 @@ -import os - -from .test_utils import CliTestCase, TEST_DATA_DIR - - -class CmdTestReportsTestCase(CliTestCase): - - def test_build_reports(self): - with self._isolate(): - json_path = os.path.join(TEST_DATA_DIR, "issue381.json") - self._check_exit_code(["test_reports", json_path], exit_code=0) - - def test_allure(self): - with self._isolate() as f: - json_path = os.path.join(TEST_DATA_DIR, "issue381.json") - results_path = os.path.join(f, "allure_results") - self._check_exit_code(["test_reports", "--test_output_allure", results_path, json_path], exit_code=0) - assert os.path.exists(results_path) - assert os.path.isdir(results_path) - assert len(os.listdir(results_path)) diff --git a/tests/test_cmd_training_fill_data_library.py b/tests/test_cmd_training_fill_data_library.py deleted file mode 100644 index d65caef50..000000000 --- a/tests/test_cmd_training_fill_data_library.py +++ /dev/null @@ -1,81 +0,0 @@ -"""Tests for the ``training_fill_data_library`` command.""" -import os -import shutil - -from .test_cmd_training_generate_from_wf import create_tutorial_dir -from .test_utils import ( - CliTestCase, - TEST_DATA_DIR -) - - -class CmdTrainingFillDataLibraryTestCase(CliTestCase): - """Container class defining test cases for the ``training_fill_data_library`` command.""" - - def test_training_fill_data_library_command_empty(self): - """Test training_fill_data_library command with no arguments.""" - with self._isolate(): - training_fill_data_library_command = [ - "training_fill_data_library" - ] - self._check_exit_code(training_fill_data_library_command, exit_code=2) - - def test_training_fill_data_library_command_topic(self): - """Test training_fill_data_library command with only topic name.""" - with self._isolate(): - training_fill_data_library_command = [ - "training_fill_data_library", - "--topic_name", "test" - ] - self._check_exit_code(training_fill_data_library_command, exit_code=2) - - def test_training_fill_data_library_command_tutorial_topic(self): - """Test training_fill_data_library command with tutorial name.""" - with self._isolate(): - topic_n = "test" - tuto_n = "test" - datatype = os.path.join(TEST_DATA_DIR, "training_datatypes.yaml") - # not working - create_tutorial_dir(topic_n, tuto_n) - training_fill_data_library_command = [ - "training_fill_data_library", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--datatypes", datatype - ] - shutil.rmtree("topics") - self._check_exit_code(training_fill_data_library_command, exit_code=1) - # working - create_tutorial_dir(topic_n, tuto_n) - training_fill_data_library_command = [ - "training_fill_data_library", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--datatypes", datatype - ] - self._check_exit_code(training_fill_data_library_command, exit_code=0) - - def test_training_fill_data_library_command_tutorial_zenodo(self): - """Test training_fill_data_library command with zenodo link.""" - with self._isolate(): - topic_n = "test" - tuto_n = "test" - create_tutorial_dir(topic_n, tuto_n) - datatype = os.path.join(TEST_DATA_DIR, "training_datatypes.yaml") - # not working test - training_fill_data_library_command = [ - "training_fill_data_library", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--zenodo_link", "https://zenodo.org/record/1321885" - ] - self._check_exit_code(training_fill_data_library_command, exit_code=1) - # working - training_fill_data_library_command = [ - "training_fill_data_library", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--zenodo_link", "https://zenodo.org/record/1321885", - "--datatypes", datatype - ] - self._check_exit_code(training_fill_data_library_command, exit_code=0) diff --git a/tests/test_cmd_training_generate_from_wf.py b/tests/test_cmd_training_generate_from_wf.py deleted file mode 100644 index 558ae93da..000000000 --- a/tests/test_cmd_training_generate_from_wf.py +++ /dev/null @@ -1,92 +0,0 @@ -"""Tests for the ``training_generate_from_wf`` command.""" -import os -import shutil - -from .test_utils import ( - CliTestCase, - skip_if_environ, - TEST_DATA_DIR, -) - - -def create_tutorial_dir(topic_n, tuto_n): - """Create the tutorial directory structure.""" - topic_dir = os.path.join("topics", topic_n) - tuto_dir = os.path.join(topic_dir, "tutorials", tuto_n) - metadata_path = os.path.join(topic_dir, "metadata.yaml") - if not os.path.isdir(tuto_dir): - os.makedirs(tuto_dir) - if not os.path.exists(metadata_path): - metadata = os.path.join(TEST_DATA_DIR, "training_metadata.yaml") - shutil.copy(metadata, metadata_path) - shutil.copy( - os.path.join(TEST_DATA_DIR, "training_tutorial.md"), - os.path.join(tuto_dir, "tutorial.md")) - - -class CmdTrainingGenerateFromWfTestCase(CliTestCase): - """Container class defining test cases for the ``training_generate_from_wf`` command.""" - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_generate_from_wf_command_empty(self): - """Test training_generate_from_wf command with no arguments.""" - with self._isolate(): - training_fill_data_library_command = [ - "training_generate_from_wf" - ] - self._check_exit_code(training_fill_data_library_command, exit_code=2) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_generate_from_wf_command_topic(self): - """Test training_generate_from_wf command with only topic name.""" - with self._isolate(): - training_fill_data_library_command = [ - "training_generate_from_wf", - "--topic_name", "test" - ] - self._check_exit_code(training_fill_data_library_command, exit_code=2) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_generate_from_wf_command_local_wf(self): - """Test training_generate_from_wf command with local workflow.""" - with self._isolate(): - topic_n = "test" - tuto_n = "test" - test_workflow = os.path.join(TEST_DATA_DIR, "test_workflow_1.ga") - # working test - create_tutorial_dir(topic_n, tuto_n) - training_init_command = [ - "training_generate_from_wf", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--workflow", test_workflow - ] - self._check_exit_code(training_init_command, exit_code=0) - shutil.rmtree("topics") - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_generate_from_wf_command_remote_wf(self): - """Test training_generate_from_wf command with workflow on running instance.""" - with self._isolate(): - topic_n = "test" - tuto_n = "test" - # not working test - training_init_command = [ - "training_generate_from_wf", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--workflow_id", "ID" - ] - self._check_exit_code(training_init_command, exit_code=self.non_zero_exit_code) - # not working test - create_tutorial_dir(topic_n, tuto_n) - training_init_command = [ - "training_generate_from_wf", - "--topic_name", topic_n, - "--tutorial_name", tuto_n, - "--workflow_id", "ID", - "--galaxy_url", "https://usegalaxy.eu/", - "--galaxy_api_key", "API" - ] - self._check_exit_code(training_init_command, exit_code=self.non_zero_exit_code) - shutil.rmtree("topics") diff --git a/tests/test_cmd_training_init.py b/tests/test_cmd_training_init.py deleted file mode 100644 index 17cb65026..000000000 --- a/tests/test_cmd_training_init.py +++ /dev/null @@ -1,131 +0,0 @@ -"""Tests for the ``training_init`` command.""" -import os - -from .test_utils import ( - CliTestCase, - skip_if_environ, - TEST_DATA_DIR -) - - -class CmdTrainingInitTestCase(CliTestCase): - """Container class defining test cases for the ``training_init`` command.""" - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_by_default(self): - """Test training_init command with only topic name.""" - with self._isolate(): - training_init_command = [ - "training_init", - "--topic_name", "test" - ] - self._check_exit_code(training_init_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_topic(self): - """Test training_init command to create new topic.""" - with self._isolate(): - # working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--topic_title", "Topic title", - "--topic_target", "use", - "--topic_summary", "Summary" - ] - self._check_exit_code(training_init_command, exit_code=0) - # failing test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--topic_title", "Topic title", - "--topic_target", "test", - "--topic_summary", "Summary" - ] - self._check_exit_code(training_init_command, exit_code=2) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_tutorial_no_topic(self): - """Test training_init command with tutorial but no topic.""" - with self._isolate(): - # working test - training_init_command = [ - "training_init", - "--tutorial_name", "test" - ] - self._check_exit_code(training_init_command, exit_code=2) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_tutorial(self): - """Test training_init command to create new tutorial.""" - with self._isolate(): - # working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--tutorial_title", "Title of the tutorial", - "--hands_on", - "--slides" - ] - self._check_exit_code(training_init_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_tutorial_zenodo(self): - """Test training_init command to create new tutorial with zenodo.""" - with self._isolate(): - datatype = os.path.join(TEST_DATA_DIR, "training_datatypes.yaml") - # not working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--zenodo_link", "https://zenodo.org/record/1321885" - ] - self._check_exit_code(training_init_command, exit_code=1) - # working - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--zenodo_link", "https://zenodo.org/record/1321885", - "--datatypes", datatype - ] - self._check_exit_code(training_init_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_tutorial_local_wf(self): - """Test training_init command to create new tutorial with local workflow.""" - with self._isolate(): - test_workflow = os.path.join(TEST_DATA_DIR, "test_workflow_1.ga") - # working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--workflow", test_workflow - ] - self._check_exit_code(training_init_command, exit_code=0) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - def test_training_init_command_tutorial_remote_wf(self): - """Test training_init command to create new tutorial with workflow on running instance.""" - with self._isolate(): - # not working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--workflow_id", "ID" - ] - self._check_exit_code(training_init_command, exit_code=1) - # working test - training_init_command = [ - "training_init", - "--topic_name", "test", - "--tutorial_name", "test", - "--workflow_id", "ID", - "--galaxy_url", "https://usegalaxy.eu/", - "--galaxy_api_key", "API" - ] - self._check_exit_code(training_init_command, exit_code=0) diff --git a/tests/test_cmd_workflow_convert.py b/tests/test_cmd_workflow_convert.py deleted file mode 100644 index d2e674f88..000000000 --- a/tests/test_cmd_workflow_convert.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Tests for the ``workflow_test_init`` command.""" -import json -import os - -import yaml - -from .test_utils import ( - CliTestCase, - TEST_DATA_DIR, -) - - -class CmdWorkflowConvertTestCase(CliTestCase): - def test_gxwf_to_ga(self): - with self._isolate() as f: - gx2_wf_path = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml") - init_cmd = ["workflow_convert", gx2_wf_path, "-o", "wf1-test.ga"] - self._check_exit_code(init_cmd) - ga_wf_path = os.path.join(f, "wf1-test.ga") - - assert os.path.exists(ga_wf_path) - with open(ga_wf_path, "r") as stream: - wf = json.load(stream) - assert isinstance(wf, dict) - assert wf["steps"]["1"]["tool_id"] == "cat" - - def test_ga_to_gxwf(self): - with self._isolate() as f: - ga_wf_path = os.path.join(TEST_DATA_DIR, "wf1.ga") - init_cmd = ["workflow_convert", ga_wf_path, "-o", "wf1-test.yml"] - self._check_exit_code(init_cmd) - gx2_wf_path = os.path.join(f, "wf1-test.yml") - - assert os.path.exists(gx2_wf_path) - with open(gx2_wf_path, "r") as stream: - wf = yaml.safe_load(stream) - assert isinstance(wf, dict) - assert wf["steps"]["first_cat"]["tool_id"] == "cat" diff --git a/tests/test_cmd_workflow_job_init.py b/tests/test_cmd_workflow_job_init.py deleted file mode 100644 index 8734c6282..000000000 --- a/tests/test_cmd_workflow_job_init.py +++ /dev/null @@ -1,43 +0,0 @@ -"""Tests for the ``workflow_test_init`` command.""" -import os - -import yaml - -from .test_utils import ( - CliTestCase, -) - - -class CmdWorkflowJobInitTestCase(CliTestCase): - - def test_plain_init(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_job_init", "0_basic_native.yml"] - self._check_exit_code(init_cmd) - job_path = os.path.join(f, "0_basic_native_job.yml") - assert os.path.exists(job_path) - with open(job_path, "r") as stream: - job = yaml.safe_load(stream) - assert isinstance(job, dict) - assert "the_input" in job - assert job.get("the_input").get("path") == "todo_test_data_path.ext" - - def test_cannot_overwrite(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_job_init", "0_basic_native.yml"] - job_path = os.path.join(f, "0_basic_native_job.yml") - with open(job_path, "w") as f: - f.write("already exists") - self._check_exit_code(init_cmd, exit_code=1) - - def test_force(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_job_init", "--force", "0_basic_native.yml"] - job_path = os.path.join(f, "0_basic_native_job.yml") - with open(job_path, "w") as f: - f.write("already exists") - self._check_exit_code(init_cmd, exit_code=0) - with open(job_path, "r") as stream: - job = yaml.safe_load(stream) - assert isinstance(job, dict) - assert "the_input" in job diff --git a/tests/test_cmd_workflow_lint.py b/tests/test_cmd_workflow_lint.py deleted file mode 100644 index e49761685..000000000 --- a/tests/test_cmd_workflow_lint.py +++ /dev/null @@ -1,138 +0,0 @@ -"""Tests for the ``workflow_lint`` command.""" -import glob -import os - -from .test_utils import ( - CliTestCase, - TEST_DATA_DIR, -) - - -class CmdWorkflowLintTestCase(CliTestCase): - - def test_gxformat2_examples_as_repos(self): - repos = glob.glob(_wf_repo("from_format2") + "/*") - for repo in repos: - repo_basename = os.path.basename(repo) - try: - expected_exit_code = int(repo_basename[0]) - except ValueError: - # not a repo, just skip. - continue - lint_cmd = ["workflow_lint", "--skip", "tests", repo] - self._check_exit_code(lint_cmd, exit_code=expected_exit_code) - - def test_fail_level(self): - # ensure missing tests normally cause it to fail... - repo = _wf_repo("from_format2/0_basic_format2") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - # ... but not if fail_level is error - repo = _wf_repo("from_format2/0_basic_format2") - lint_cmd = ["workflow_lint", "--fail_level", "error", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_workflow_test_linting(self): - repo = _wf_repo("basic_format2_ok") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_native_ok") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_input_misspelled") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_input_missing") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_output_misnamed") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_missing_input") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - def test_workflow_test_linting_control(self): - # if we skip the tests linting - the above failures should pass - repo = _wf_repo("basic_format2_input_misspelled") - lint_cmd = ["workflow_lint", "--skip", "tests", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_input_missing") - lint_cmd = ["workflow_lint", "--skip", "tests", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_output_misnamed") - lint_cmd = ["workflow_lint", "--skip", "tests", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_missing_input") - lint_cmd = ["workflow_lint", "--skip", "tests", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_workflow_dockstore_linting(self): - repo = _wf_repo("basic_format2_dockstore") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_empty") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_dockstore_invalid_yaml") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_dockstore_wrong_descriptor") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_dockstore_wrong_test_file") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - repo = _wf_repo("basic_format2_dockstore_misspelled_primary_key") - lint_cmd = ["workflow_lint", repo] - self._check_exit_code(lint_cmd, exit_code=1) - - def test_workflow_dockstore_linting_control(self): - # run same tests as above but make sure if we skip dockstore they - # all pass - repo = _wf_repo("basic_format2_dockstore") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_empty") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_invalid_yaml") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_wrong_descriptor") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_wrong_test_file") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - repo = _wf_repo("basic_format2_dockstore_misspelled_primary_key") - lint_cmd = ["workflow_lint", "--skip", "dockstore", repo] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_lint_test_examples(self): - tags_wf = os.path.join(TEST_DATA_DIR, "wf10-tags-and-rules.gxwf.yml") - lint_cmd = ["workflow_lint", tags_wf] - self._check_exit_code(lint_cmd, exit_code=0) - - -def _wf_repo(rel_path): - return os.path.join(TEST_DATA_DIR, "wf_repos", rel_path) diff --git a/tests/test_cmd_workflow_test_init.py b/tests/test_cmd_workflow_test_init.py deleted file mode 100644 index 10813e842..000000000 --- a/tests/test_cmd_workflow_test_init.py +++ /dev/null @@ -1,55 +0,0 @@ -"""Tests for the ``workflow_test_init`` command.""" -import os - -import yaml - -from .test_utils import ( - CliTestCase, -) - - -class CmdWorkflowTestInitTestCase(CliTestCase): - - def test_plain_init(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_test_init", "0_basic_native.yml"] - self._check_exit_code(init_cmd) - test_path = os.path.join(f, "0_basic_native_tests.yml") - assert os.path.exists(test_path) - with open(test_path, "r") as stream: - test_config = yaml.safe_load(stream) - job = test_config[0]['job'] - assert isinstance(job, dict) - - def test_init_split_test(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_test_init", "--split_test", "0_basic_native.yml"] - self._check_exit_code(init_cmd) - test_path = os.path.join(f, "0_basic_native_tests.yml") - assert os.path.exists(test_path) - with open(test_path, "r") as stream: - test_config = yaml.safe_load(stream) - assert isinstance(test_config, list) - job_path = os.path.join(f, "0_basic_native_job1.yml") - assert os.path.exists(job_path) - with open(job_path, "r") as stream: - job = yaml.safe_load(stream) - assert isinstance(job, dict) - assert "the_input" in job - assert job.get("the_input").get("path") == "todo_test_data_path.ext" - - def test_cannot_overwrite(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_test_init", "0_basic_native.yml"] - test_path = os.path.join(f, "0_basic_native_tests.yml") - with open(test_path, "w") as f: - f.write("already exists") - self._check_exit_code(init_cmd, exit_code=1) - - def test_force(self): - with self._isolate_with_test_data("wf_repos/from_format2/0_basic_native") as f: - init_cmd = ["workflow_test_init", "--force", "0_basic_native.yml"] - test_path = os.path.join(f, "0_basic_native_tests.yml") - with open(test_path, "w") as f: - f.write("already exists") - self._check_exit_code(init_cmd) diff --git a/tests/test_cmds_with_workflow_id.py b/tests/test_cmds_with_workflow_id.py deleted file mode 100644 index 39025dc70..000000000 --- a/tests/test_cmds_with_workflow_id.py +++ /dev/null @@ -1,78 +0,0 @@ -import json -import os -import tempfile -import time - -from planemo import network_util -from planemo.galaxy import api -from .test_cmd_serve import UsesServeCommand -from .test_utils import ( - CliTestCase, - mark, - PROJECT_TEMPLATES_DIR, - safe_rmtree, - skip_if_environ, - TEST_DATA_DIR, -) - -TEST_HISTORY_NAME = "Cool History 42" -SERVE_TEST_VERBOSE = True - - -class CmdsWithWorkflowIdTestCase(CliTestCase, UsesServeCommand): - - @classmethod - def setUpClass(cls): - cls.galaxy_root = tempfile.mkdtemp() - - @classmethod - def tearDownClass(cls): - safe_rmtree(cls.galaxy_root) - - def setUp(self): - super(CmdsWithWorkflowIdTestCase, self).setUp() - self._port = network_util.get_free_port() - self._pid_file = os.path.join(self._home, "test.pid") - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_serve_workflow(self): - with self._isolate() as f: - random_lines = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "randomlines.xml") - cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") - self._serve_artifact = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml") - extra_args = [ - "--daemon", - "--skip_client_build", - "--pid_file", self._pid_file, - "--extra_tools", random_lines, - "--extra_tools", cat, - ] - self._launch_thread_and_wait(self._run, extra_args) - time.sleep(30) - user_gi = self._user_gi - assert len(user_gi.histories.get_histories(name=TEST_HISTORY_NAME)) == 0 - user_gi.histories.create_history(TEST_HISTORY_NAME) - assert user_gi.tools.get_tools(tool_id="random_lines1") - workflows = user_gi.workflows.get_workflows() - assert len(workflows) == 1 - workflow = workflows[0] - workflow_id = workflow["id"] - - pseudo_path = os.path.join(TEST_DATA_DIR, "wf11-remote.gxwf.yml") - remote_uri = f"gxid://workflows/{workflow_id}?runnable_path={pseudo_path}" - test_command = [ - "test", - "--engine", - "external_galaxy", - "--galaxy_url", - f"http://localhost:{self._port}", - "--galaxy_admin_key", - api.DEFAULT_ADMIN_API_KEY, - remote_uri, - ] - self._check_exit_code(test_command, exit_code=0) - output_json_path = os.path.join(f, "tool_test_output.json") - with open(output_json_path, "r") as f: - output = json.load(f) - assert "tests" in output diff --git a/tests/test_command_io.py b/tests/test_command_io.py deleted file mode 100644 index 325c99bba..000000000 --- a/tests/test_command_io.py +++ /dev/null @@ -1,138 +0,0 @@ -"""Test cases for the CommandIO abstraction in tool_builder.""" - -from planemo.tool_builder import CommandIO -from .test_utils import assert_equal - - -def test_simplest_command(): - """Test very simple command.""" - command_io = _example("random_fastq") - assert_equal(command_io.cheetah_template, "random_fastq") - - -def test_example_and_quotes(): - """Test example input/output transition.""" - command_io = _example("convert 1.bed 1.bam", example_outputs=["1.bam"], example_inputs=["1.bed"]) - assert_equal(command_io.cheetah_template, "convert '$input1' '$output1'") - assert_equal(len(command_io.outputs), 1) - assert_equal(len(command_io.inputs), 1) - - -def test_example_already_quoted(): - """Test example input/output transition.""" - command_io = _example('convert "1.bed" "1.bam"', example_outputs=["1.bam"], example_inputs=["1.bed"]) - assert_equal(command_io.cheetah_template, "convert '$input1' '$output1'") - - -def test_example_already_quoted_single(): - """Test example input/output transition.""" - command_io = _example("convert '1.bed' '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"]) - assert_equal(command_io.cheetah_template, "convert '$input1' '$output1'") - - -def test_example_cwl_simplest(): - command_io = _example("convert '1.bed' '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"]) - cwl_properties = command_io.cwl_properties() - - assert_equal(cwl_properties["base_command"], ["convert"]) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["outputs"][0].position, 2) - - -def test_example_cwl_argument(): - command_io = _example("seqtk convert '1.bed' moo '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"]) - cwl_properties = command_io.cwl_properties() - - assert_equal(cwl_properties["base_command"], ["seqtk", "convert"]) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["inputs"][0].prefix, None) - assert_equal(cwl_properties["outputs"][0].position, 3) - assert_equal(cwl_properties["outputs"][0].prefix, None) - assert_equal(cwl_properties["outputs"][0].glob, "$(inputs.output1)") - assert_equal(len(cwl_properties["arguments"]), 1) - assert_equal(cwl_properties["arguments"][0].position, 2) - assert_equal(cwl_properties["arguments"][0].value, "moo") - - -def test_example_cwl_simple_redirect(): - command_io = _example("seqtk convert '1.bed' > '1.bam'", example_outputs=["1.bam"], example_inputs=["1.bed"]) - cwl_properties = command_io.cwl_properties() - - assert_equal(cwl_properties["base_command"], ["seqtk", "convert"]) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["outputs"][0].glob, "out") - assert_equal(cwl_properties["stdout"], "out") - - -def test_prefixes_separated(): - command_io = _example( - "seqtk convert -i '1.bed' --output '1.bam'", - example_outputs=["1.bam"], - example_inputs=["1.bed"] - ) - cwl_properties = command_io.cwl_properties() - assert_equal(cwl_properties["base_command"], ["seqtk", "convert"]) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["inputs"][0].prefix.prefix, "-i") - assert_equal(cwl_properties["inputs"][0].prefix.separated, True) - - assert_equal(cwl_properties["outputs"][0].glob, "$(inputs.output1)") - assert_equal(cwl_properties["outputs"][0].prefix.prefix, "--output") - assert_equal(cwl_properties["outputs"][0].prefix.separated, True) - assert_equal(cwl_properties["stdout"], None) - - -def test_prefixes_joined(): - command_io = _example( - "seqtk convert INPUT=1.bed OUTPUT=1.bam", - example_outputs=["1.bam"], - example_inputs=["1.bed"] - ) - cwl_properties = command_io.cwl_properties() - assert_equal(cwl_properties["base_command"], ["seqtk", "convert"]) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["inputs"][0].prefix.prefix, "INPUT=") - assert_equal(cwl_properties["inputs"][0].prefix.separated, False) - - assert_equal(cwl_properties["outputs"][0].glob, "$(inputs.output1)") - assert_equal(cwl_properties["outputs"][0].prefix.prefix, "OUTPUT=") - assert_equal(cwl_properties["outputs"][0].prefix.separated, False) - assert_equal(cwl_properties["stdout"], None) - - -def test_integer_parameters(): - command_io = _example( - "seqtk convert --size 100 -i '1.bed' --threshold 2.0 --output_type bam > '1.bam'", - example_outputs=["1.bam"], - example_inputs=["1.bed"] - ) - cwl_properties = command_io.cwl_properties() - assert_equal(cwl_properties["base_command"], ["seqtk", "convert"]) - assert_equal(len(cwl_properties["inputs"]), 4) - assert_equal(cwl_properties["inputs"][0].position, 1) - assert_equal(cwl_properties["inputs"][0].type, "int") - assert_equal(cwl_properties["inputs"][0].prefix.prefix, "--size") - - assert_equal(cwl_properties["inputs"][1].position, 2) - assert_equal(cwl_properties["inputs"][1].type, "File") - assert_equal(cwl_properties["inputs"][1].prefix.prefix, "-i") - - assert_equal(cwl_properties["inputs"][2].position, 3) - assert_equal(cwl_properties["inputs"][2].type, "float") - assert_equal(cwl_properties["inputs"][2].prefix.prefix, "--threshold") - - assert_equal(cwl_properties["inputs"][3].position, 4) - assert_equal(cwl_properties["inputs"][3].type, "string") - assert_equal(cwl_properties["inputs"][3].prefix.prefix, "--output_type") - - assert_equal(cwl_properties["outputs"][0].glob, "out") - assert_equal(cwl_properties["stdout"], "out") - - -def _example(example_command, example_outputs=[], example_inputs=[]): - """Build a CommandIO object for test cases.""" - kwds = {} - kwds["example_command"] = example_command - kwds["example_output"] = example_outputs - kwds["example_input"] = example_inputs - return CommandIO(**kwds) diff --git a/tests/test_conda_lint.py b/tests/test_conda_lint.py deleted file mode 100644 index 294e8d60e..000000000 --- a/tests/test_conda_lint.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Tests for the ``conda_lint`` command.""" -import glob - -from .test_utils import ( - CliTestCase, - TEST_RECIPES_DIR, -) - - -class CondaLintTestCase(CliTestCase): - """Container class defining test cases for the ``conda_lint`` command.""" - - def test_ok_tools(self): - """Iterate through the test recipes and check that ok tools are good.""" - ok_tools = glob.glob("%s/ok_*" % TEST_RECIPES_DIR) - for ok_tool in ok_tools: - lint_cmd = ["conda_lint", ok_tool] - self._check_exit_code(lint_cmd) - - def test_fail_tools(self): - """Iterate through the test recipes and check that failing tools fail.""" - fail_tools = glob.glob("%s/fail_*" % TEST_RECIPES_DIR) - for fail_tool in fail_tools: - lint_cmd = ["conda_lint", fail_tool] - self._check_exit_code(lint_cmd, exit_code=1) diff --git a/tests/test_config_init.py b/tests/test_config_init.py deleted file mode 100644 index 372d87af6..000000000 --- a/tests/test_config_init.py +++ /dev/null @@ -1,24 +0,0 @@ -import os - -import yaml - -from .test_utils import CliTestCase - - -class ConfigInitTestCase(CliTestCase): - - def test_config(self): - assert not os.path.exists(self.planemo_yaml_path) - with self._isolate(): - self._check_exit_code(["config_init"]) - assert os.path.exists(self.planemo_yaml_path) - with open(self.planemo_yaml_path, "r") as f: - # Ensure it is valid YAML - yaml.safe_load(f) - - def test_config_wont_overwrite(self): - with self._isolate(): - # create the config - self._check_exit_code(["config_init"]) - # make sure it isn't overwritten - self._check_exit_code(["config_init"], exit_code=1) diff --git a/tests/test_database_commands.py b/tests/test_database_commands.py deleted file mode 100644 index 18f1beff8..000000000 --- a/tests/test_database_commands.py +++ /dev/null @@ -1,34 +0,0 @@ -from planemo.database.postgres_docker import stop_postgres_docker -from .test_utils import ( - CliTestCase, - skip_unless_environ, - skip_unless_executable, -) - - -class DatabaseCommandsTestCase(CliTestCase): - - @skip_unless_environ("PLANEMO_ENABLE_POSTGRES_TESTS") - def _database_commands(self, database_type="postgres"): - with self._isolate(): - result = self._check_exit_code(["database_list", "--database_type", database_type]) - assert "test1234" not in result.output - self._check_exit_code(["database_create", "test1234", "--database_type", database_type]) - result = self._check_exit_code(["database_list", "--database_type", database_type]) - assert "test1234" in result.output - self._check_exit_code(["database_delete", "test1234", "--database_type", database_type]) - result = self._check_exit_code(["database_list", "--database_type", database_type]) - assert "test1234" not in result.output - - @skip_unless_environ("PLANEMO_ENABLE_POSTGRES_TESTS") - @skip_unless_executable("psql") - def test_database_commands(self): - self._database_commands() - - @skip_unless_environ("PLANEMO_ENABLE_POSTGRES_TESTS") - @skip_unless_executable("docker") - def test_database_commands_docker(self): - try: - self._database_commands(database_type="postgres_docker") - finally: - stop_postgres_docker() diff --git a/tests/test_engines.py b/tests/test_engines.py deleted file mode 100644 index b185bc837..000000000 --- a/tests/test_engines.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Unit tests for engines and runnables.""" - -import os - -from planemo.engine import engine_context -from planemo.runnable import ( - for_path, - get_outputs, - RunnableType, -) -from .test_utils import test_context, TEST_DATA_DIR - -A_CWL_TOOL = os.path.join(TEST_DATA_DIR, "tools", "ok-cat1-tool.cwl") -A_CWL_WORKFLOW = os.path.join(TEST_DATA_DIR, "count-lines2-wf.cwl") - -A_GALAXY_TOOL = os.path.join(TEST_DATA_DIR, "tools", "ok_select_param.xml") -A_GALAXY_GA_WORKFLOW = os.path.join(TEST_DATA_DIR, "test_workflow_1.ga") -A_GALAXY_YAML_WORKFLOW = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml") - -CAN_HANDLE = { - 'galaxy': { - A_CWL_TOOL: True, - A_CWL_WORKFLOW: True, - A_GALAXY_TOOL: True, - A_GALAXY_GA_WORKFLOW: True, - A_GALAXY_YAML_WORKFLOW: True, - }, - 'cwltool': { - A_CWL_TOOL: True, - A_CWL_WORKFLOW: True, - A_GALAXY_TOOL: False, - A_GALAXY_GA_WORKFLOW: False, - A_GALAXY_YAML_WORKFLOW: False, - } -} - - -def test_can_handle(): - ctx = test_context() - for engine_type in ["galaxy", "cwltool"]: - with engine_context(ctx, engine=engine_type) as e: - for key, value in CAN_HANDLE[engine_type].items(): - assert bool(e.can_run(for_path(key))) is value - - -def test_outputs(): - outputs = get_outputs(for_path(A_CWL_WORKFLOW)) - assert len(outputs) == 1 - output_id = outputs[0].get_id() - assert output_id == "count_output" - - -def test_runnable_types(): - assert RunnableType.galaxy_tool.is_galaxy_artifact - assert RunnableType.galaxy_workflow.is_galaxy_artifact - assert not RunnableType.cwl_tool.is_galaxy_artifact - assert not RunnableType.cwl_workflow.is_galaxy_artifact diff --git a/tests/test_external_galaxy_commands.py b/tests/test_external_galaxy_commands.py deleted file mode 100644 index 79d65df60..000000000 --- a/tests/test_external_galaxy_commands.py +++ /dev/null @@ -1,78 +0,0 @@ -"""Tests for planemo commands relating to external Galaxy instances -""" -import os - -import yaml - -from planemo import cli -from planemo.engine import engine_context -from planemo.runnable import for_path -from .test_utils import ( - CliTestCase, - PROJECT_TEMPLATES_DIR, - TEST_DATA_DIR, -) - - -class ExternalGalaxyCommandsTestCase(CliTestCase): - def test_plain_init(self): - ctx = cli.PlanemoCliContext() - ctx.planemo_directory = "/tmp/planemo-test-workspace" - cat_tool = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") - test_workflow_path = os.path.join(TEST_DATA_DIR, 'wf2.ga') - - with engine_context(ctx, extra_tools=(cat_tool,)) as galaxy_engine: - with galaxy_engine.ensure_runnables_served([for_path(test_workflow_path)]) as config: - wfid = config.workflow_id(test_workflow_path) - - # commands to test - profile_list_cmd = ["profile_list"] - profile_create_cmd = ["profile_create", "test_ext_profile", "--galaxy_url", config.galaxy_url, - "--galaxy_user_key", config.user_api_key] - alias_create_cmd = ["create_alias", wfid, "--alias", "test_wf_alias", "--profile", "test_ext_profile"] - alias_list_cmd = ["list_alias", "--profile", "test_ext_profile"] - alias_delete_cmd = ["delete_alias", "--alias", "test_wf_alias", "--profile", "test_ext_profile"] - profile_delete_cmd = ["profile_delete", "test_ext_profile"] - run_cmd = ["run", "test_wf_alias", os.path.join(TEST_DATA_DIR, "wf2-job.yml"), "--profile", "test_ext_profile"] - list_invocs_cmd = ["list_invocations", "test_wf_alias", "--profile", "test_ext_profile"] - upload_data_cmd = ["upload_data", "test_wf_alias", os.path.join(TEST_DATA_DIR, "wf2-job.yml"), "new-job.yml", - "--profile", "test_ext_profile"] - - # test alias and profile creation - result = self._check_exit_code(profile_list_cmd) - assert 'test_ext_profile' not in result.output - result = self._check_exit_code(profile_create_cmd) - assert 'Profile [test_ext_profile] created' in result.output - result = self._check_exit_code(profile_list_cmd) - assert 'test_ext_profile' in result.output - result = self._check_exit_code(alias_create_cmd) - assert 'Alias test_wf_alias created.' in result.output - result = self._check_exit_code(alias_list_cmd) - assert 'test_wf_alias' in result.output - assert wfid in result.output - assert '1 aliases were found for profile test_ext_profile.' in result.output - - # test upload_data command - self._check_exit_code(upload_data_cmd) - with open("new-job.yml") as f: - new_job = yaml.safe_load(f) - assert list(new_job['WorkflowInput1']) == list(new_job['WorkflowInput2']) == ["class", "galaxy_id"] - - # test WF execution (from wfid) using created profile and alias - result = self._check_exit_code(run_cmd) - assert 'Run failed' not in result.output - result = self._check_exit_code(run_cmd + ["--no_wait"]) - assert 'Run successfully executed' in result.output - result = self._check_exit_code(list_invocs_cmd) - assert '2 invocations found.' in result.output - assert '1 jobs ok' in result.output or '"ok": 1' in result.output # so it passes regardless if tabulate is installed or not - - # test alias and profile deletion - result = self._check_exit_code(alias_delete_cmd) - assert 'Alias test_wf_alias was successfully deleted from profile test_ext_profile' in result.output - result = self._check_exit_code(alias_list_cmd) - assert '0 aliases were found for profile test_ext_profile.' in result.output - result = self._check_exit_code(profile_delete_cmd) - assert 'Profile deleted.' in result.output - result = self._check_exit_code(profile_list_cmd) - assert 'test_ext_profile' not in result.output diff --git a/tests/test_galaxy_config.py b/tests/test_galaxy_config.py deleted file mode 100644 index 01b097c1c..000000000 --- a/tests/test_galaxy_config.py +++ /dev/null @@ -1,68 +0,0 @@ -"""Unit tests for ``planemo.galaxy.config``.""" -import contextlib -import os - -import yaml - -from planemo.galaxy.config import ( - galaxy_config, - get_refgenie_config, -) -from .test_utils import ( - skip_if_environ, - TempDirectoryContext, - test_context, -) - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_defaults(): - """Test by default Galaxy files are stored in temp ``config_directory``.""" - with _test_galaxy_config() as config: - config_directory = config.config_directory - _assert_property_is(config, "file_path", os.path.join(config_directory, "files")) - conn = "sqlite:///%s/galaxy.sqlite?isolation_level=IMMEDIATE" % config_directory - _assert_property_is(config, "database_connection", conn) - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_database_connection_override_path(): - """Test by default Galaxy files are stored in temp ``config_directory``.""" - conn = "postgresql://username:password@localhost/mydatabase" - with _test_galaxy_config(database_connection=conn) as config: - _assert_property_is(config, "database_connection", conn) - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_override_files_path(): - """Test Galaxy file path overrideable with --file_path.""" - with TempDirectoryContext() as tdc: - with _test_galaxy_config(file_path=tdc.temp_directory) as config: - _assert_property_is(config, "file_path", tdc.temp_directory) - - -def test_refgenie_config_version(): - with TempDirectoryContext() as tdc: - galaxy_lib_path = os.path.join(tdc.temp_directory, 'lib', 'galaxy') - os.makedirs(galaxy_lib_path) - version_path = os.path.join(galaxy_lib_path, 'version.py') - with open(version_path, 'w') as version_fh: - version_fh.write('VERSION_MAJOR = "21.05"') - refgenie_config = get_refgenie_config(galaxy_root=tdc.temp_directory, refgenie_dir='/') - assert yaml.load(refgenie_config)['config_version'] == 0.3 - - -def _assert_property_is(config, prop, value): - env_var = "GALAXY_CONFIG_OVERRIDE_%s" % prop.upper() - assert config.env[env_var] == value - - -@contextlib.contextmanager -def _test_galaxy_config(tool_paths=[], **kwargs): - ctx = test_context() - with TempDirectoryContext() as tdc: - test_data = os.path.join(tdc.temp_directory, "test-data") - os.makedirs(test_data) - kwargs["test_data"] = test_data - with galaxy_config(ctx, tool_paths, **kwargs) as gc: - yield gc diff --git a/tests/test_galaxy_test.py b/tests/test_galaxy_test.py deleted file mode 100644 index 572f3f7c4..000000000 --- a/tests/test_galaxy_test.py +++ /dev/null @@ -1,168 +0,0 @@ -"""Tests for the `planeo.galaxy.test` module.""" - -import os -import shutil - -from planemo.galaxy.test import structures -from planemo.galaxy.test.actions import passed -from planemo.galaxy.test.actions import run_in_config -from .test_utils import ( - TempDirectoryTestCase, - test_context, - TEST_DATA_DIR, -) - -nose_1_3_report = os.path.join(TEST_DATA_DIR, "xunit_nose_1_3.xml") -nose_0_11_report = os.path.join(TEST_DATA_DIR, "xunit_nose_0_11.xml") - -xunit_report_with_failure = os.path.join(TEST_DATA_DIR, "xunit_failure.xml") - - -class RunInConfigTestCase(TempDirectoryTestCase): - """Test cases for ``run_in_config``.""" - - def setUp(self): - """Setup mock keywords, context, and Galaxy config for tests.""" - super(RunInConfigTestCase, self).setUp() - td = self.temp_directory - self.ctx = test_context() - self.config = _MockConfig(td) - self.kwds = { - "test_output": os.path.join(td, "tests.html"), - "test_output_json": os.path.join(td, "tests.json"), - "test_output_xunit": os.path.join(td, "tests.xml"), - "summary": "full", - } - - def test_failed_execution(self): - """Test run_in_config with a failed test.""" - def mock_galaxy_run(ctx_, command, env, action): - self._copy_failing_artifacts(["xml", "html", "json"]) - return 1 - - assert self._do_run(mock_galaxy_run) == 1 - - def test_failed_execution_minimal(self): - """Test run_in_config with a failed test.""" - self.kwds["summary"] = "minimal" - self.test_failed_execution() - - def test_failed_execution_no_summary(self): - """Test run_in_config with a failed test.""" - self.kwds["summary"] = "none" - self.test_failed_execution() - - def test_normal_execution(self): - """Test normal operation of run_in_config.""" - def mock_galaxy_run(ctx_, command, env, action): - assert ctx_ is self.ctx - assert env["test_key"] == "test_value" - self._copy_good_artifacts(["xml", "html", "json"]) - return 0 - - assert self._do_run(mock_galaxy_run) == 0 - - def test_normal_execution_summary_minimal(self): - """Test normal operation with minimal summary printed.""" - self.kwds["summary"] = "minimal" - self.test_normal_execution() - - def test_normal_execution_summary_none(self): - """Test normal operation with no summary printed.""" - self.kwds["summary"] = "none" - self.test_normal_execution() - - def test_failed_to_produce_xunit(self): - """Test an exception is thrown if not XUnit report is produced.""" - def mock_galaxy_run(ctx_, command, env, action): - self._copy_good_artifacts(["json", "html"]) - return 0 - - with self.assertRaises(Exception): - self._do_run(mock_galaxy_run) - - def test_failed_to_produce_json(self): - """Test an exception is thrown if not XUnit report is produced.""" - def mock_galaxy_run(ctx_, command, env, action): - self._copy_good_artifacts(["xml", "html"]) - return 0 - - with self.assertRaises(Exception): - self._do_run(mock_galaxy_run) - - def test_failed_to_update_xml(self): - """Test an exception is thrown if XUnit report isn't updated.""" - self._copy_good_artifacts(["xml", "html", "json"]) - - def mock_galaxy_run(ctx_, command, env, action): - self._copy_good_artifacts(["json", "html"]) - return 0 - - with self.assertRaises(Exception): - self._do_run(mock_galaxy_run) - - def test_failed_to_update_json(self): - """Test an exception is thrown if XUnit report isn't updated.""" - self._copy_good_artifacts(["xml", "html", "json"]) - - def mock_galaxy_run(ctx_, command, env, action): - self._copy_good_artifacts(["xml", "html"]) - return 0 - - with self.assertRaises(Exception): - self._do_run(mock_galaxy_run) - - def _copy_artifacts(self, suffix, extensions): - for extension in extensions: - source = os.path.join(TEST_DATA_DIR, "tt_%s.%s" % (suffix, extension)) - destination = os.path.join(self.temp_directory, "tests.%s" % extension) - shutil.copy(source, destination) - - def _copy_good_artifacts(self, extensions): - self._copy_artifacts("success", extensions) - - def _copy_failing_artifacts(self, extensions): - self._copy_artifacts("fail", extensions) - - def _do_run(self, mock_run_function): - return run_in_config(self.ctx, self.config, run=mock_run_function, **self.kwds) - - -def get_test_id_new(): - """Test ID parsing on newer nose dependency.""" - _get_test_id(nose_1_3_report) - - -def get_test_id_old(): - """Test ID parsing on older nose dependency.""" - _get_test_id(nose_0_11_report) - - -def _get_test_id(path): - xml_tree = structures.parse_xunit_report(path) - root = xml_tree.getroot() - first_testcase = structures.find_cases(root)[0] - test_id = structures.case_id(first_testcase) - assert test_id.label == "cat[0]" - expected_id = "functional.test_toolbox.TestForTool_cat.test_tool_000000" - assert test_id.id == expected_id - assert test_id.num == 0 - - -def test_passed(): - """Test :func:`passed`.""" - xml_tree = structures.parse_xunit_report(xunit_report_with_failure) - root = xml_tree.getroot() - good_testcase_el = structures.find_cases(root)[0] - assert passed(good_testcase_el) - - bad_testcase_el = structures.find_cases(root)[1] - assert not passed(bad_testcase_el) - - -class _MockConfig(object): - - def __init__(self, temp_directory): - self.config_directory = temp_directory - self.env = {"test_key": "test_value"} - self.galaxy_root = os.path.join(self.config_directory, "galaxy-dev") diff --git a/tests/test_git.py b/tests/test_git.py deleted file mode 100644 index a8e9d0759..000000000 --- a/tests/test_git.py +++ /dev/null @@ -1,70 +0,0 @@ -"""Test git library functions in ``planemo.git``.""" -import contextlib -import os - -from planemo import git -from .test_utils import io - -EXPECTED_HELLO_REV = "1c36390f585f8baa953548c00fc18c58e32fcf8b" - -COMMITTER_DATE = "GIT_COMMITTER_DATE='2000-01-01T00:00:00+0000'" -COMMITTER_NAME = "GIT_COMMITTER_NAME='a' GIT_COMMITTER_EMAIL='a@example.com'" -COMMIT = ("git commit --date='2000-01-01T00:00:00+0000' " - "--author='a ' -m 'initial'") - - -def test_rev(): - with _git_directory() as t: - rev = git.rev(None, t) - assert rev == EXPECTED_HELLO_REV, rev - - -def test_rev_if_git(): - with io.temp_directory() as t: - rev = git.rev_if_git(None, t) - assert rev is None - - -def test_rev_dirty_if_git(): - with _git_directory() as t: - io.write_file(os.path.join(t, "README"), "Hello World!") - rev = git.rev_if_git(None, t) - assert rev == EXPECTED_HELLO_REV + "-dirty", rev - - -def test_diff(): - with _git_directory() as t: - io.write_file(os.path.join(t, "README"), "new docs") - _add_and_commit(t, ["README"]) - io.write_file(os.path.join(t, "file1"), "file1") - _add_and_commit(t, ["file1"]) - io.write_file(os.path.join(t, "file1"), "file1 changed") - _add_and_commit(t, ["file1"]) - assert git.diff(None, t, "HEAD~..HEAD") == ["file1"] - assert "README" in git.diff(None, t, "HEAD~~~..HEAD") - - -@contextlib.contextmanager -def _git_directory(): - with io.temp_directory() as t: - io.write_file(os.path.join(t, "README"), "Hello!") - _add_and_commit(t, ["README"], init=True) - yield t - - -def _add_and_commit(t, files, init=False): - cmd = " && ".join([ - "cd '{0}'", - "git init ." if init else "true", - "git add %s" % " ".join(files), - _commit_command(), - ]).format(t) - assert io.shell(cmd) == 0 - - -def _commit_command(): - return "%s %s %s" % ( - COMMITTER_DATE, - COMMITTER_NAME, - COMMIT - ) diff --git a/tests/test_github_create_release.py b/tests/test_github_create_release.py deleted file mode 100644 index c27c3c7d9..000000000 --- a/tests/test_github_create_release.py +++ /dev/null @@ -1,115 +0,0 @@ -import os -import uuid - -import pytest - -from planemo import git -from planemo.github_util import ( - add_dir_contents_to_repo, - assert_new_version, - changelog_in_repo, - get_or_create_repository, -) -from planemo.io import temp_directory -from .test_utils import ( - test_context, -) - - -def test_changelog_in_repo(): - CHANGELOG = """ -# Changelog - -## [0.2] - -### Changed - -- Turn the AmpliconRemoval variant FILTER into an AmpliconBias INFO flag - - -## [0.1] - -- Initial version of COVID-19: variation analysis on ARTIC PE data workflow - """ - EXPECTED_FRAGMENT = """## [0.2] - -### Changed - -- Turn the AmpliconRemoval variant FILTER into an AmpliconBias INFO flag -""" - with temp_directory() as test_dir: - with open(os.path.join(test_dir, "CHANGELOG.md"), 'w') as changelog: - changelog.write(CHANGELOG) - assert changelog_in_repo(test_dir) == EXPECTED_FRAGMENT - - -def test_get_or_create_repo_with_existing_repo(): - ctx = test_context() - ctx._global_config = {"github": {"access_token": 'ABCDEFG'}} - repository_path = get_or_create_repository(ctx, owner='galaxyproject', repo='planemo', dry_run=False) - assert os.path.exists(os.path.join(repository_path, 'README.rst')) - - -def test_get_or_create_repo_with_new_repo(): - ctx = test_context() - ctx._global_config = {"github": {"access_token": 'ABCDEFG'}} - with pytest.raises(RuntimeError) as excinfo: - # Token isn't valid, so this errors out while running gh create - get_or_create_repository(ctx, owner=str(uuid.uuid4()), repo='some-repo', dry_run=False) - assert "Problem executing commands" in str(excinfo.value) - assert "repo create -y" in str(excinfo.value) - - -def test_add_dir_contents_to_repo(): - ctx = test_context() - ctx._global_config = {"github": {"access_token": 'ABCDEFG'}} - with temp_directory() as test_dir, temp_directory() as repo_dir: - with open(os.path.join(test_dir, 'Readme.md'), 'w') as readme: - readme.write('#Very important!') - git.init(ctx, repo_path=repo_dir) - with pytest.raises(RuntimeError) as excinfo: - # Can't push without remote - add_dir_contents_to_repo( - ctx, - from_dir=test_dir, - target_dir="workflows/my-cool-workflow", - target_repository_path=repo_dir, - version=1.0, - notes='The big release!', - dry_run=False - ) - assert "Problem executing commands git push" in str(excinfo.value) - - -def test_add_dir_contents_to_repo_dry_run(): - ctx = test_context() - ctx._global_config = {"github": {"access_token": 'ABCDEFG'}} - with temp_directory() as test_dir, temp_directory() as repo_dir: - with open(os.path.join(test_dir, 'Readme.md'), 'w') as readme: - readme.write('#Very important!') - git.init(ctx, repo_path=repo_dir) - add_dir_contents_to_repo( - ctx, - from_dir=test_dir, - target_dir="workflows/my-cool-workflow", - target_repository_path=repo_dir, - version=1.0, - notes='The big release!', - dry_run=True - ) - - -def test_git_ls_remote(): - ctx = test_context() - tags_and_commits = git.ls_remote(ctx, 'https://github.com/galaxyproject/galaxy') - assert 'refs/heads/release_20.09' in tags_and_commits - - -def test_assert_is_new_version_raises_exception(): - with pytest.raises(Exception) as excinfo: - assert_new_version(None, version='v20.05', owner='galaxyproject', repo='galaxy') - assert "Please change the version" in str(excinfo) - - -def test_assert_is_new_version(): - assert_new_version(None, version='v20.06', owner='galaxyproject', repo='galaxy') diff --git a/tests/test_init_and_test.py b/tests/test_init_and_test.py deleted file mode 100644 index b1691adb4..000000000 --- a/tests/test_init_and_test.py +++ /dev/null @@ -1,23 +0,0 @@ -from .test_utils import ( - CliTestCase, - mark, - skip_if_environ, - target_galaxy_branch, -) - - -class InitAndTestTestCase(CliTestCase): - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_init_and_test(self): - with self._isolate(): - init_cmd = ["project_init", "--template", "demo", "basic"] - self._check_exit_code(init_cmd) - test_cmd = [ - "test", - "--no_dependency_resolution", - "--galaxy_branch", target_galaxy_branch(), - "basic/cat.xml" - ] - self._check_exit_code(test_cmd) diff --git a/tests/test_io.py b/tests/test_io.py deleted file mode 100644 index d81ba5235..000000000 --- a/tests/test_io.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Test utilities from :module:`planemo.io`.""" -import tempfile - -from planemo import io -from .test_utils import assert_equal - - -def test_io_capture(): - """Test :func:`planemo.io.conditionally_captured_io`.""" - with io.conditionally_captured_io(True, tee=False) as capture: - io.warn("Problem...") - assert_equal(capture[0]["data"], "Problem...") - - with io.conditionally_captured_io(True, tee=False) as capture: - io.shell("echo 'Problem...'") - assert_equal(capture[0]["data"], "echo 'Problem...'") - assert_equal(capture[1]["data"], "Problem...") - - with io.conditionally_captured_io(True, tee=False) as capture: - io.communicate("echo 'Problem...'") - assert_equal(capture[0]["data"], "echo 'Problem...'") - assert_equal(capture[1]["data"], "Problem...") - - with io.conditionally_captured_io(False, tee=False) as capture: - io.communicate("echo 'Test...'") - - assert capture is None - - -def test_filter_paths(): - """Test :func:`planemo.io.filter_paths`.""" - test_cwd = "/a/b" - - def assert_filtered_is(paths, expected, **kwds): - result = io.filter_paths(paths, cwd=test_cwd, **kwds) - assert result == expected, "paths [%s] arent't expected [%s]" % (result, expected) - assert_filtered_is([], [], exclude=["/a"]) - assert_filtered_is(["/a/c"], [], exclude=["/a"]) - assert_filtered_is(["/b"], ["/b"], exclude=["/a"]) - assert_filtered_is(["/a/b/c"], [], exclude=["c"]) - with tempfile.NamedTemporaryFile(mode='w+') as tmp: - tmp.write("#exclude c\n\nc\n") - tmp.flush() - assert_filtered_is(["/a/b/c", "/a/b/d"], ["/a/b/d"], exclude_from=[tmp.name]) diff --git a/tests/test_lint.py b/tests/test_lint.py deleted file mode 100644 index a1dabe947..000000000 --- a/tests/test_lint.py +++ /dev/null @@ -1,110 +0,0 @@ -import glob -import os - -from .test_utils import ( - CliTestCase, - PROJECT_TEMPLATES_DIR, - skip_if_environ, - TEST_REPOS_DIR, - TEST_TOOLS_DIR, -) - - -class LintTestCase(CliTestCase): - - def test_ok_tools(self): - ok_tools = glob.glob("%s/ok_*" % TEST_TOOLS_DIR) - for ok_tool in ok_tools: - lint_cmd = ["lint", ok_tool] - self._check_exit_code(lint_cmd) - - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - def test_ok_urls(self): - url_path = os.path.join(TEST_TOOLS_DIR, "url.xml") - lint_cmd = ["lint", "--urls", url_path] - self._check_exit_code(lint_cmd) - - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - def test_ok_http(self): - lint_cmd = ["lint", "https://raw.githubusercontent.com/galaxyproject/planemo/master/tests/data/tools/ok_conditional.xml"] - self._check_exit_code(lint_cmd) - - def test_fail_tools(self): - fail_tools = glob.glob("%s/fail_*" % TEST_TOOLS_DIR) - for fail_tool in fail_tools: - lint_cmd = ["lint", fail_tool] - self._check_exit_code(lint_cmd, exit_code=1) - - def test_lint_default(self): - with self._isolate_repo("single_tool"): - self._check_exit_code(["lint", "--skip", "citations"]) - with self._isolate_repo("single_tool"): - self._check_exit_code(["lint"], exit_code=1) - - def test_lint_multiple(self): - names = ["fail_citation.xml", "fail_order.xml"] - paths = list(map(lambda p: os.path.join(TEST_TOOLS_DIR, p), names)) - self._check_exit_code(["lint"] + paths, exit_code=1) - self._check_exit_code( - ["lint", "--skip", "citations,xml_order"] + paths, - exit_code=0 - ) - - def test_skips(self): - fail_citation = os.path.join(TEST_TOOLS_DIR, "fail_citation.xml") - lint_cmd = ["lint", fail_citation] - self._check_exit_code(lint_cmd, exit_code=1) - - lint_cmd = ["lint", "--skip", "citations", fail_citation] - self._check_exit_code(lint_cmd, exit_code=0) - - # Check string splitting and stuff. - lint_cmd = ["lint", "--skip", "xml_order, citations", fail_citation] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_recursive(self): - nested_dir = os.path.join(TEST_REPOS_DIR, "multi_repos_nested") - - # Fails to find any tools without -r. - lint_cmd = ["lint", "--skip", "citations", nested_dir] - self._check_exit_code(lint_cmd, exit_code=2) - - # Works with -r. - lint_cmd = ["lint", "--skip", "citations", "-r", nested_dir] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_empty_cdata(self): - empty_cdata = os.path.join(TEST_TOOLS_DIR, "empty_cdata.xml") - lint_cmd = ["lint", "--skip", "citations,help", empty_cdata] - self._check_exit_code(lint_cmd, exit_code=0) - - def test_lint_doi(self): - fail_doi = os.path.join(TEST_TOOLS_DIR, "invalid_doi.xml") - lint_cmd = ["lint", "--doi", fail_doi] - self._check_exit_code(lint_cmd, exit_code=1) - - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - def test_lint_conda_requirements_empty(self): - bwa_no_reqs = os.path.join(TEST_TOOLS_DIR, "bwa_without_requirements.xml") - lint_cmd = ["lint", bwa_no_reqs] - self._check_exit_code(lint_cmd) - lint_cmd = ["lint", "--conda_requirements", bwa_no_reqs] - self._check_exit_code(lint_cmd, exit_code=self.non_zero_exit_code) - - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - def test_lint_conda_requirements_wrong_version(self): - bwa_wrong_version = os.path.join(TEST_TOOLS_DIR, "bwa_invalid_version.xml") - lint_cmd = ["lint", bwa_wrong_version] - self._check_exit_code(lint_cmd) - lint_cmd = ["lint", "--conda_requirements", bwa_wrong_version] - self._check_exit_code(lint_cmd, exit_code=self.non_zero_exit_code) - - @skip_if_environ("PLANEMO_SKIP_SLOW_TESTS") - def test_lint_dependencies_okay(self): - seqtk_seq_v6 = os.path.join(PROJECT_TEMPLATES_DIR, "seqtk_complete", "seqtk_seq.xml") - lint_cmd = ["lint", seqtk_seq_v6] - self._check_exit_code(lint_cmd) - lint_cmd = ["lint", "--conda_requirements", seqtk_seq_v6] - self._check_exit_code(lint_cmd) - lint_cmd = ["lint", "--biocontainer", seqtk_seq_v6] - self._check_exit_code(lint_cmd) diff --git a/tests/test_normalize.py b/tests/test_normalize.py deleted file mode 100644 index f187ce468..000000000 --- a/tests/test_normalize.py +++ /dev/null @@ -1,22 +0,0 @@ -""" Integration tests for normalize command. -""" - -import os - -from .test_utils import CliTestCase -from .test_utils import TEST_TOOLS_DIR - - -class NormalizeTestCase(CliTestCase): - - def test_shed_diff(self): - with self._isolate() as f: - fail_order = os.path.join(TEST_TOOLS_DIR, "fail_order.xml") - # Doesn't pass linting before normalization... - self._check_exit_code(["lint", fail_order], exit_code=1) - result = self._check_exit_code(["normalize", fail_order]) - good_path = os.path.join(f, "good.xml") - with open(good_path, "w") as good_f: - good_f.write(result.output) - # Does after! - self._check_exit_code(["lint", good_path]) diff --git a/tests/test_planemo.py b/tests/test_planemo.py deleted file mode 100644 index acdc55d49..000000000 --- a/tests/test_planemo.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" -test_planemo ----------------------------------- - -Tests for `planemo` module. -""" - -from .test_utils import CliTestCase - - -class TestPlanemo(CliTestCase): - - def test_commands_have_help(self): - commands = self._cli.list_cmds() - for command in commands: - self._check_exit_code([command, "--help"]) - - def test_responds_to_desired_commands(self): - commands = self._cli.list_cmds() - - def assert_responds_to(command): - assert command in commands, "No command %s" % command - - assert_responds_to("config_init") - assert_responds_to("create_gist") - assert_responds_to("docker_build") - assert_responds_to("docker_shell") - assert_responds_to("lint") - assert_responds_to("normalize") - assert_responds_to("project_init") - assert_responds_to("serve") - assert_responds_to("shed_diff") - assert_responds_to("shed_download") - assert_responds_to("shed_upload") - assert_responds_to("syntax") - assert_responds_to("test") - assert_responds_to("tool_init") - - def test_planemo_version_command(self): - self._check_exit_code(["--version"]) - - def test_planemo_help_command(self): - self._check_exit_code(["--help"]) diff --git a/tests/test_profile_commands.py b/tests/test_profile_commands.py deleted file mode 100644 index 63ff10748..000000000 --- a/tests/test_profile_commands.py +++ /dev/null @@ -1,32 +0,0 @@ -from planemo.database.postgres_docker import stop_postgres_docker -from .test_utils import ( - CliTestCase, - skip_unless_environ, - skip_unless_executable -) - - -class ProfileCommandsTestCase(CliTestCase): - - def _profile_commands(self, database_type="postgres"): - with self._isolate(): - result = self._check_exit_code(["profile_list"]) - assert "profile1234" not in result.output - self._check_exit_code(["profile_create", "profile1234", "--database_type", database_type]) - result = self._check_exit_code(["profile_list"]) - assert "profile1234" in result.output - self._check_exit_code(["profile_delete", "profile1234"]) - result = self._check_exit_code(["profile_list"]) - assert "profile1234" not in result.output, result.output - - @skip_unless_environ("PLANEMO_ENABLE_POSTGRES_TESTS") - @skip_unless_executable("psql") - def test_profile_commands(self): - self._profile_commands() - - @skip_unless_executable("docker") - def test_profile_commands_docker(self): - try: - self._profile_commands(database_type="postgres_docker") - finally: - stop_postgres_docker() diff --git a/tests/test_run.py b/tests/test_run.py deleted file mode 100644 index 4429515dc..000000000 --- a/tests/test_run.py +++ /dev/null @@ -1,113 +0,0 @@ -"""The module contains a class to test the ``cwl_run`` command.""" -import os - -from .test_utils import ( - CliTestCase, - CWL_DRAFT3_DIR, - mark, - PROJECT_TEMPLATES_DIR, - skip_if_environ, - target_galaxy_branch, - TEST_DATA_DIR, -) - - -def _cwl_file(name): - return os.path.normpath(os.path.join(CWL_DRAFT3_DIR, name)) - - -# TODO: Improve these tests so they actually check something instead -# of just arbitrarily exercising the code. -class RunTestCase(CliTestCase): - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_run_cat_cwltool(self): - with self._isolate() as f: - tool_path = _cwl_file("cat1-tool.cwl") - job_path = _cwl_file("cat-job.json") - test_cmd = [ - "run", - "--engine", "cwltool", - "--no_container", - tool_path, - job_path, - ] - self._check_exit_code(test_cmd) - assert os.path.exists(os.path.join(f, 'tool_test_output.html')) - assert os.path.exists(os.path.join(f, 'tool_test_output.json')) - - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - def test_run_cat_cwltool_more_options(self): - with self._isolate() as f: - tool_path = _cwl_file("cat1-tool.cwl") - job_path = _cwl_file("cat-job.json") - test_cmd = [ - "--verbose", - "run", - "--engine", "cwltool", - "--no_container", - tool_path, - job_path, - ] - self._check_exit_code(test_cmd) - assert os.path.exists(os.path.join(f, 'tool_test_output.html')) - assert os.path.exists(os.path.join(f, 'tool_test_output.json')) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @mark.tests_galaxy_branch - def test_run_gxtool_randomlines(self): - with self._isolate() as f: - tool_path = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "randomlines.xml") - job_path = os.path.join(TEST_DATA_DIR, "randomlines_job_1.json") - test_cmd = [ - "--verbose", - "run", - "--no_dependency_resolution", - "--galaxy_branch", target_galaxy_branch(), - tool_path, - job_path, - ] - self._check_exit_code(test_cmd) - assert os.path.exists(os.path.join(f, 'tool_test_output.html')) - assert os.path.exists(os.path.join(f, 'tool_test_output.json')) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - @skip_if_environ("PLANEMO_SKIP_GALAXY_CWL_TESTS") - def test_run_cat(self): - with self._isolate() as f: - tool_path = _cwl_file("cat1-tool.cwl") - job_path = _cwl_file("cat-job.json") - test_cmd = [ - "run", - "--no_dependency_resolution", - tool_path, - job_path, - ] - self._check_exit_code(test_cmd) - assert os.path.exists(os.path.join(f, 'tool_test_output.html')) - assert os.path.exists(os.path.join(f, 'tool_test_output.json')) - - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") - @skip_if_environ("PLANEMO_SKIP_GALAXY_CWL_TESTS") - def test_run_output_directory(self): - with self._isolate() as f: - tool_path = _cwl_file("wc-tool.cwl") - job_path = _cwl_file("wc-job.json") - test_cmd = [ - "--verbose", - "run", - "--no_dependency_resolution", - "--output_directory", - f, - tool_path, - job_path, - ] - self._check_exit_code(test_cmd) - assert os.path.exists(os.path.join(f, 'tool_test_output.html')) - assert os.path.exists(os.path.join(f, 'tool_test_output.json')) - output_path = os.path.join(f, "output") - assert os.path.exists(output_path) - with open(output_path, "r") as fh: - assert fh.read().startswith(" 16 198 1111") diff --git a/tests/test_shed.py b/tests/test_shed.py deleted file mode 100644 index 330bfa100..000000000 --- a/tests/test_shed.py +++ /dev/null @@ -1,78 +0,0 @@ -""" -""" - -import os -import random -import string - -import yaml -from bioblend import toolshed - -from planemo import io -from planemo.shed import username -from .test_utils import ( - CliTestCase, - skip_unless_environ, - TEST_DIR -) - - -SHED_TEMPLATE = string.Template("""owner: ${owner} -name: ${name} -description: Planemo test repository. -homepage_url: https://planemo.readthedocs.org/ -remote_repository_url: https://github.com/galaxyproject/planemo/ -type: tool_dependency_definition -categories: - - cooltools -""") - - -class ShedTestCase(CliTestCase): - - @skip_unless_environ("TEST_TOOL_SHED_API_KEY") - def test_shed(self): - shed_url = os.environ.get("TEST_TOOL_SHED_URL", - "http://localhost:9009") - shed_api_key = os.environ.get("TEST_TOOL_SHED_API_KEY") - tsi = toolshed.ToolShedInstance(shed_url, key=shed_api_key) - owner = username(tsi) - name = "planemotestrepo%d" % random.randint(0, 1000000) - with self._isolate(): - shed_yml_contents = SHED_TEMPLATE.safe_substitute( - owner=owner, - name=name, - ) - io.write_file(".shed.yml", shed_yml_contents) - test_path = os.path.join(TEST_DIR, "tool_dependencies_good_1.xml") - with open(test_path) as fh: - contents = fh.read() - io.write_file("tool_dependencies.xml", contents) - init_cmd = [ - "shed_create", - "--shed_key", shed_api_key, - "--shed_target", shed_url - ] - self._check_exit_code(init_cmd) - with open(".shed.yml", "r") as fh: - contents_dict = yaml.safe_load(fh) - contents_dict["description"] = "Update test repository." - io.write_file(".shed.yml", yaml.dump(contents_dict)) - update_cmd = [ - "shed_update", - "--shed_key", shed_api_key, - "--shed_target", shed_url - ] - self._check_exit_code(update_cmd) - upload_cmd = [ - "shed_upload", - "--shed_key", shed_api_key, - "--shed_target", shed_url - ] - self._check_exit_code(upload_cmd) - download_cmd = [ - "shed_download", - "--shed_target", shed_url, - "--destination", "shed_download.tar.gz" - ] - self._check_exit_code(download_cmd) diff --git a/tests/test_shed_create.py b/tests/test_shed_create.py deleted file mode 100644 index 6c918aa33..000000000 --- a/tests/test_shed_create.py +++ /dev/null @@ -1,61 +0,0 @@ -from planemo import shed -from .test_utils import CliShedTestCase -from .test_utils import skip - -CS1_DESCRIPTION = "The tool Cat 1 from the cat tool suite." -CS2_DESCRIPTION = "The tool Cat 2 from the cat tool suite." -SUITE_DESCRIPTION = "A suite of Cat tools." -SUITE_DESCRIPTION_LONG = "A longer description of all the cat tools." - - -class ShedCreateTestCase(CliShedTestCase): - - def test_create_single(self): - with self._isolate_repo("single_tool"): - create_command = ["shed_create", "--skip_upload"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - - @skip - def test_create_wrong_owner(self): - with self._isolate_repo("single_tool_other_owner"): - create_command = ["shed_create", "--skip_upload"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command, exit_code=1) - - def test_create_multiple(self): - with self._isolate_repo("multi_repos_nested"): - create_command = ["shed_create", "--skip_upload", "-r"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - - def test_create_expansion_configured(self): - with self._isolate_repo("multi_repos_flat_configured"): - self._multi_repo_create_and_verify() - - def test_create_expansion_flag(self): - with self._isolate_repo("multi_repos_flat_flag"): - self._multi_repo_create_and_verify() - - def test_create_expansion_flag_suite(self): - with self._isolate_repo("multi_repos_flat_flag_suite"): - self._multi_repo_create_and_verify() - suite_repo = self._get_repo_info("suite_cat") - assert suite_repo["synopsis"] == SUITE_DESCRIPTION - assert suite_repo["description"] == SUITE_DESCRIPTION_LONG - assert suite_repo["type"] == "repository_suite_definition" - - def _multi_repo_create_and_verify(self): - create_command = ["shed_create", "--skip_upload", "-r"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - cat1_repo = self._get_repo_info("cs-cat1") - cat2_repo = self._get_repo_info("cs-cat2") - assert cat1_repo is not None - assert cat1_repo["synopsis"] == CS1_DESCRIPTION - assert cat2_repo is not None - assert cat2_repo["synopsis"] == CS2_DESCRIPTION - - def _get_repo_info(self, name): - self._tsi.repositories.get_repositories() - return shed.find_repository(self._tsi, "iuc", name) diff --git a/tests/test_shed_diff.py b/tests/test_shed_diff.py deleted file mode 100644 index 54ec8ad95..000000000 --- a/tests/test_shed_diff.py +++ /dev/null @@ -1,160 +0,0 @@ -""" Integration tests for shed_diff command. -""" - -import os -import sys -import tempfile -from os.path import join -from xml.etree import ElementTree - -from planemo import io -from planemo.xml.diff import diff -from .test_shed_upload import update_package_1 -from .test_utils import ( - CliShedTestCase, - TEST_REPOS_DIR, -) - -DIFF_LINES = [ - "diff -r _workingdir_/related_file _custom_shed_/related_file", - "< A related non-tool file (modified).", - "> A related non-tool file.", -] - - -class ShedDiffTestCase(CliShedTestCase): - - def test_shed_diff(self): - with self._isolate_repo("single_tool") as f: - upload_command = ["shed_upload", "--force_repository_creation"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - io.write_file( - join(f, "related_file"), - "A related non-tool file (modified).\n", - ) - self._check_diff(f, True) - self._check_diff(f, False) - - def test_diff_doesnt_exist(self): - with self._isolate_repo("multi_repos_nested"): - diff_command = ["shed_diff"] - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=2) - - def test_diff_recursive(self): - with self._isolate_repo("multi_repos_nested") as f: - self._shed_create(recursive=True) - - diff_command = ["shed_diff", "-r"] - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=0) - - io.write_file( - join(f, "cat1", "related_file"), - "A related non-tool file (modified).\n", - ) - self._check_exit_code(diff_command, exit_code=1) - - def test_shed_diff_raw(self): - with self._isolate_repo("suite_auto"): - self._shed_create() - - diff_command = [ - "shed_diff", "-o", "diff" - ] - diff_command.append("--raw") - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=1) - - diff_command = [ - "shed_diff", "-o", "diff" - ] - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=0) - - def test_shed_diff_xml_no_diff(self): - with self._isolate_repo("package_1"): - self._shed_create() - - diff_command = ["shed_diff"] - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=0) - - def test_shed_diff_xml_diff(self): - with self._isolate_repo("package_1") as f: - self._shed_create() - - update_package_1(f) - - diff_command = ["shed_diff"] - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=1) - - def test_diff_xunit(self): - with self._isolate_repo("multi_repos_nested") as f: - self._shed_create(recursive=True) - - xunit_report = tempfile.NamedTemporaryFile(delete=False) - xunit_report.flush() - xunit_report.close() - diff_command = ["shed_diff", "-r", "--report_xunit", xunit_report.name] - diff_command.extend(self._shed_args(read_only=True)) - known_good_xunit_report = os.path.join(TEST_REPOS_DIR, - 'multi_repos_nested.xunit.xml') - known_bad_xunit_report = os.path.join(TEST_REPOS_DIR, - 'multi_repos_nested.xunit-bad.xml') - self._check_exit_code(diff_command, exit_code=0) - - with open(xunit_report.name, 'r') as fh: - compare = fh.read() - if diff( - self._make_deterministic(ElementTree.parse(known_good_xunit_report).getroot()), - self._make_deterministic(ElementTree.fromstring(compare)), - reporter=sys.stdout.write - ): - sys.stdout.write(compare) - assert False, "XUnit report different from multi_repos_nested.xunit.xml." - - io.write_file( - join(f, "cat1", "related_file"), - "A related non-tool file (modified).\n", - ) - self._check_exit_code(diff_command, exit_code=1) - - with open(xunit_report.name, 'r') as fh: - compare = fh.read() - if diff( - self._make_deterministic(ElementTree.parse(known_bad_xunit_report).getroot()), - self._make_deterministic(ElementTree.fromstring(compare)), - reporter=sys.stdout.write - ): - sys.stdout.write(compare) - assert False, "XUnit report different from multi_repos_nested.xunit-bad.xml." - - os.unlink(xunit_report.name) - - def _check_diff(self, f, raw): - diff_command = ["shed_diff", "-o", "diff"] - if raw: - diff_command.append("--raw") - diff_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(diff_command, exit_code=1) - diff_path = join(f, "diff") - with open(diff_path, "r") as diff_f: - diff = diff_f.read() - for diff_line in DIFF_LINES: - assert diff_line in diff - - def _make_deterministic(self, node): - for x in node.findall('testcase'): - if 'time' in x.attrib: - del x.attrib['time'] - - # Remove contents of stdout/stderr blocks - for y in x.findall('system-out'): - y.text = "" - for y in x.findall('system-err'): - y.text = "" - - return node diff --git a/tests/test_shed_diff_xml.py b/tests/test_shed_diff_xml.py deleted file mode 100644 index eb621b565..000000000 --- a/tests/test_shed_diff_xml.py +++ /dev/null @@ -1,10 +0,0 @@ -import os - -from planemo.shed import diff -from .test_utils import TEST_DIR - - -def test_compare(): - local = os.path.join(TEST_DIR, "repository_dependencies.xml") - shed = os.path.join(TEST_DIR, "repository_dependencies_shed.xml") - assert not diff._shed_diff(local, shed) diff --git a/tests/test_shed_download.py b/tests/test_shed_download.py deleted file mode 100644 index 2678f7761..000000000 --- a/tests/test_shed_download.py +++ /dev/null @@ -1,36 +0,0 @@ -from os.path import join - -from .test_utils import assert_exists, CliShedTestCase - - -class ShedUploadTestCase(CliShedTestCase): - - def test_download_expansion_tars(self): - with self._isolate_repo("multi_repos_flat_flag") as f: - upload_command = [ - "shed_upload", "--force_repository_creation" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - download_command = [ - "shed_download", - ] - download_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(download_command) - assert_exists(join(f, "shed_download_cs_cat1.tar.gz")) - assert_exists(join(f, "shed_download_cs_cat2.tar.gz")) - - def test_download_expansion_dir(self): - with self._isolate_repo("multi_repos_flat_flag") as f: - upload_command = [ - "shed_upload", "--force_repository_creation" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - download_command = [ - "shed_download", "--destination", "shed_d" - ] - download_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(download_command) - assert_exists(join(f, "shed_d_cs_cat1", "cat1.xml")) - assert_exists(join(f, "shed_d_cs_cat2", "cat2.xml")) diff --git a/tests/test_shed_expansion.py b/tests/test_shed_expansion.py deleted file mode 100644 index ea6a4ee90..000000000 --- a/tests/test_shed_expansion.py +++ /dev/null @@ -1,33 +0,0 @@ - -import os - -import yaml - -from planemo import shed -from .test_utils import TempDirectoryTestCase - - -class ShedExpansionTestCase(TempDirectoryTestCase): - - def test_invalid_name_with_multiple_repos(self): - self._make_shed_yml("repo1", name="repo1") - self._make_shed_yml("repo2", name="repo2") - - with self.assertRaises(Exception): - self._repos(name="repo1", recursive=True) - - def test_invalid_name_conflict(self): - self._make_shed_yml("repo2", name="repo2") - - with self.assertRaises(Exception): - self._repos(name="repo1", recursive=True) - - def _make_shed_yml(self, path, **kwds): - shed_dir = os.path.join(self.temp_directory, path) - os.makedirs(shed_dir) - shed_yml = os.path.join(shed_dir, ".shed.yml") - with open(shed_yml, "w") as f: - yaml.dump(kwds, f) - - def _repos(self, **kwds): - return shed.build_effective_repositories(self.temp_directory, **kwds) diff --git a/tests/test_shed_init.py b/tests/test_shed_init.py deleted file mode 100644 index 3c6b1a6f2..000000000 --- a/tests/test_shed_init.py +++ /dev/null @@ -1,93 +0,0 @@ -import os - -import yaml - -from .test_utils import ( - CliShedTestCase, - TEST_REPOS_DIR, -) - -TEST_WORKFLOW_PATH = os.path.join( - TEST_REPOS_DIR, - "workflow_1", - "blast_top_hit_species.ga" -) - - -class ShedInitTestCase(CliShedTestCase): - - def test_minimal(self): - with self._isolate() as f: - self._check_exit_code([ - "shed_init", "--owner", "iuc", "--name", "samtools_filter" - ]) - shed_config_path = os.path.join(f, ".shed.yml") - assert os.path.exists(shed_config_path) - with open(shed_config_path, "r") as fh: - shed_config = yaml.safe_load(fh) - assert shed_config["name"] == "samtools_filter" - assert shed_config["owner"] == "iuc" - assert shed_config["description"] == "samtools_filter" - assert len(shed_config["categories"]) == 0 - - def test_more_options(self): - with self._isolate() as f: - repo_url = "https://github.com/galaxyproject/tools-devteam" - init_command = [ - "shed_init", - "--owner", "devteam", - "--name", "samtools_filter", - "--description", "A samtools repo", - "--long_description", "A longer description.", - "--remote_repository_url", - repo_url, - "--homepage_url", "https://example.com/", - "--category", "SAM", - "--category", "Sequence Analysis", - "--category", "Statistics", - ] - self._check_exit_code(init_command) - shed_config_path = os.path.join(f, ".shed.yml") - assert os.path.exists(shed_config_path) - with open(shed_config_path, "r") as fh: - shed_config = yaml.safe_load(fh) - assert shed_config["name"] == "samtools_filter" - assert shed_config["owner"] == "devteam" - assert shed_config["description"] == "A samtools repo" - assert shed_config["long_description"] == "A longer description." - assert shed_config["remote_repository_url"] == repo_url - assert shed_config["homepage_url"] == "https://example.com/" - - categories = shed_config["categories"] - assert len(categories) == 3 - assert "SAM" in categories - assert "Statistics" in categories - - def test_from_workflow(self): - with self._isolate() as f: - init_command = ["shed_init", "--owner", "iuc"] - init_command += ["--category", "Sequence Analysis"] - init_command += ["--name", "blasthits"] - init_command += ["--from_workflow", TEST_WORKFLOW_PATH] - self._check_exit_code(init_command) - - repo_deps_path = os.path.join(f, "repository_dependencies.xml") - wf_path = os.path.join(f, "blast_top_hit_species.ga") - assert os.path.exists(repo_deps_path) - assert os.path.exists(wf_path) - - # lint repository as a way of verifying repository_dependencies - self._check_exit_code(["shed_lint"]) - - def test_bad_name(self): - with self._isolate(): - # has an invalid - - self._check_exit_code([ - "shed_init", "--owner", "iuc", "--name", "samtools-filter" - ], exit_code=1) - - def test_bad_owner(self): - with self._isolate(): - self._check_exit_code([ - "shed_init", "--owner", "IuC", "--name", "samtools_filter" - ], exit_code=1) diff --git a/tests/test_shed_lint.py b/tests/test_shed_lint.py deleted file mode 100644 index 57a0e6aa6..000000000 --- a/tests/test_shed_lint.py +++ /dev/null @@ -1,75 +0,0 @@ -from os.path import join - -from .test_utils import CliTestCase - - -class ShedLintTestCase(CliTestCase): - - def test_valid_repos(self): - with self._isolate_repo("single_tool"): - self._check_exit_code(["shed_lint"]) - with self._isolate_repo("multi_repos_nested"): - self._check_exit_code(["shed_lint", "--recursive"]) - with self._isolate_repo("package_1"): - self._check_exit_code(["shed_lint"]) - with self._isolate_repo("suite_1"): - self._check_exit_code(["shed_lint"]) - with self._isolate_repo("workflow_1"): - self._check_exit_code(["shed_lint"]) - - def test_invalid_repos(self): - # And now - with self._isolate_repo("bad_readme_rst"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_readme_md"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_repo_name"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_missing_include"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_missing_tool_deps"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_missing_repo_deps"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_package_category"): - self._check_exit_code(["shed_lint"], exit_code=1) - with self._isolate_repo("bad_invalid_yaml"): - self._check_exit_code(["shed_lint"], exit_code=254) - - def test_tool_linting(self): - # Make sure bad_invalid_tool_xml only when used with --tools. - with self._isolate_repo("bad_invalid_tool_xml"): - self._check_exit_code(["shed_lint"], exit_code=0) - with self._isolate_repo("bad_invalid_tool_xml"): - self._check_exit_code(["shed_lint", "--tools"], exit_code=1) - with self._isolate_repo("bad_tool_no_citations"): - self._check_exit_code(["shed_lint", "--tools"], exit_code=1) - - def test_invalid_nested(self): - # Created a nested repository with one good and one - # invalid repository and make sure it runs and produces - # a 254 (it ran to completion but one or more things failed - # ) - with self._isolate() as f: - for name in ["bad_invalid_yaml", "single_tool_exclude"]: - self._copy_repo(name, join(f, name)) - self._copy_repo(name, join(f, name)) - self._check_exit_code(["shed_lint", "-r"], exit_code=254) - - def test_fail_fast(self): - # Created a nested repository with one good and one - # invalid repository and make sure it exits immediately with 1. - with self._isolate() as f: - for name in ["bad_invalid_yaml", "single_tool_exclude"]: - self._copy_repo(name, join(f, name)) - self._copy_repo(name, join(f, name)) - r = self._check_exit_code(["shed_lint", "-r", "--fail_fast"], - exit_code=1) - assert isinstance(r.exception, RuntimeError) - - def test_ensure_metadata(self): - with self._isolate_repo("single_tool"): - self._check_exit_code(["shed_lint"]) - with self._isolate_repo("single_tool_exclude"): - self._check_exit_code(["shed_lint", "--ensure_metadata"], - exit_code=1) diff --git a/tests/test_shed_operations.py b/tests/test_shed_operations.py deleted file mode 100644 index 85703a667..000000000 --- a/tests/test_shed_operations.py +++ /dev/null @@ -1,90 +0,0 @@ -"""Test some lower-level utilities in planemo.shed.""" - -import os - -from planemo import shed -from .test_utils import ( - mock_shed_context, - TEST_REPOS_DIR, -) - - -def test_find_repository_id(): - with mock_shed_context() as shed_context: - repo_id = shed.find_repository_id( - ctx=None, - shed_context=shed_context, - path=".", - name="test_repo_1", - owner="iuc", - ) - assert repo_id == "r1" - - -def test_find_repository_id_missing(): - with mock_shed_context() as shed_context: - repo_id = shed.find_repository_id( - ctx=None, - shed_context=shed_context, - path=".", - name="test_repo_absent", - owner="iuc", - allow_none=True - ) - assert repo_id is None - - -def test_find_repository_id_missing_exception(): - with mock_shed_context() as shed_context: - exception = None - try: - shed.find_repository_id( - ctx=None, - shed_context=shed_context, - path=".", - name="test_repo_absent", - owner="iuc" - ) - except Exception as e: - exception = e - assert exception is not None - - -def test_find_category_ids(): - with mock_shed_context() as shed_context: - category_ids = shed.find_category_ids( - shed_context.tsi, - ["Text Manipulation"] - ) - assert category_ids == ["c1"] - - -def test_create_simple(): - with mock_shed_context() as shed_context: - path = os.path.join(TEST_REPOS_DIR, "single_tool") - repo_config = shed.shed_repo_config(shed_context, path) - create_response = shed.create_repository_for( - None, - shed_context.tsi, - "single_tool", - repo_config, - ) - assert "id" in create_response - repo_id = shed.find_repository_id( - ctx=None, - shed_context=shed_context, - path=".", - name="single_tool", - owner="iuc" - ) - assert repo_id == create_response["id"] - - -def test_suite_repositories_different_owners(): - with mock_shed_context() as shed_context: - path = os.path.join(TEST_REPOS_DIR, "multi_repos_flat_configured_owners") - repo_config = shed.shed_repo_config(shed_context, path) - assert '' in \ - repo_config["repositories"]["suite_cat"]["_files"]["repository_dependencies.xml"], repo_config - assert '' in \ - repo_config["repositories"]["suite_cat"]["_files"]["repository_dependencies.xml"], repo_config diff --git a/tests/test_shed_test.py b/tests/test_shed_test.py deleted file mode 100644 index 46714ecab..000000000 --- a/tests/test_shed_test.py +++ /dev/null @@ -1,35 +0,0 @@ -import os - -from .test_utils import ( - CliTestCase, - skip, - skip_if_environ, - TEST_REPOS_DIR, -) - -SHED_TARGET = "toolshed" - - -class ShedTestTestCase(CliTestCase): - - @skip # Skip for now since toolshed has invalid test data for 0.11.4 - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @skip_if_environ("PLANEMO_SKIP_SHED_TESTS") - def test_shed_test_fastqc(self): - self.__run_shed_test("fastqc") - - @skip # Skip for now since toolshed has problem with op column. - @skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") - @skip_if_environ("PLANEMO_SKIP_SHED_TESTS") - def test_shed_test_datamash(self): - self.__run_shed_test("datamash") - - def __run_shed_test(self, repo_name, target=SHED_TARGET): - repo_path = os.path.join(TEST_REPOS_DIR, "datamash") - test_cmd = [ - "shed_test", - "--shed_target", target, - "--install_galaxy", - repo_path, - ] - self._check_exit_code(test_cmd) diff --git a/tests/test_shed_upload.py b/tests/test_shed_upload.py deleted file mode 100644 index 3b2a7c162..000000000 --- a/tests/test_shed_upload.py +++ /dev/null @@ -1,445 +0,0 @@ -"""Integration tests for shed contents commands. - -Specifically, tests for shed_upload, shed_download, and shed_create. -commands. -""" -import contextlib -import os -import shutil -import tarfile -from os.path import exists, join - -from galaxy.util import unicodify - -from planemo import git -from planemo.io import shell -from .test_utils import ( - assert_exists, - CliShedTestCase, - modify_environ, - TEST_REPOS_DIR, -) - - -class ShedUploadTestCase(CliShedTestCase): - - def test_tar_single(self): - with self._isolate_repo("single_tool") as f: - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - assert_exists(join(f, "shed_upload.tar.gz")) - - def test_upload_not_exists(self): - with self._isolate_repo("single_tool"): - upload_command = ["shed_upload"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command, exit_code=2) - - def test_update_not_exists(self): - with self._isolate_repo("single_tool"): - upload_command = ["shed_update"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command, exit_code=2) - - def test_update_not_exists_update_only(self): - with self._isolate_repo("single_tool"): - upload_command = ["shed_update", "--skip_upload"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command, exit_code=2) - - def test_update_with_check_diff(self): - with self._isolate_repo("single_tool") as f: - self._shed_create() - - self._assert_shed_diff(diff=0) - - upload_command = [ - "shed_update", "--force_repository_creation", "--check_diff" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - - # First time no difference. - r = self._check_exit_code(upload_command) - assert "not different, skipping upload." in r.output - - # Modify a file so there is a difference. - with open(join(f, "related_file"), "w") as rf: - rf.write("new_contents") - - self._assert_shed_diff(diff=1) - - # No assert there is no difference again. - r = self._check_exit_code(upload_command) - assert "not different, skipping upload." not in r.output - - self._assert_shed_diff(diff=0) - - def test_update_with_check_diff_package(self): - with self._isolate_repo("package_1") as f: - self._shed_create() - - self._assert_shed_diff(diff=0) - upload_command = [ - "shed_update", "--force_repository_creation", "--check_diff" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - - # First time no difference. - r = self._check_exit_code(upload_command) - assert "not different, skipping upload." in r.output - - update_package_1(f) - self._assert_shed_diff(diff=1) - - # No assert there is no difference again. - r = self._check_exit_code(upload_command) - assert "not different, skipping upload." not in r.output - - self._assert_shed_diff(diff=0) - - def test_update_with_force_create_metadata_only(self): - with self._isolate_repo("single_tool") as f: - upload_command = ["shed_update", "--force_repository_creation", "--skip_upload"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_empty_repository(f) - - def test_update_with_force_create(self): - with self._isolate_repo("single_tool") as f: - upload_command = ["shed_update", "--force_repository_creation"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_single_uploaded(f) - - def test_tar_from_git(self): - with self._isolate() as f: - with self._git_configured(): - dest = join(f, "single_tool") - self._copy_repo("single_tool", dest) - shell(" && ".join([ - "cd %s" % dest, - "git init", - "git add .", - "git commit -m 'initial commit'" - ])) - upload_command = [ - "shed_update", "--force_repository_creation", - "git+single_tool/.git" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_single_uploaded(f, ["single_tool"]) - - def test_upload_from_git(self): - with self._isolate() as f: - with self._git_configured(): - dest = join(f, "single_tool") - self._copy_repo("single_tool", dest) - shell(" && ".join([ - "cd %s" % dest, - "git init", - "git add .", - "git commit -m 'initial commit'" - ])) - rev = git.rev(None, "single_tool") - upload_command = [ - "shed_update", "--force_repository_creation", - "git+single_tool/.git" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_single_uploaded(f, ["single_tool"]) - model = self.mock_shed.model - repo_id = self.repository_by_name("single_tool")["id"] - message = model._repositories_msg[repo_id][0] - assert "planemo upload for repository " in message - assert "repository https://github.com/galaxyproject" in message - assert rev in message - - @contextlib.contextmanager - def _git_configured(self): - with modify_environ({ - "GIT_AUTHOR_NAME": "planemo developer", - "GIT_COMMITTER_NAME": "planemo developer", - "EMAIL": "planemo@galaxyproject.org", - "GIT_AUTHOR_EMAIL": "planemo@galaxyproject.org", - "GIT_COMMITTER_EMAIL": "planemo@galaxyproject.org", - }): - yield - - def test_create_and_upload(self): - with self._isolate_repo("single_tool") as f: - create_command = ["shed_create"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - upload_command = ["shed_upload"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_single_uploaded(f) - - def test_create_with_upload(self): - with self._isolate_repo("single_tool") as f: - create_command = ["shed_create"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - self._verify_single_uploaded(f) - - def test_cannont_recreate(self): - with self._isolate_repo("single_tool"): - create_command = ["shed_create"] - create_command.extend(self._shed_args()) - self._check_exit_code(create_command) - self._check_exit_code(create_command, exit_code=1) - - def test_cannot_upload_missing_include(self): - with self._isolate_repo("bad_missing_include"): - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command, exit_code=254) - - def test_upload_recusrive(self): - with self._isolate_repo("multi_repos_nested") as f: - upload_command = [ - "shed_update", "-r", "--force_repository_creation" - ] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._verify_upload(f, ["cat1.xml", "macros.xml"], ["cat1"]) - self._verify_upload(f, ["cat2.xml", "macros.xml"], ["cat2"]) - - def test_upload_filters_invalid_suite(self): - with self._isolate_repo("suite_1") as f: - # No .shed.yml, make sure to test it can infer type - # from passed in --name. - upload_command = ["shed_upload", "--tar_only", - "--name", "suite_1"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._untar(f, "shed_upload.tar.gz") - # Only one file was in archive - assert_exists(join(target, "repository_dependencies.xml")) - # this got filtered - assert not exists(join(target, "README.rst")) - - def test_upload_suite_auto(self): - with self._isolate_repo("suite_auto") as f: - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._untar(f, "shed_upload.tar.gz") - # Only one file was in archive - assert_exists(join(target, "repository_dependencies.xml")) - - def test_upload_filters_ignore(self): - with self._isolate_repo("single_tool_exclude") as f: - upload_command = ["shed_upload", "--force_repository_creation"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._verify_upload(f) - assert not exists(join(target, "related_file")) - - def test_tar_with_symlinks(self): - with self._isolate_repo("multi_repos_nested") as f: - upload_command = ["shed_upload", "--force_repository_creation"] - upload_command.append("cat2") - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._verify_upload(f, ["macros.xml"], ["cat2"]) - with open(join(target, "macros.xml"), "r") as macro_f: - macro_contents = macro_f.read() - assert macro_contents.startswith("") - - def test_upload_filters_git(self): - with self._isolate_repo("single_tool") as f: - mock_git_dir = join(f, ".git") - os.makedirs(mock_git_dir) - index_path = join(mock_git_dir, "index_file") - with open(index_path, "w") as index_f: - index_f.write("test") - with open(join(f, "related_file~"), "w") as tilde_f: - tilde_f.write("backup!") - upload_command = ["shed_upload", "--force_repository_creation"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._verify_upload(f) - assert not exists(join(target, ".git")) - assert not exists(join(target, "related_file~")) - - def test_upload_filters_invalid_package(self): - with self._isolate_repo("package_1") as f: - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._untar(f, "shed_upload.tar.gz") - # Only one file was in archive - assert_exists(join(target, "tool_dependencies.xml")) - # this got filtered - assert not exists(join(target, "README.rst")) - # .shed.yml always gets filtered - assert not exists(join(target, ".shed.yml")) - - def test_upload_not_filters_unrestricted(self): - with self._isolate_repo("workflow_1") as f: - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - target = self._untar(f, "shed_upload.tar.gz") - # Only one file was in archive - assert_exists(join(target, "repository_dependencies.xml")) - assert_exists(join(target, "README.rst")) - - def test_upload_expansion_configured(self): - with self._isolate_repo("multi_repos_flat_configured") as f: - self._verify_expansion(f) - - def test_upload_expansion_flagged(self): - with self._isolate_repo("multi_repos_flat_flag") as f: - self._verify_expansion(f) - - def test_upload_expansion_configured_extras(self): - with self._isolate() as f: - repo = join(f, "repo") - self._copy_repo("multi_repos_flat_configured_complex", repo) - self._copy_repo("shared_files", join(f, "shared_files")) - self._verify_expansion(f, "repo") - for tool_id in ["cat1", "cat2"]: - self._check_tar( - f, "shed_upload_cs_%s.tar.gz" % tool_id, - contains=[ - "CITATION.txt", - "test-data/extra_test_file.txt", - ], - ) - - def test_upload_expansion_suite(self): - with self._isolate_repo("multi_repos_flat_flag_suite") as f: - self._verify_expansion(f) - target = self._check_tar( - f, "shed_upload_suite_cat.tar.gz", - contains=[ - "repository_dependencies.xml", - ], - not_contains=["macros.xml"] - ) - with open(join(target, "repository_dependencies.xml")) as f: - repo_xml = f.read() - assert 'owner="devteam" name="cat_legacy"' in repo_xml - assert 'owner="iuc" name="cs-cat2"' in repo_xml - - def test_upload_with_double_dot(self): - with self._isolate() as f: - self._copy_repo("up_root/", join(f, "up_root/")) - self._copy_repo("shared_files/", join(f, "shared_files/")) - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - self._check_exit_code(upload_command) - self._check_tar( - f, "shed_upload.tar.gz", - contains=[ - "up_root/README.rst", - "up_root/cat.xml", - "shared_files/extra_test_data/extra_test_file.txt", - ], - not_contains=[]) - - def _assert_shed_diff(self, diff=1): - shed_diff_command = ["shed_diff"] - shed_diff_command.extend(self._shed_args()) - self._check_exit_code(shed_diff_command, exit_code=diff) - - def _verify_expansion(self, f, name=None): - upload_command = ["shed_upload", "--tar_only"] - upload_command.extend(self._shed_args()) - if name is not None: - upload_command.append(join(f, name)) - self._check_exit_code(upload_command) - self._check_tar( - f, "shed_upload_cs_cat1.tar.gz", - contains=[ - "cat1.xml", - "macros.xml", - "test-data/1.bed" - ], - not_contains=["cat2.xml"] - ) - self._check_tar( - f, "shed_upload_cs_cat2.tar.gz", - contains=[ - "cat2.xml", - "macros.xml", - "test-data/1.bed" - ], - not_contains=["cat1.xml"] - ) - - def _verify_single_uploaded(self, f, download_args=[]): - self._verify_upload( - f, ["cat.xml", "related_file", "test-data/1.bed"], download_args - ) - - def _verify_empty_repository(self, f, download_args=[]): - target = self._download_repo(f, download_args) - assert len(os.listdir(target)) == 0 - - def _verify_upload(self, f, download_files=[], download_args=[]): - target = self._download_repo(f, download_args) - for download_file in download_files: - assert_exists(join(target, download_file)) - return target - - def _check_tar(self, f, tar_path, contains=[], not_contains=[]): - tar_path = join(f, tar_path) - assert_exists(tar_path) - target = self._untar(f, tar_path) - for path in contains: - assert_exists(join(target, path)) - for path in not_contains: - assert not exists(join(target, path)) - return target - - def _download_repo(self, f, download_args=[]): - download_command = ["shed_download"] - download_command.extend(download_args) - download_command.extend(self._shed_args(read_only=True)) - self._check_exit_code(download_command) - download = join(f, "shed_download.tar.gz") - assert_exists(download) - return self._untar(f, "shed_download.tar.gz", tarbomb=False) - - def _untar(self, f, path, tarbomb=True): - target = join(f, "download") - if exists(target): - shutil.rmtree(target) - os.makedirs(target) - try: - tar = tarfile.open(path, "r:gz") - except tarfile.ReadError as e: - # Fixed in later version of Python, see - # http://bugs.python.org/issue6123 - assert unicodify(e) == "empty header", e - return target # note contained no files! - tar.extractall(path=target) - tar.close() - tar = tarfile.open(path, "r:gz") - for tar_info in tar.getmembers(): - # These entries cause problems with TS. - assert tar_info.name != "." - assert tar_info.name != "" - tar.close() - if not tarbomb: - return os.path.join(target, os.listdir(target)[0]) - else: - return target - - -def update_package_1(f): - """Update tool dependencies file for package_1.""" - changed_xml = join( - TEST_REPOS_DIR, - "package_1_changed", - "tool_dependencies.xml" - ) - shutil.copyfile(changed_xml, join(f, "tool_dependencies.xml")) diff --git a/tests/test_test_checker.py b/tests/test_test_checker.py deleted file mode 100644 index adc8ab69c..000000000 --- a/tests/test_test_checker.py +++ /dev/null @@ -1,88 +0,0 @@ -"""Unit tests for runnable test case checking and related functionality.""" -import os - -from planemo.runnable import ( - cases, - for_path, - SuccessfulRunResponse -) -from .test_utils import TEST_DATA_DIR - - -def test_non_file_case_checker(): - """Verify simply usage of :func:`planemo.runnable.TestCase.check`.""" - int_tool_path = os.path.join(TEST_DATA_DIR, "int_tool.cwl") - test_cases = cases(for_path(int_tool_path)) - assert len(test_cases) == 1 - test_case = test_cases[0] - outputs_dict = { - "output": 4, - } - - sd = test_case.structured_test_data(MockRunResponse(outputs_dict)) - assert sd["data"]["status"] == "success" - - bad_outputs_dict = { - "output": 5, - } - sd = test_case.structured_test_data(MockRunResponse(bad_outputs_dict)) - assert sd["data"]["status"] == "failure" - - -def test_file_case_checker(): - hello_txt_path = os.path.join(TEST_DATA_DIR, "hello.txt") - int_tool_path = os.path.join(TEST_DATA_DIR, "cat_tool.cwl") - test_cases = cases(for_path(int_tool_path)) - assert len(test_cases) == 1 - test_case = test_cases[0] - outputs_dict = { - "output_file": { - "path": hello_txt_path, - } - } - - sd = test_case.structured_test_data(MockRunResponse(outputs_dict)) - assert sd["data"]["status"] == "success" - - not_hello_txt_path = os.path.join(TEST_DATA_DIR, "int_tool_job.json") - bad_outputs_dict = { - "output_file": { - "path": not_hello_txt_path, - } - } - sd = test_case.structured_test_data(MockRunResponse(bad_outputs_dict)) - assert sd["data"]["status"] == "failure" - - -class MockRunResponse(SuccessfulRunResponse): - start_datetime = None - end_datetime = None - - def __init__(self, outputs_dict): - self._outputs_dict = outputs_dict - - @property - def log(self): - return "My Log" - - @property - def job_info(self): - return { - "command_line": "cat /tmp/1.txt > /tmp/2.out", - "stdout": "Cat output", - "stderr": "Cat problems..." - } - - @property - def outputs_dict(self): - return self._outputs_dict - - @property - def invocation_details(self): - return None - - -__all__ = ( - "test_non_file_case_checker", - "test_file_case_checker", -) diff --git a/tests/test_test_engines.py b/tests/test_test_engines.py deleted file mode 100644 index 8512a8069..000000000 --- a/tests/test_test_engines.py +++ /dev/null @@ -1,208 +0,0 @@ -import json -import os -from tempfile import NamedTemporaryFile - -from planemo.engine.test import ( - test_runnables as t_runnables -) -from planemo.runnable import ( - for_paths, -) -from .test_utils import ( - mark, - PROJECT_TEMPLATES_DIR, - skip_if_environ, - skip_unless_module, - target_galaxy_branch, - test_context as t_context, - TEST_DATA_DIR, -) - - -@skip_if_environ("PLANEMO_SKIP_CWLTOOL_TESTS") -@skip_unless_module("toil") -def test_toil_tests(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "int_tool.cwl") - runnables = for_paths([test_artifact]) - exit_code = t_runnables( - ctx, - runnables, - engine="toil", - ) - assert exit_code == 0 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_wf_tests(): - ctx = t_context() - random_lines = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "randomlines.xml") - cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml") - test_artifact = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": target_galaxy_branch(), - "extra_tools": [random_lines, cat] - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 0 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_workflow_collection_output(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf7-collection-output.gxwf.yml") - collection_creates_pair = os.path.join(TEST_DATA_DIR, "collection_creates_pair_2.xml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": target_galaxy_branch(), - "extra_tools": [collection_creates_pair], - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 0 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_workflow_collection_output_fail(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf7-collection-output-fail.gxwf.yml") - collection_creates_pair = os.path.join(TEST_DATA_DIR, "collection_creates_pair_2.xml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": target_galaxy_branch(), - "extra_tools": [collection_creates_pair], - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 1 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -# @mark.tests_galaxy_branch only works >= 20.09 or newer -def test_galaxy_workflow_tags(): - with NamedTemporaryFile(prefix="data_manager_test_json") as json_out: - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf10-tags-and-rules.gxwf.yml") - collection_cat_list = os.path.join(TEST_DATA_DIR, "cat_list.xml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": "dev", - "extra_tools": [collection_cat_list], - "test_output_json": json_out.name, - } - try: - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 0 - except Exception: - with open(json_out.name, "r") as f: - print(f.read()) - raise - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_workflow_nested_collection_inputs(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf8-collection-nested-input.gxwf.yml") - collection_cat_pair = os.path.join(TEST_DATA_DIR, "cat_pair.xml") - collection_cat_list = os.path.join(TEST_DATA_DIR, "cat_list.xml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": target_galaxy_branch(), - "extra_tools": [collection_cat_pair, collection_cat_list], - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 0 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_workflow_non_data_inputs(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf9-int-input.gxwf.yml") - runnables = for_paths([test_artifact]) - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "galaxy_branch": target_galaxy_branch(), - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 0 - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -@mark.tests_galaxy_branch -def test_galaxy_workflow_step_failed(): - ctx = t_context() - test_artifact = os.path.join(TEST_DATA_DIR, "wf_failed_step.ga") - runnables = for_paths([test_artifact]) - with NamedTemporaryFile(prefix="result_json") as json_out: - kwds = { - "engine": "galaxy", - "no_dependency_resolution": True, - "paste_test_data_paths": False, - "extra_tools": ['$GALAXY_FUNCTIONAL_TEST_TOOLS'], - "test_output_json": json_out.name, - "galaxy_branch": target_galaxy_branch(), - } - exit_code = t_runnables( - ctx, - runnables, - **kwds - ) - assert exit_code == 1 - report = json.load(json_out) - data = report['tests'][0]['data'] - assert data['status'] == 'error' - assert data['execution_problem'] - invocation_steps = data['invocation_details']['steps'] - assert len(invocation_steps) == 2 - first_step, second_step = invocation_steps.values() - assert first_step['state'] == 'scheduled' - job = first_step['jobs'][0] - assert job['exit_code'] == 127 - assert job['state'] == 'error' - assert second_step['state'] == 'scheduled' - assert second_step['jobs'][0]['state'] == 'paused' diff --git a/tests/test_training.py b/tests/test_training.py deleted file mode 100644 index cc192cd76..000000000 --- a/tests/test_training.py +++ /dev/null @@ -1,261 +0,0 @@ -"""Training training functions.""" -import json -import os -import shutil - -from planemo import cli -from planemo.runnable import for_path -from planemo.training import Training -from .test_utils import ( - assert_raises_regexp, - skip_if_environ, - TEST_DATA_DIR, -) - - -datatype_fp = os.path.join(TEST_DATA_DIR, "training_datatypes.yaml") -tuto_fp = os.path.join(TEST_DATA_DIR, "training_tutorial.md") -tuto_wo_zenodo_fp = os.path.join(TEST_DATA_DIR, "training_tutorial_wo_zenodo.md") -zenodo_link = 'https://zenodo.org/record/1321885' -# load a workflow generated from Galaxy -WF_FP = os.path.join(TEST_DATA_DIR, "training_workflow.ga") -with open(WF_FP, "r") as wf_f: - wf = json.load(wf_f) -# load wf_param_values (output of tutorial.get_wf_param_values on wf['steps']['4']) -with open(os.path.join(TEST_DATA_DIR, "training_wf_param_values.json"), "r") as wf_param_values_f: - wf_param_values = json.load(wf_param_values_f) -# configuration -RUNNABLE = for_path(WF_FP) -CTX = cli.PlanemoCliContext() -CTX.planemo_directory = "/tmp/planemo-test-workspace" -KWDS = { - 'topic_name': 'my_new_topic', - 'topic_title': "New topic", - 'topic_target': "use", - 'topic_summary': "Topic summary", - 'tutorial_name': "new_tuto", - 'tutorial_title': "Title of tuto", - 'hands_on': True, - 'slides': True, - 'workflow': None, - 'workflow_id': None, - 'zenodo_link': None, - 'datatypes': os.path.join(TEST_DATA_DIR, "training_datatypes.yaml"), - 'templates': None, - # planemo configuation - 'conda_auto_init': True, - 'conda_auto_install': True, - 'conda_copy_dependencies': False, - 'conda_debug': False, - 'conda_dependency_resolution': False, - 'conda_ensure_channels': 'iuc,conda-forge,bioconda,defaults', - 'conda_exec': None, - 'conda_prefix': None, - 'conda_use_local': False, - 'brew_dependency_resolution': False, - 'daemon': False, - 'database_connection': None, - 'database_type': 'auto', - 'dependency_resolvers_config_file': None, - 'docker': False, - 'docker_cmd': 'docker', - 'docker_extra_volume': None, - 'docker_galaxy_image': 'quay.io/bgruening/galaxy', - 'docker_host': None, - 'docker_sudo': False, - 'docker_sudo_cmd': 'sudo', - 'engine': 'galaxy', - 'extra_tools': (), - 'file_path': None, - 'galaxy_api_key': None, - 'galaxy_branch': None, - 'galaxy_email': 'planemo@galaxyproject.org', - 'galaxy_root': None, - 'galaxy_single_user': True, - 'galaxy_source': None, - 'galaxy_url': None, - 'host': '127.0.0.1', - 'ignore_dependency_problems': False, - 'install_galaxy': False, - 'job_config_file': None, - 'mulled_containers': False, - 'no_cleanup': False, - 'no_cache_galaxy': False, - 'no_dependency_resolution': True, - 'non_strict_cwl': False, - 'pid_file': None, - 'port': '9090', - 'postgres_database_host': None, - 'postgres_database_port': None, - 'postgres_database_user': 'postgres', - 'postgres_psql_path': 'psql', - 'profile': None, - 'shed_dependency_resolution': False, - 'shed_install': True, - 'shed_tool_conf': None, - 'shed_tool_path': None, - 'skip_client_build': True, - 'skip_venv': False, - 'test_data': None, - 'tool_data_table': None, - 'tool_dependency_dir': None -} - - -def test_training_init(): - """Test :func:`planemo.training.Training.init`.""" - train = Training(KWDS) - assert train.topics_dir == "topics" - assert train.topic is not None - assert train.tuto is None - - -def test_training_init_training(): - """Test :func:`planemo.training.Training.init_training`.""" - train = Training(KWDS) - # new topic, nothing else - train.kwds['tutorial_name'] = None - train.kwds['slides'] = None - train.kwds['workflow'] = None - train.kwds['workflow_id'] = None - train.kwds['zenodo_link'] = None - train.init_training(CTX) - assert os.path.exists(train.topic.dir) - assert not os.listdir(os.path.join(train.topic.dir, 'tutorials')) - # no new topic, no tutorial name but hands-on - train.kwds['slides'] = True - exp_exception = "A tutorial name is needed to create the skeleton of a tutorial slide deck" - with assert_raises_regexp(Exception, exp_exception): - train.init_training(CTX) - # no new topic, no tutorial name but workflow - train.kwds['workflow'] = WF_FP - train.kwds['slides'] = False - exp_exception = "A tutorial name is needed to create the skeleton of the tutorial from a workflow" - with assert_raises_regexp(Exception, exp_exception): - train.init_training(CTX) - # no new topic, no tutorial name but zenodo - train.kwds['workflow'] = None - train.kwds['zenodo_link'] = zenodo_link - exp_exception = "A tutorial name is needed to add Zenodo information" - with assert_raises_regexp(Exception, exp_exception): - train.init_training(CTX) - # no new topic, new tutorial - train.kwds['tutorial_name'] = "new_tuto" - train.kwds['workflow'] = None - train.kwds['zenodo_link'] = None - train.init_training(CTX) - assert os.path.exists(train.tuto.dir) - assert os.path.exists(train.tuto.tuto_fp) - with open(train.tuto.tuto_fp, 'r') as fh: - assert train.kwds['tutorial_title'] in fh.read() - # clean after - shutil.rmtree(train.topics_dir) - shutil.rmtree("metadata") - - -def create_existing_tutorial(exit_tuto_name, tuto_fp, topic): - exist_tuto_dir = os.path.join(topic.dir, 'tutorials', exit_tuto_name) - os.makedirs(exist_tuto_dir) - shutil.copyfile(tuto_fp, os.path.join(exist_tuto_dir, 'tutorial.md')) - - -def test_training_check_topic_init_tuto(): - """Test :func:`planemo.training.Training.check_topic_init_tuto`.""" - train = Training(KWDS) - # no topic - exp_exception = "The topic my_new_topic does not exists. It should be created" - with assert_raises_regexp(Exception, exp_exception): - train.check_topic_init_tuto() - # add topic - train.kwds['tutorial_name'] = None - train.kwds['slides'] = None - train.kwds['workflow'] = None - train.kwds['workflow_id'] = None - train.kwds['zenodo_link'] = None - train.init_training(CTX) - train.kwds['tutorial_name'] = 'existing_tutorial' - create_existing_tutorial('existing_tutorial', tuto_fp, train.topic) - train.check_topic_init_tuto() - assert train.tuto.name == train.kwds['tutorial_name'] - assert train.tuto.datatype_fp - # clean after - shutil.rmtree(train.topics_dir) - shutil.rmtree("metadata") - - -def test_fill_data_library(): - """Test :func:`planemo.training.fill_data_library`.""" - train = Training(KWDS) - train.kwds['tutorial_name'] = None - train.kwds['slides'] = False - train.kwds['hands_on'] = False - train.init_training(CTX) - train.kwds['tutorial_name'] = 'existing_tutorial' - create_existing_tutorial('existing_tutorial', tuto_wo_zenodo_fp, train.topic) - # no Zenodo link - train.kwds['zenodo_link'] = None - exp_exception = "A Zenodo link should be provided either in the metadata file or as argument of the command" - with assert_raises_regexp(Exception, exp_exception): - train.fill_data_library(CTX) - # with a given Zenodo link and no Zenodo in metadata - train.kwds['zenodo_link'] = zenodo_link - train.fill_data_library(CTX) - with open(train.tuto.data_lib_fp, 'r') as fh: - assert 'DOI: 10.5281/zenodo.1321885' in fh.read() - with open(train.tuto.tuto_fp, 'r') as fh: - assert 'zenodo_link: %s' % zenodo_link in fh.read() - # with a given Zenodo link and Zenodo in metadata - new_z_link = 'https://zenodo.org/record/1324204' - train.kwds['zenodo_link'] = new_z_link - train.tuto = None - train.fill_data_library(CTX) - with open(train.tuto.data_lib_fp, 'r') as fh: - assert 'DOI: 10.5281/zenodo.1324204' in fh.read() - with open(train.tuto.tuto_fp, 'r') as fh: - assert 'zenodo_link: %s' % new_z_link in fh.read() - # with no given Zenodo link - train.kwds['zenodo_link'] = None - train.fill_data_library(CTX) - with open(train.tuto.data_lib_fp, 'r') as fh: - assert 'DOI: 10.5281/zenodo.1324204' in fh.read() - with open(train.tuto.tuto_fp, 'r') as fh: - assert 'zenodo_link: %s' % new_z_link in fh.read() - # clean after - shutil.rmtree(train.topics_dir) - shutil.rmtree("metadata") - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_generate_tuto_from_wf(): - """Test :func:`planemo.training.generate_tuto_from_wf`.""" - train = Training(KWDS) - train.kwds['tutorial_name'] = None - train.kwds['slides'] = False - train.init_training(CTX) - train.kwds['tutorial_name'] = 'existing_tutorial' - create_existing_tutorial('existing_tutorial', tuto_fp, train.topic) - # no workflow - train.kwds['workflow'] = None - exp_exception = "A path to a local workflow or the id of a workflow on a running Galaxy instance should be provided" - with assert_raises_regexp(Exception, exp_exception): - train.generate_tuto_from_wf(CTX) - # with workflow - train.kwds['workflow'] = WF_FP - train.generate_tuto_from_wf(CTX) - assert_file_contains( - train.tuto.tuto_fp, - "{% tool [FastQC](toolshed.g2.bx.psu.edu/repos/devteam/fastqc/fastqc/0.71) %} with the following parameters:", - ) - assert os.path.exists(train.tuto.wf_fp) - # clean after - shutil.rmtree(train.topics_dir) - shutil.rmtree("metadata") - - -def assert_file_contains(file, text): - with open(file, 'r') as fh: - contents = fh.read() - if text not in contents: - template = "Expected file [%s] to contain [%s], it did not - contents [%s]" - message = template % (file, text, contents) - raise AssertionError(message) diff --git a/tests/test_training_tool_input.py b/tests/test_training_tool_input.py deleted file mode 100644 index aca6d1236..000000000 --- a/tests/test_training_tool_input.py +++ /dev/null @@ -1,289 +0,0 @@ -"""Training:tool_input functions.""" -import json -import os - -from planemo.training.tool_input import ( - get_empty_input, - get_empty_param, - get_input_tool_name, - ToolInput -) -from .test_training import ( - wf, - wf_param_values -) -from .test_utils import ( - assert_raises_regexp, - TEST_DATA_DIR -) - - -wf_steps = wf['steps'] -# load the output from -# gi.tools.show_tool('toolshed.g2.bx.psu.edu/repos/iuc/query_tabular/query_tabular/2.0.0', io_details=True) -with open(os.path.join(TEST_DATA_DIR, "training_query_tabular.json"), "r") as tool_desc_f: - tool_desc = json.load(tool_desc_f) -tool_inp_desc = tool_desc["inputs"] - - -def test_get_input_tool_name(): - """Test :func:`planemo.training.tool_input.get_input_tool_name`.""" - assert "Input dataset" in get_input_tool_name('1', wf_steps) - assert "output of" in get_input_tool_name('4', wf_steps) - assert get_input_tool_name('10', wf_steps) == '' - - -def test_get_empty_input(): - """Test :func:`planemo.training.tool_input.get_empty_input`.""" - assert '{% icon param-file %} *"Input file"*: File' in get_empty_input() - - -def test_get_empty_param(): - """Test :func:`planemo.training.tool_input.get_empty_param`.""" - assert '*"Parameter"*: `a value`' in get_empty_param() - - -def test_ToolInput_init(): - """Test :func:`planemo.training.tool_input.ToolInput.init`.""" - # test type exception - exp_exception = "No type for the parameter t" - with assert_raises_regexp(Exception, exp_exception): - ToolInput( - tool_inp_desc={'name': 't'}, - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - # test with param not in workflow and exception - exp_exception = "t not in workflow" - with assert_raises_regexp(Exception, exp_exception): - ToolInput( - tool_inp_desc={'name': 't', 'type': ''}, - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - # test with param not in workflow but no exception - tool_input = ToolInput( - tool_inp_desc={'name': 't', 'type': ''}, - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - assert "save_db" in tool_input.wf_param_values - # test with param in workflow - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[0], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - assert "save_db" not in tool_input.wf_param_values - assert tool_input.wf_param_values == "workdb.sqlite" - - -def test_ToolInput_get_formatted_inputs(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_inputs`.""" - # test no input - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[1]["inputs"][0], - wf_param_values={}, - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - inputlist = tool_input.get_formatted_inputs() - assert inputlist == '' - # test collection - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[1]["inputs"][0], - wf_param_values=wf_param_values["add_to_database"], - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - inputlist = tool_input.get_formatted_inputs() - assert 'param-collection' in inputlist - assert '(Input dataset collection)' in inputlist - # test single input - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[2]["inputs"][0], - wf_param_values=wf_param_values["tables"][0], - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - inputlist = tool_input.get_formatted_inputs() - assert 'param-file' in inputlist - assert '(Input dataset)' in inputlist - - -def test_ToolInput_get_lower_param_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_lower_param_desc`.""" - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[1], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - sub_param_desc = tool_input.get_lower_param_desc() - assert '> - {% icon param-collection %}' in sub_param_desc - - -def test_ToolInput_get_formatted_section_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_section_desc`.""" - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[1], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - section_paramlist = tool_input.get_formatted_section_desc() - assert '> - In *"' in section_paramlist - assert '> - {%' in section_paramlist - - -def test_ToolInput_get_formatted_conditional_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_conditional_desc`.""" - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[5], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - conditional_paramlist = tool_input.get_formatted_conditional_desc() - assert '> - *"' in conditional_paramlist - assert '"*: `Yes`' in conditional_paramlist - assert '> - *"' in conditional_paramlist - - -def test_ToolInput_get_formatted_repeat_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_repeat_desc`.""" - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[2], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - repeat_desc = tool_input.get_formatted_repeat_desc() - assert '> - In *"' in repeat_desc - assert '> - {% icon param-repeat %} *"Insert' in repeat_desc - assert '> -' in repeat_desc - - -def test_ToolInput_get_formatted_other_param_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_other_param_desc`.""" - # test default value of the tool - tool_input = ToolInput( - tool_inp_desc={'value': 10, 'name': 't', 'type': ''}, - wf_param_values={'t': 10}, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - assert tool_input.get_formatted_other_param_desc() == '' - # test boolean parameter - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[3], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - assert tool_input.get_formatted_other_param_desc() == '' - tool_input.wf_param_values = 'true' - assert '*: `Yes`' in tool_input.get_formatted_other_param_desc() - # test select parameter - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[5]['cases'][0]['inputs'][0], - wf_param_values=wf_param_values['query_result'], - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - assert '*: `&`' in tool_input.get_formatted_other_param_desc() - # test other parameter - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[4], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=True) - assert '*: ``' in tool_input.get_formatted_other_param_desc() - - -def test_ToolInput_get_formatted_desc(): - """Test :func:`planemo.training.tool_input.ToolInput.get_formatted_desc`.""" - # test no param values - tool_input = ToolInput( - tool_inp_desc={'value': 10, 'name': 't', 'type': ''}, - wf_param_values={}, - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - assert tool_input.get_formatted_desc() == '' - # test data - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[2]["inputs"][0], - wf_param_values=wf_param_values["tables"][0], - wf_steps=wf_steps, - level=1, - should_be_there=False, - force_default=False) - inputlist = tool_input.get_formatted_inputs() - formatted_desc = tool_input.get_formatted_desc() - assert inputlist == formatted_desc - # test section - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[1], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - section_paramlist = tool_input.get_formatted_section_desc() - formatted_desc = tool_input.get_formatted_desc() - assert section_paramlist == formatted_desc - # test conditional - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[5], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - conditional_paramlist = tool_input.get_formatted_conditional_desc() - formatted_desc = tool_input.get_formatted_desc() - assert conditional_paramlist == formatted_desc - # test repeat - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[2], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - repeat_desc = tool_input.get_formatted_repeat_desc() - formatted_desc = tool_input.get_formatted_desc() - assert repeat_desc == formatted_desc - # test other - tool_input = ToolInput( - tool_inp_desc=tool_inp_desc[3], - wf_param_values=wf_param_values, - wf_steps=wf_steps, - level=1, - should_be_there=True, - force_default=False) - param_desc = tool_input.get_formatted_other_param_desc() - formatted_desc = tool_input.get_formatted_desc() - assert param_desc == formatted_desc diff --git a/tests/test_training_topic.py b/tests/test_training_topic.py deleted file mode 100644 index 9efa05520..000000000 --- a/tests/test_training_topic.py +++ /dev/null @@ -1,149 +0,0 @@ -"""Training:topic functions.""" -import os -import shutil - -from planemo.training.topic import Topic -from planemo.training.utils import load_yaml -from .test_utils import TEST_DATA_DIR - - -def test_topic_init(): - """Test :func:`planemo.training.topic.Topic.init`.""" - # test requirement with default parameter - topic = Topic() - assert topic.name == "new_topic" - assert topic.type == "use" - assert topic.title == "The new topic" - assert topic.summary == "Summary" - assert topic.docker_image == "" - assert "maintainers" in topic.maintainers - assert topic.parent_dir == "topics" - assert topic.dir == "topics/new_topic" - assert topic.requirements[0].topic_name == "introduction" - # test requirement with non default - topic = Topic(name="topic2", target="admin", title="The 2nd topic", summary="", parent_dir="dir") - assert topic.name == "topic2" - assert topic.type == "admin" - assert topic.title == "The 2nd topic" - assert topic.summary == "" - assert topic.parent_dir == "dir" - assert topic.dir == "dir/topic2" - assert len(topic.requirements) == 0 - - -def test_topic_init_from_kwds(): - """Test :func:`planemo.training.topic.Topic.init_from_kwds`.""" - topic = Topic() - topic.init_from_kwds({ - 'topic_name': "topic", - 'topic_title': "New topic", - 'topic_target': "admin", - 'topic_summary': "Topic summary" - }) - assert topic.name == "topic" - assert topic.type == "admin" - assert topic.title == "New topic" - assert topic.summary == "Topic summary" - assert topic.dir == "topics/topic" - assert len(topic.requirements) == 0 - - -def test_topic_init_from_metadata(): - """Test :func:`planemo.training.topic.Topic.init_from_metadata`.""" - topic = Topic() - os.makedirs(topic.dir) - shutil.copy(os.path.join(TEST_DATA_DIR, 'training_metadata.yaml'), topic.metadata_fp) - topic.init_from_metadata() - assert topic.name == 'test' - assert topic.title == 'Test' - assert topic.summary == 'Summary' - assert topic.requirements[0].topic_name == 'introduction' - assert topic.requirements[0].tutorials == ['peaks2genes'] - assert 'maintainer1' in topic.maintainers - shutil.rmtree(topic.parent_dir) - - -def test_topic_get_requirements(): - """Test :func:`planemo.training.topic.Topic.get_requirements`.""" - topic = Topic() - reqs = topic.get_requirements() - assert len(reqs) == 1 - assert 'topic_name' in reqs[0] - - -def test_topic_export_metadata_to_ordered_dict(): - """Test :func:`planemo.training.topic.Topic.export_metadata_to_ordered_dict`.""" - topic = Topic() - metadata = topic.export_metadata_to_ordered_dict() - assert 'name' in metadata - assert metadata['name'] == "new_topic" - assert 'type' in metadata - assert 'title' in metadata - assert 'summary' in metadata - assert 'requirements' in metadata - assert 'docker_image' in metadata - assert 'maintainers' in metadata - - -def test_topic_set_paths(): - """Test :func:`planemo.training.topic.Topic.set_paths`.""" - new_name = 'the_new_name' - topic = Topic() - topic.name = new_name - topic.set_paths() - assert new_name in topic.dir - assert new_name in topic.img_folder - assert new_name in topic.tuto_folder - assert new_name in topic.index_fp - assert new_name in topic.readme_fp - assert new_name in topic.metadata_fp - assert new_name in topic.docker_folder - assert new_name in topic.dockerfile_fp - assert new_name in topic.slides_folder - - -def test_topic_exists(): - """Test :func:`planemo.training.topic.Topic.exists`.""" - topic = Topic() - os.makedirs(topic.dir) - assert topic.exists() - shutil.rmtree(topic.parent_dir) - - -def test_topic_create_topic_structure(): - """Test :func:`planemo.training.topic.Topic.create_topic_structure`.""" - topic = Topic() - topic.create_topic_structure() - topic_name = "new_topic" - topic_title = "The new topic" - # check the folder and its structure - assert topic.exists() - assert os.path.exists(topic.img_folder) - assert os.path.exists(topic.tuto_folder) - # create the index.md and the topic name - assert os.path.exists(topic.index_fp) - with open(topic.index_fp, 'r') as fh: - assert topic_name in fh.read() - # create the README.md and the topic name - assert os.path.exists(topic.readme_fp) - with open(topic.readme_fp, 'r') as fh: - assert topic_title in fh.read() - # check metadata content - assert os.path.exists(topic.metadata_fp) - metadata = load_yaml(topic.metadata_fp) - assert metadata['name'] == topic_name - # check dockerfile - assert os.path.exists(topic.dockerfile_fp) - with open(topic.dockerfile_fp, 'r') as fh: - assert topic_name in fh.read() - with open(topic.dockerfile_fp, 'r') as fh: - assert topic_title in fh.read() - # check introduction slide - assert os.path.exists(topic.intro_slide_fp) - with open(topic.intro_slide_fp, 'r') as fh: - assert topic_title in fh.read() - # check in metadata directory - assert os.path.exists(os.path.join("metadata", "%s.yaml" % topic_name)) - # clean - shutil.rmtree(topic.parent_dir) - shutil.rmtree("metadata") diff --git a/tests/test_training_tutorial.py b/tests/test_training_tutorial.py deleted file mode 100644 index 60c33475e..000000000 --- a/tests/test_training_tutorial.py +++ /dev/null @@ -1,444 +0,0 @@ -"""Training:tutorial functions.""" -import os -import shutil - -from planemo.engine import ( - engine_context, - is_galaxy_engine, -) -from planemo.training import ( - Training -) -from planemo.training.topic import Topic -from planemo.training.tutorial import ( - get_galaxy_datatype, - get_hands_on_boxes_from_local_galaxy, - get_hands_on_boxes_from_running_galaxy, - get_wf_inputs, - get_wf_param_values, - get_zenodo_record, - Tutorial -) -from planemo.training.utils import save_to_yaml -from .test_training import ( - create_existing_tutorial, - CTX, - datatype_fp, - KWDS, - RUNNABLE, - tuto_fp, - wf, - WF_FP, - wf_param_values, - zenodo_link -) -from .test_utils import ( - assert_raises_regexp, - skip_if_environ, -) - -topic = Topic() -training = Training(KWDS) - - -def test_get_galaxy_datatype(): - """Test :func:`planemo.training.tutorial.get_galaxy_datatype`.""" - assert get_galaxy_datatype("csv", datatype_fp) == "csv" - assert get_galaxy_datatype("test", datatype_fp) == "strange_datatype" - assert "# Please add" in get_galaxy_datatype("unknown", datatype_fp) - - -def test_get_zenodo_record(): - """Test :func:`planemo.training.tutorial.get_zenodo_record`.""" - z_record, req_res = get_zenodo_record(zenodo_link) - file_link_prefix = "https://zenodo.org/api/files/51a1b5db-ff05-4cda-83d4-3b46682f921f" - assert z_record == "1321885" - assert 'files' in req_res - assert req_res['files'][0]['type'] in ['rdata', 'csv'] - assert file_link_prefix in req_res['files'][0]['links']['self'] - # check with wrong zenodo link - z_record, req_res = get_zenodo_record('https://zenodo.org/api/records/zenodooo') - assert z_record is None - assert 'files' in req_res - assert len(req_res['files']) == 0 - # using DOI - z_link = 'https://doi.org/10.5281/zenodo.1321885' - z_record, req_res = get_zenodo_record(z_link) - file_link_prefix = "https://zenodo.org/api/files/51a1b5db-ff05-4cda-83d4-3b46682f921f" - assert z_record == "1321885" - assert 'files' in req_res - assert req_res['files'][0]['type'] in ['rdata', 'csv'] - assert file_link_prefix in req_res['files'][0]['links']['self'] - - -def test_get_wf_inputs(): - """Test :func:`planemo.training.tutorial.get_wf_inputs`.""" - step_inp = { - 'tables_1|table': {'output_name': 'output', 'id': 2}, - 'add_to_database|withdb': {'output_name': 'output', 'id': 0}, - 'tables_0|table': {'output_name': 'output', 'id': 1}, - 'add_to_database|tab_0|tt': {'output_name': 'output', 'id': 0}, - 'tables_2|section|sect': {'output_name': 'output', 'id': 1}, - 'tables_3|tables_0|sect': {'output_name': 'output', 'id': 1} - } - step_inputs = get_wf_inputs(step_inp) - assert 'tables' in step_inputs - assert '0' in step_inputs['tables'] - assert 'table' in step_inputs['tables']['0'] - assert '2' in step_inputs['tables'] - assert 'section' in step_inputs['tables']['2'] - assert 'sect' in step_inputs['tables']['2']['section'] - assert 'output_name' in step_inputs['tables']['2']['section']['sect'] - assert 'add_to_database' in step_inputs - assert 'withdb' in step_inputs['add_to_database'] - assert 'tab' in step_inputs['add_to_database'] - assert '0' in step_inputs['add_to_database']['tab'] - assert 'tt' in step_inputs['add_to_database']['tab']['0'] - - -def test_get_wf_param_values(): - """Test :func:`planemo.training.tutorial.get_wf_param_values`.""" - wf_step = wf['steps']['3'] - wf_param_value_tests = get_wf_param_values(wf_step['tool_state'], get_wf_inputs(wf_step['input_connections'])) - assert isinstance(wf_param_value_tests, dict) - for k in wf_param_values: - assert k in wf_param_value_tests - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_get_hands_on_boxes_from_local_galaxy(): - """Test :func:`planemo.training.tutorial.get_hands_on_boxes_from_local_galaxy`.""" - tuto_body = get_hands_on_boxes_from_local_galaxy(KWDS, WF_FP, CTX) - assert_body_contains(tuto_body, '## Sub-step with **FastQC**') - assert_body_contains(tuto_body, '## Sub-step with **Query Tabular**') - assert_body_contains(tuto_body, '## Sub-step with **Select first**') - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_get_hands_on_boxes_from_running_galaxy(): - """Test :func:`planemo.training.tutorial.get_hands_on_boxes_from_running_galaxy`.""" - assert is_galaxy_engine(**KWDS) - galaxy_url = 'http://%s:%s' % (KWDS['host'], KWDS['port']) - with engine_context(CTX, **KWDS) as galaxy_engine: - with galaxy_engine.ensure_runnables_served([RUNNABLE]) as config: - wf_id = config.workflow_id(WF_FP) - tuto_body = get_hands_on_boxes_from_running_galaxy(wf_id, galaxy_url, config.user_api_key) - - assert_body_contains(tuto_body, '## Sub-step with **FastQC**') - assert_body_contains(tuto_body, '## Sub-step with **Query Tabular**') - assert_body_contains(tuto_body, '## Sub-step with **Select first**') - - -def test_tutorial_init(): - """Test :func:`planemo.training.tutorial.tutorial.init`.""" - # with default parameter - tuto = Tutorial( - training=training, - topic=topic) - assert tuto.name == "new_tuto" - assert tuto.title == "The new tutorial" - assert tuto.zenodo_link == "" - assert tuto.hands_on - assert not tuto.slides - assert tuto.init_wf_id is None - assert tuto.init_wf_fp is None - assert tuto.datatype_fp == '' - assert "new_tuto" in tuto.dir - assert '## Sub-step with **My Tool**' in tuto.body - assert tuto.data_lib - # with non default parameter - tuto = Tutorial( - training=training, - topic=topic, - name="my_tuto", - title="The tutorial", - zenodo_link="URL") - assert tuto.name == "my_tuto" - assert tuto.title == "The tutorial" - assert tuto.zenodo_link == "URL" - assert "my_tuto" in tuto.dir - - -def test_tutorial_init_from_kwds(): - """Test :func:`planemo.training.tutorial.tutorial.init_from_kwds`.""" - kwds = { - 'tutorial_name': "my_tuto", - 'tutorial_title': "Title of tuto", - 'hands_on': True, - 'slides': True, - 'workflow': WF_FP, - 'workflow_id': 'id', - 'zenodo_link': None, - 'datatypes': datatype_fp - } - tuto = Tutorial( - training=training, - topic=topic) - tuto.init_from_kwds(kwds) - assert tuto.name == "my_tuto" - assert tuto.title == "Title of tuto" - assert tuto.zenodo_link == '' - assert "Which biological questions are addressed by the tutorial?" in tuto.questions - assert tuto.hands_on - assert tuto.slides - assert tuto.init_wf_id == 'id' - assert tuto.init_wf_fp == WF_FP - assert tuto.datatype_fp == datatype_fp - assert "my_tuto" in tuto.dir - - -def test_tutorial_init_from_existing_tutorial(): - """Test :func:`planemo.training.tutorial.tutorial.init_from_existing_tutorial`.""" - tuto = Tutorial( - training=training, - topic=topic) - # non existing tutorial - exp_exception = "The tutorial existing_tutorial does not exists. It should be created" - with assert_raises_regexp(Exception, exp_exception): - tuto.init_from_existing_tutorial('existing_tutorial') - # existing tutorial - create_existing_tutorial('existing_tutorial', tuto_fp, tuto.topic) - tuto.init_from_existing_tutorial('existing_tutorial') - assert tuto.title == 'A tutorial to test' - assert "A learning objective" in tuto.objectives - assert tuto.time_estimation == "1H" - assert 'the_best_contributor' in tuto.contributors - assert '# First section' in tuto.body - shutil.rmtree("topics") - - -def test_tutorial_init_data_lib(): - """Test :func:`planemo.training.tutorial.tutorial.init_data_lib`.""" - tuto = Tutorial( - training=training, - topic=topic) - tuto.init_data_lib() - assert tuto.data_lib['destination']['type'] == 'library' - assert tuto.data_lib['items'][0]['name'] == topic.title - assert tuto.data_lib['items'][0]['items'][0]['name'] == tuto.title - # from existing data library file - os.makedirs(tuto.dir) - tuto.data_lib = {} - tuto.init_data_lib() - assert tuto.data_lib['items'][0]['name'] == topic.title - assert tuto.data_lib['items'][0]['items'][0]['name'] == tuto.title - # other tutorial already there and add the new one - tuto.data_lib['items'][0]['items'][0]['name'] = 'Different tutorial' - save_to_yaml(tuto.data_lib, tuto.data_lib_fp) - tuto.init_data_lib() - assert tuto.data_lib['items'][0]['items'][0]['name'] == 'Different tutorial' - assert tuto.data_lib['items'][0]['items'][1]['name'] == tuto.title - shutil.rmtree("topics") - - -def test_tutorial_get_tuto_metata(): - """Test :func:`planemo.training.tutorial.tutorial.get_tuto_metata`.""" - tuto = Tutorial( - training=training, - topic=topic) - tuto.questions = ['q1', 'q2'] - metadata = tuto.get_tuto_metata() - assert 'title: The new tutorial' in metadata - assert '- q1' in metadata - - -def test_tutorial_set_dir_name(): - """Test :func:`planemo.training.tutorial.tutorial.set_dir_name`.""" - tuto = Tutorial( - training=training, - topic=topic) - tuto.name = "the_tuto" - tuto.set_dir_name() - assert tuto.name in tuto.dir - assert tuto.name in tuto.tuto_fp - assert tuto.name in tuto.slide_fp - assert tuto.name in tuto.data_lib_fp - assert tuto.name in tuto.wf_dir - assert tuto.name in tuto.wf_fp - - -def test_tutorial_exists(): - """Test :func:`planemo.training.tutorial.tutorial.exists`.""" - # default - tuto = Tutorial( - training=training, - topic=topic) - assert not tuto.exists() - # after dir creation - os.makedirs(tuto.dir) - assert tuto.exists() - shutil.rmtree("topics") - - -def test_tutorial_has_workflow(): - """Test :func:`planemo.training.tutorial.tutorial.has_workflow`.""" - # default - tuto = Tutorial( - training=training, - topic=topic) - assert not tuto.has_workflow() - # with wf filepath - tuto.init_wf_fp = WF_FP - assert tuto.has_workflow() - # with no wf filepah nor wf id - tuto.init_wf_fp = None - tuto.init_wf_id = '' - assert not tuto.has_workflow() - # with wf id - tuto.init_wf_id = 'ID' - assert tuto.has_workflow() - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_tutorial_export_workflow_file(): - """Test :func:`planemo.training.tutorial.tutorial.export_workflow_file`.""" - tuto = Tutorial( - training=training, - topic=topic) - os.makedirs(tuto.wf_dir) - # with worflow fp - tuto.init_wf_fp = WF_FP - tuto.export_workflow_file() - assert os.path.exists(tuto.wf_fp) - # with workflow id - tuto.init_wf_fp = None - os.remove(tuto.wf_fp) - assert is_galaxy_engine(**KWDS) - galaxy_url = 'http://%s:%s' % (KWDS['host'], KWDS['port']) - with engine_context(CTX, **KWDS) as galaxy_engine: - with galaxy_engine.ensure_runnables_served([RUNNABLE]) as config: - tuto.init_wf_id = config.workflow_id(WF_FP) - tuto.training.galaxy_url = galaxy_url - tuto.training.galaxy_api_key = config.user_api_key - tuto.export_workflow_file() - assert os.path.exists(tuto.wf_fp) - shutil.rmtree("topics") - - -def test_tutorial_get_files_from_zenodo(): - """Test :func:`planemo.training.tutorial.tutorial.get_files_from_zenodo`.""" - tuto = Tutorial( - training=training, - topic=topic, - zenodo_link=zenodo_link) - tuto.datatype_fp = datatype_fp - files, z_record = tuto.get_files_from_zenodo() - assert z_record == "1321885" - # test links - file_link_prefix = "https://zenodo.org/api/files/51a1b5db-ff05-4cda-83d4-3b46682f921f" - assert file_link_prefix in tuto.zenodo_file_links[0] - # test files dict - assert file_link_prefix in files[0]['url'] - assert files[0]['src'] == 'url' - assert files[0]['info'] == zenodo_link - assert "# Please add" in files[0]['ext'] - assert files[1]['ext'] == 'csv' - - -def test_tutorial_prepare_data_library_from_zenodo(): - """Test :func:`planemo.training.tutorial.tutorial.prepare_data_library_from_zenodo`.""" - # without zenodo link - tuto = Tutorial( - training=training, - topic=topic) - tuto.datatype_fp = datatype_fp - os.makedirs(tuto.wf_dir) - tuto.prepare_data_library_from_zenodo() - assert os.path.exists(tuto.data_lib_fp) - with open(tuto.data_lib_fp, 'r') as fh: - assert 'DOI' not in fh.read() - # with zenodo link - tuto.zenodo_link = zenodo_link - tuto.prepare_data_library_from_zenodo() - with open(tuto.data_lib_fp, 'r') as fh: - assert "DOI: 10.5281/zenodo" in fh.read() - shutil.rmtree("topics") - - -def test_tutorial_write_hands_on_tutorial(): - """Test :func:`planemo.training.tutorial.tutorial.write_hands_on_tutorial`.""" - tuto = Tutorial( - training=training, - topic=topic) - os.makedirs(tuto.wf_dir) - tuto.zenodo_file_links = ["URL1", "URL2"] - tuto.write_hands_on_tutorial() - assert os.path.exists(tuto.tuto_fp) - with open(tuto.tuto_fp, 'r') as tuto_f: - tuto_c = tuto_f.read() - assert 'layout: tutorial_hands_on' in tuto_c - assert '# Introduction' in tuto_c - assert 'URL1' in tuto_c - assert '# Conclusion' in tuto_c - shutil.rmtree("topics") - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_tutorial_create_hands_on_tutorial(): - """Test :func:`planemo.training.tutorial.tutorial.create_hands_on_tutorial`.""" - tuto = Tutorial( - training=training, - topic=topic) - os.makedirs(tuto.wf_dir) - # with init_wf_id and no Galaxy URL - tuto.init_wf_id = 'ID' - tuto.training.galaxy_url = None - exp_exception = "No Galaxy URL given" - with assert_raises_regexp(Exception, exp_exception): - tuto.create_hands_on_tutorial(CTX) - # with init_wf_id and no Galaxy API key - tuto.init_wf_id = 'ID' - tuto.training.galaxy_url = 'http://%s:%s' % (KWDS['host'], KWDS['port']) - tuto.training.galaxy_api_key = None - exp_exception = "No API key to access the given Galaxy instance" - with assert_raises_regexp(Exception, exp_exception): - tuto.create_hands_on_tutorial(CTX) - # with init_wf_id - assert is_galaxy_engine(**KWDS) - with engine_context(CTX, **KWDS) as galaxy_engine: - with galaxy_engine.ensure_runnables_served([RUNNABLE]) as config: - tuto.init_wf_id = config.workflow_id(WF_FP) - tuto.training.galaxy_api_key = config.user_api_key - tuto.create_hands_on_tutorial(CTX) - assert os.path.exists(tuto.tuto_fp) - os.remove(tuto.tuto_fp) - # with init_wf_fp - tuto.init_wf_id = None - tuto.init_wf_fp = WF_FP - tuto.create_hands_on_tutorial(CTX) - assert os.path.exists(tuto.tuto_fp) - shutil.rmtree("topics") - - -@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS") -def test_tutorial_create_tutorial(): - """Test :func:`planemo.training.tutorial.tutorial.create_tutorial`.""" - tuto = Tutorial( - training=training, - topic=topic) - tuto.init_from_kwds({ - 'tutorial_name': "my_tuto", - 'tutorial_title': "Title of tuto", - 'hands_on': True, - 'slides': True, - 'workflow': WF_FP, - 'workflow_id': None, - 'zenodo_link': zenodo_link, - 'datatypes': datatype_fp - }) - tuto.create_tutorial(CTX) - assert os.path.exists(tuto.dir) - assert os.path.exists(tuto.tour_dir) - assert os.path.exists(tuto.wf_dir) - assert os.path.exists(tuto.data_lib_fp) - assert os.path.exists(tuto.tuto_fp) - assert os.path.exists(tuto.slide_fp) - with open(tuto.slide_fp, 'r') as fh: - assert 'layout: tutorial_slides' in fh.read() - shutil.rmtree("topics") - - -def assert_body_contains(body, contents): - if contents not in body: - message = "Expected to find contents [%s] in body [%s]" % (contents, body) - raise AssertionError(message) diff --git a/tests/test_validation.py b/tests/test_validation.py deleted file mode 100644 index ae13e1fe5..000000000 --- a/tests/test_validation.py +++ /dev/null @@ -1,67 +0,0 @@ -import os - -from galaxy.util import unicodify - -from planemo import shed_lint -from planemo.xml import validation -from .test_utils import ( - skip_unless_executable, - skip_unless_module, - TEST_DIR, -) - - -@skip_unless_module("lxml") -def test_lxml_validation(): - lxml_xsd_validator = validation.LxmlValidator() - _check_validator(lxml_xsd_validator) - - -@skip_unless_executable("xmllint") -def test_xmllint_validation(): - xmllint_xsd_validator = validation.XmllintValidator() - _check_validator(xmllint_xsd_validator) - - -def test_tool_dependencies_validation(): - _assert_validates(shed_lint.TOOL_DEPENDENCIES_XSD, - _path("tool_dependencies_good_1.xml")) - _assert_validates(shed_lint.TOOL_DEPENDENCIES_XSD, - _path("tool_dependencies_good_2.xml")) - - -def test_repository_dependencies_validation(): - _assert_validates(shed_lint.REPO_DEPENDENCIES_XSD, - _path("repository_dependencies.xml")) - - -def _check_validator(xsd_validator): - _assert_validates( - _path("xsd_schema_1.xsd"), - _path("xml_good_1.xml"), - xsd_validator, - ) - _assert_validates( - _path("xsd_schema_1.xsd"), - _path("xml_good_2.xml"), - xsd_validator, - ) - - result = xsd_validator.validate(_path("xsd_schema_1.xsd"), - _path("xml_bad_1.xml")) - assert not result.passed - output = unicodify(result.output) - assert "not_command" in output, output - - -def _assert_validates(schema, target, xsd_validator=None): - if xsd_validator is None: - xsd_validator = validation.get_validator() - result = xsd_validator.validate(schema, - target) - assert result.passed, result.output - - -def _path(filename): - # TODO: move all test data into tests/data - return os.path.join(TEST_DIR, filename) diff --git a/tests/test_workflow_lint.py b/tests/test_workflow_lint.py deleted file mode 100644 index bed860178..000000000 --- a/tests/test_workflow_lint.py +++ /dev/null @@ -1,20 +0,0 @@ -import os - -from planemo.workflow_lint import input_labels -from .test_utils import ( - TEST_DATA_DIR, -) - - -def test_input_labels(): - wf_example_1 = os.path.join(TEST_DATA_DIR, "wf_repos", "basic_format2_ok", "basic_format2.gxwf.yml") - labels = input_labels(wf_example_1) - assert "the_input" in labels - # verify non-input labels excluded - assert "cat" not in labels - - wf_example_1 = os.path.join(TEST_DATA_DIR, "wf_repos", "basic_native_ok", "basic_native.yml") - labels = input_labels(wf_example_1) - assert "the_input" in labels - # verify non-input labels excluded - assert "cat" not in labels diff --git a/tests/test_xml_diff.py b/tests/test_xml_diff.py deleted file mode 100644 index 8b3549746..000000000 --- a/tests/test_xml_diff.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -import sys -from xml.etree import ElementTree - -from planemo.xml.diff import diff -from .test_utils import TEST_DIR - - -def test_diff(): - # Check with and without reporter. - _check(sys.stdout.write) - _check(None) - - -def _check(reporter): - assert not diff(ElementTree.fromstring("cow"), - ElementTree.fromstring("cow"), - reporter) - assert diff(ElementTree.fromstring("cow"), - ElementTree.fromstring("cow1"), - reporter) - assert diff(ElementTree.fromstring(""), - ElementTree.fromstring(""), - reporter) - assert diff(ElementTree.fromstring(""), - ElementTree.fromstring("a"), - reporter) - assert diff(ElementTree.fromstring("*"), - ElementTree.fromstring("*a"), - reporter) - assert not diff(_root("repository_dependencies.xml"), - _root("repository_dependencies.xml"), - reporter) - assert not diff(_root("repository_dependencies_shed.xml"), - _root("repository_dependencies_shed.xml"), - reporter) - assert diff(_root("repository_dependencies.xml"), - _root("repository_dependencies_shed.xml"), - reporter) - assert diff(_root("repository_dependencies.xml"), - _root("tool_dependencies_good_1.xml"), - reporter) - assert diff(_root("tool_dependencies_good_1.xml"), - _root("tool_dependencies_good_2.xml"), - reporter) - - -def _root(*args): - return ElementTree.parse(os.path.join(TEST_DIR, *args)).getroot()