From e3aa926f98a3640e5bec02f42586769e646bb196 Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Wed, 7 Jul 2021 10:43:33 +0200 Subject: [PATCH 1/4] Moved module tests into seperate files --- tests/modules/__init__.py | 0 tests/modules/bump_versions.py | 49 ++++++ tests/modules/create.py | 42 +++++ tests/modules/create_test_yml.py | 59 +++++++ tests/modules/install.py | 42 +++++ tests/modules/lint.py | 31 ++++ tests/modules/list.py | 34 ++++ tests/modules/remove.py | 22 +++ tests/test_modules.py | 287 ++++++------------------------- 9 files changed, 327 insertions(+), 239 deletions(-) create mode 100644 tests/modules/__init__.py create mode 100644 tests/modules/bump_versions.py create mode 100644 tests/modules/create.py create mode 100644 tests/modules/create_test_yml.py create mode 100644 tests/modules/install.py create mode 100644 tests/modules/lint.py create mode 100644 tests/modules/list.py create mode 100644 tests/modules/remove.py diff --git a/tests/modules/__init__.py b/tests/modules/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/modules/bump_versions.py b/tests/modules/bump_versions.py new file mode 100644 index 0000000000..923c39a0df --- /dev/null +++ b/tests/modules/bump_versions.py @@ -0,0 +1,49 @@ +import os +import re +import pytest + +import nf_core.modules +from nf_core.modules.module_utils import ModuleException + + +def test_modules_bump_versions_single_module(self): + """Test updating a single module""" + # Change the star/align version to an older version + main_nf_path = os.path.join(self.nfcore_modules, "software", "star", "align", "main.nf") + with open(main_nf_path, "r") as fh: + content = fh.read() + new_content = re.sub(r"bioconda::star=\d.\d.\d\D?", r"bioconda::star=2.6.1d", content) + with open(main_nf_path, "w") as fh: + fh.write(new_content) + version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) + version_bumper.bump_versions(module="star/align") + assert len(version_bumper.failed) == 0 + + +def test_modules_bump_versions_all_modules(self): + """Test updating all modules""" + version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) + version_bumper.bump_versions(all_modules=True) + assert len(version_bumper.failed) == 0 + + +def test_modules_bump_versions_fail(self): + """Fail updating a module with wrong name""" + version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) + with pytest.raises(ModuleException) as excinfo: + version_bumper.bump_versions(module="no/module") + assert "Could not find the specified module:" in str(excinfo.value) + + +def test_modules_bump_versions_fail_unknown_version(self): + """Fail because of an unknown version""" + # Change the star/align version to an older version + main_nf_path = os.path.join(self.nfcore_modules, "software", "star", "align", "main.nf") + with open(main_nf_path, "r") as fh: + content = fh.read() + new_content = re.sub(r"bioconda::star=\d.\d.\d\D?", r"bioconda::star=xxx", content) + with open(main_nf_path, "w") as fh: + fh.write(new_content) + version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) + version_bumper.bump_versions(module="star/align") + assert "Conda package had unknown version" in version_bumper.failed[0][0] diff --git a/tests/modules/create.py b/tests/modules/create.py new file mode 100644 index 0000000000..e554822807 --- /dev/null +++ b/tests/modules/create.py @@ -0,0 +1,42 @@ +import os +import pytest + +import nf_core.modules + + +def test_modules_create_succeed(self): + """Succeed at creating the TrimGalore! module""" + module_create = nf_core.modules.ModuleCreate( + self.pipeline_dir, "trimgalore", "@author", "process_low", True, True, conda_name="trim-galore" + ) + module_create.create() + assert os.path.exists(os.path.join(self.pipeline_dir, "modules", "local", "trimgalore.nf")) + + +def test_modules_create_fail_exists(self): + """Fail at creating the same module twice""" + module_create = nf_core.modules.ModuleCreate( + self.pipeline_dir, "trimgalore", "@author", "process_low", False, False, conda_name="trim-galore" + ) + module_create.create() + with pytest.raises(UserWarning) as excinfo: + module_create.create() + assert "Module file exists already" in str(excinfo.value) + + +def test_modules_create_nfcore_modules(self): + """Create a module in nf-core/modules clone""" + module_create = nf_core.modules.ModuleCreate(self.nfcore_modules, "fastqc", "@author", "process_low", False, False) + module_create.create() + assert os.path.exists(os.path.join(self.nfcore_modules, "software", "fastqc", "main.nf")) + assert os.path.exists(os.path.join(self.nfcore_modules, "tests", "software", "fastqc", "main.nf")) + + +def test_modules_create_nfcore_modules_subtool(self): + """Create a tool/subtool module in a nf-core/modules clone""" + module_create = nf_core.modules.ModuleCreate( + self.nfcore_modules, "star/index", "@author", "process_medium", False, False + ) + module_create.create() + assert os.path.exists(os.path.join(self.nfcore_modules, "software", "star", "index", "main.nf")) + assert os.path.exists(os.path.join(self.nfcore_modules, "tests", "software", "star", "index", "main.nf")) diff --git a/tests/modules/create_test_yml.py b/tests/modules/create_test_yml.py new file mode 100644 index 0000000000..9b7d8ecbef --- /dev/null +++ b/tests/modules/create_test_yml.py @@ -0,0 +1,59 @@ +import os +import tempfile +import pytest + +import nf_core.modules + + +def test_modules_custom_yml_dumper(self): + """Try to create a yml file with the custom yml dumper""" + out_dir = tempfile.mkdtemp() + yml_output_path = os.path.join(out_dir, "test.yml") + meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) + meta_builder.test_yml_output_path = yml_output_path + meta_builder.tests = [{"testname": "myname"}] + meta_builder.print_test_yml() + assert os.path.isfile(yml_output_path) + + +def test_modules_test_file_dict(self): + """Creat dict of test files and create md5 sums""" + test_file_dir = tempfile.mkdtemp() + meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) + with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh: + fh.write("this line is just for testing") + test_files = meta_builder.create_test_file_dict(test_file_dir) + assert len(test_files) == 1 + assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" + + +def test_modules_create_test_yml_get_md5(self): + """Get md5 sums from a dummy output""" + test_file_dir = tempfile.mkdtemp() + meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) + with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh: + fh.write("this line is just for testing") + test_files = meta_builder.get_md5_sums( + entry_point="dummy", command="dummy", results_dir=test_file_dir, results_dir_repeat=test_file_dir + ) + assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" + + +def test_modules_create_test_yml_entry_points(self): + """Test extracting test entry points from a main.nf file""" + meta_builder = nf_core.modules.ModulesTestYmlBuilder("star/align", False, "./", False, True) + meta_builder.module_test_main = os.path.join(self.nfcore_modules, "tests", "software", "star", "align", "main.nf") + meta_builder.scrape_workflow_entry_points() + assert meta_builder.entry_points[0] == "test_star_align" + + +def test_modules_create_test_yml_check_inputs(self): + """Test the check_inputs() function - raise UserWarning because test.yml exists""" + cwd = os.getcwd() + os.chdir(self.nfcore_modules) + meta_builder = nf_core.modules.ModulesTestYmlBuilder("star/align", False, "./", False, True) + meta_builder.module_test_main = os.path.join(self.nfcore_modules, "tests", "software", "star", "align", "main.nf") + with pytest.raises(UserWarning) as excinfo: + meta_builder.check_inputs() + os.chdir(cwd) + assert "Test YAML file already exists!" in str(excinfo.value) diff --git a/tests/modules/install.py b/tests/modules/install.py new file mode 100644 index 0000000000..399d7f4aa5 --- /dev/null +++ b/tests/modules/install.py @@ -0,0 +1,42 @@ +import tempfile +import pytest +import os + + +def test_modules_install_nopipeline(self): + """Test installing a module - no pipeline given""" + self.mods_install.dir = None + assert self.mods_install.install("foo") is False + + +def test_modules_install_emptypipeline(self): + """Test installing a module - empty dir given""" + self.mods_install.dir = tempfile.mkdtemp() + with pytest.raises(UserWarning) as excinfo: + self.mods_install.install("foo") + assert "Could not find a 'main.nf' or 'nextflow.config' file" in str(excinfo.value) + + +def test_modules_install_nomodule(self): + """Test installing a module - unrecognised module given""" + assert self.mods_install.install("foo") is False + + +def test_modules_install_trimgalore(self): + """Test installing a module - TrimGalore!""" + assert self.mods_install.install("trimgalore") is not False + module_path = os.path.join(self.mods_install.dir, "modules", "nf-core", "software", "trimgalore") + assert os.path.exists(module_path) + + +def test_modules_install_trimgalore_alternative_source(self): + """Test installing a module from a different source repository - TrimGalore!""" + assert self.mods_install_alt.install("trimgalore") is not False + module_path = os.path.join(self.mods_install.dir, "modules", "external", "trimgalore") + assert os.path.exists(module_path) + + +def test_modules_install_trimgalore_twice(self): + """Test installing a module - TrimGalore! already there""" + self.mods_install.install("trimgalore") + assert self.mods_install.install("trimgalore") is True diff --git a/tests/modules/lint.py b/tests/modules/lint.py new file mode 100644 index 0000000000..f96e0af0a5 --- /dev/null +++ b/tests/modules/lint.py @@ -0,0 +1,31 @@ +import nf_core.modules + + +def test_modules_lint_trimgalore(self): + """Test linting the TrimGalore! module""" + self.mods_install.install("trimgalore") + module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir) + module_lint.lint(print_results=False, module="trimgalore") + assert len(module_lint.passed) > 0 + assert len(module_lint.warned) == 0 + assert len(module_lint.failed) == 0 + + +def test_modules_lint_empty(self): + """Test linting a pipeline with no modules installed""" + self.mods_remove.remove("fastqc") + self.mods_remove.remove("multiqc") + module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir) + module_lint.lint(print_results=False, all_modules=True) + assert len(module_lint.passed) == 0 + assert len(module_lint.warned) == 0 + assert len(module_lint.failed) == 0 + + +def test_modules_lint_new_modules(self): + """lint all modules in nf-core/modules repo clone""" + module_lint = nf_core.modules.ModuleLint(dir=self.nfcore_modules) + module_lint.lint(print_results=True, all_modules=True) + assert len(module_lint.passed) > 0 + assert len(module_lint.warned) >= 0 + assert len(module_lint.failed) == 0 diff --git a/tests/modules/list.py b/tests/modules/list.py new file mode 100644 index 0000000000..8bbe0a7082 --- /dev/null +++ b/tests/modules/list.py @@ -0,0 +1,34 @@ +import nf_core.modules +from rich.console import Console + + +def test_modules_list_remote(self): + """Test listing available modules""" + mods_list = nf_core.modules.ModuleList(None) + listed_mods = mods_list.list_modules() + console = Console(record=True) + console.print(listed_mods) + output = console.export_text() + assert "fastqc" in output + + +def test_modules_list_pipeline(self): + """Test listing locally installed modules""" + mods_list = nf_core.modules.ModuleList(self.pipeline_dir) + listed_mods = mods_list.list_modules() + console = Console(record=True) + console.print(listed_mods) + output = console.export_text() + assert "fastqc" in output + assert "multiqc" in output + + +def test_modules_install_and_list_pipeline(self): + """Test listing locally installed modules""" + self.mods_install.install("trimgalore") + mods_list = nf_core.modules.ModuleList(self.pipeline_dir) + listed_mods = mods_list.list_modules() + console = Console(record=True) + console.print(listed_mods) + output = console.export_text() + assert "trimgalore" in output diff --git a/tests/modules/remove.py b/tests/modules/remove.py new file mode 100644 index 0000000000..318b784786 --- /dev/null +++ b/tests/modules/remove.py @@ -0,0 +1,22 @@ +import os + + +def test_modules_remove_trimgalore(self): + """Test removing TrimGalore! module after installing it""" + self.mods_install.install("trimgalore") + module_path = os.path.join(self.mods_install.dir, "modules", "nf-core", "software", "trimgalore") + assert self.mods_remove.remove("trimgalore") + assert os.path.exists(module_path) is False + + +def test_modules_remove_trimgalore_alternative_source(self): + """Test removing TrimGalore! module after installing it from an alternative source""" + self.mods_install_alt.install("trimgalore") + module_path = os.path.join(self.mods_install.dir, "modules", "external", "trimgalore") + assert self.mods_remove_alt.remove("trimgalore") + assert os.path.exists(module_path) is False + + +def test_modules_remove_trimgalore_uninstalled(self): + """Test removing TrimGalore! module without installing it""" + assert self.mods_remove.remove("trimgalore") is False diff --git a/tests/test_modules.py b/tests/test_modules.py index 2856f420c5..88636306da 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -2,17 +2,12 @@ """ Tests covering the modules commands """ -from nf_core.modules.module_utils import ModuleException -from nf_core.modules import create import nf_core.modules import os -import re import shutil import tempfile import unittest -import pytest -from rich.console import Console def create_modules_repo_dummy(): @@ -62,237 +57,51 @@ def test_modulesrepo_class(self): assert modrepo.name == "nf-core/modules" assert modrepo.branch == "master" - def test_modules_list_remote(self): - """Test listing available modules""" - mods_list = nf_core.modules.ModuleList(None) - listed_mods = mods_list.list_modules() - console = Console(record=True) - console.print(listed_mods) - output = console.export_text() - assert "fastqc" in output - - def test_modules_list_pipeline(self): - """Test listing locally installed modules""" - mods_list = nf_core.modules.ModuleList(self.pipeline_dir) - listed_mods = mods_list.list_modules() - console = Console(record=True) - console.print(listed_mods) - output = console.export_text() - assert "fastqc" in output - assert "multiqc" in output - - def test_modules_install_and_list_pipeline(self): - """Test listing locally installed modules""" - self.mods_install.install("trimgalore") - mods_list = nf_core.modules.ModuleList(self.pipeline_dir) - listed_mods = mods_list.list_modules() - console = Console(record=True) - console.print(listed_mods) - output = console.export_text() - assert "trimgalore" in output - - def test_modules_install_nopipeline(self): - """Test installing a module - no pipeline given""" - self.mods_install.dir = None - assert self.mods_install.install("foo") is False - - def test_modules_install_emptypipeline(self): - """Test installing a module - empty dir given""" - self.mods_install.dir = tempfile.mkdtemp() - with pytest.raises(UserWarning) as excinfo: - self.mods_install.install("foo") - assert "Could not find a 'main.nf' or 'nextflow.config' file" in str(excinfo.value) - - def test_modules_install_nomodule(self): - """Test installing a module - unrecognised module given""" - assert self.mods_install.install("foo") is False - - def test_modules_install_trimgalore(self): - """Test installing a module - TrimGalore!""" - assert self.mods_install.install("trimgalore") is not False - module_path = os.path.join(self.mods_install.dir, "modules", "nf-core", "software", "trimgalore") - assert os.path.exists(module_path) - - def test_modules_install_trimgalore_alternative_source(self): - """Test installing a module from a different source repository - TrimGalore!""" - assert self.mods_install_alt.install("trimgalore") is not False - module_path = os.path.join(self.mods_install.dir, "modules", "external", "trimgalore") - assert os.path.exists(module_path) - - def test_modules_install_trimgalore_twice(self): - """Test installing a module - TrimGalore! already there""" - self.mods_install.install("trimgalore") - assert self.mods_install.install("trimgalore") is True - - def test_modules_remove_trimgalore(self): - """Test removing TrimGalore! module after installing it""" - self.mods_install.install("trimgalore") - module_path = os.path.join(self.mods_install.dir, "modules", "nf-core", "software", "trimgalore") - assert self.mods_remove.remove("trimgalore") - assert os.path.exists(module_path) is False - - def test_modules_remove_trimgalore_alternative_source(self): - """Test removing TrimGalore! module after installing it from an alternative source""" - self.mods_install_alt.install("trimgalore") - module_path = os.path.join(self.mods_install.dir, "modules", "external", "trimgalore") - assert self.mods_remove_alt.remove("trimgalore") - assert os.path.exists(module_path) is False - - def test_modules_remove_trimgalore_uninstalled(self): - """Test removing TrimGalore! module without installing it""" - assert self.mods_remove.remove("trimgalore") is False - - def test_modules_lint_trimgalore(self): - """Test linting the TrimGalore! module""" - self.mods_install.install("trimgalore") - module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir) - module_lint.lint(print_results=False, module="trimgalore") - assert len(module_lint.passed) > 0 - assert len(module_lint.warned) == 0 - assert len(module_lint.failed) == 0 - - def test_modules_lint_empty(self): - """Test linting a pipeline with no modules installed""" - self.mods_remove.remove("fastqc") - self.mods_remove.remove("multiqc") - module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir) - module_lint.lint(print_results=False, all_modules=True) - assert len(module_lint.passed) == 0 - assert len(module_lint.warned) == 0 - assert len(module_lint.failed) == 0 - - def test_modules_lint_new_modules(self): - """lint all modules in nf-core/modules repo clone""" - module_lint = nf_core.modules.ModuleLint(dir=self.nfcore_modules) - module_lint.lint(print_results=True, all_modules=True) - assert len(module_lint.passed) > 0 - assert len(module_lint.warned) >= 0 - assert len(module_lint.failed) == 0 - - def test_modules_create_succeed(self): - """Succeed at creating the TrimGalore! module""" - module_create = nf_core.modules.ModuleCreate( - self.pipeline_dir, "trimgalore", "@author", "process_low", True, True, conda_name="trim-galore" - ) - module_create.create() - assert os.path.exists(os.path.join(self.pipeline_dir, "modules", "local", "trimgalore.nf")) - - def test_modules_create_fail_exists(self): - """Fail at creating the same module twice""" - module_create = nf_core.modules.ModuleCreate( - self.pipeline_dir, "trimgalore", "@author", "process_low", False, False, conda_name="trim-galore" - ) - module_create.create() - with pytest.raises(UserWarning) as excinfo: - module_create.create() - assert "Module file exists already" in str(excinfo.value) - - def test_modules_custom_yml_dumper(self): - """Try to create a yml file with the custom yml dumper""" - out_dir = tempfile.mkdtemp() - yml_output_path = os.path.join(out_dir, "test.yml") - meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) - meta_builder.test_yml_output_path = yml_output_path - meta_builder.tests = [{"testname": "myname"}] - meta_builder.print_test_yml() - assert os.path.isfile(yml_output_path) - - def test_modules_test_file_dict(self): - """Creat dict of test files and create md5 sums""" - test_file_dir = tempfile.mkdtemp() - meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) - with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh: - fh.write("this line is just for testing") - test_files = meta_builder.create_test_file_dict(test_file_dir) - assert len(test_files) == 1 - assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" - - def test_modules_create_test_yml_get_md5(self): - """Get md5 sums from a dummy output""" - test_file_dir = tempfile.mkdtemp() - meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", False, "./", False, True) - with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh: - fh.write("this line is just for testing") - test_files = meta_builder.get_md5_sums( - entry_point="dummy", command="dummy", results_dir=test_file_dir, results_dir_repeat=test_file_dir - ) - assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" - - def test_modules_create_test_yml_entry_points(self): - """Test extracting test entry points from a main.nf file""" - meta_builder = nf_core.modules.ModulesTestYmlBuilder("star/align", False, "./", False, True) - meta_builder.module_test_main = os.path.join( - self.nfcore_modules, "tests", "software", "star", "align", "main.nf" - ) - meta_builder.scrape_workflow_entry_points() - assert meta_builder.entry_points[0] == "test_star_align" - - def test_modules_create_test_yml_check_inputs(self): - """Test the check_inputs() function - raise UserWarning because test.yml exists""" - cwd = os.getcwd() - os.chdir(self.nfcore_modules) - meta_builder = nf_core.modules.ModulesTestYmlBuilder("star/align", False, "./", False, True) - meta_builder.module_test_main = os.path.join( - self.nfcore_modules, "tests", "software", "star", "align", "main.nf" - ) - with pytest.raises(UserWarning) as excinfo: - meta_builder.check_inputs() - os.chdir(cwd) - assert "Test YAML file already exists!" in str(excinfo.value) - - def test_modules_create_nfcore_modules(self): - """Create a module in nf-core/modules clone""" - module_create = nf_core.modules.ModuleCreate( - self.nfcore_modules, "fastqc", "@author", "process_low", False, False - ) - module_create.create() - assert os.path.exists(os.path.join(self.nfcore_modules, "software", "fastqc", "main.nf")) - assert os.path.exists(os.path.join(self.nfcore_modules, "tests", "software", "fastqc", "main.nf")) - - def test_modules_create_nfcore_modules_subtool(self): - """Create a tool/subtool module in a nf-core/modules clone""" - module_create = nf_core.modules.ModuleCreate( - self.nfcore_modules, "star/index", "@author", "process_medium", False, False - ) - module_create.create() - assert os.path.exists(os.path.join(self.nfcore_modules, "software", "star", "index", "main.nf")) - assert os.path.exists(os.path.join(self.nfcore_modules, "tests", "software", "star", "index", "main.nf")) - - def test_modules_bump_versions_single_module(self): - """ Test updating a single module """ - # Change the star/align version to an older version - main_nf_path = os.path.join(self.nfcore_modules, "software", "star", "align", "main.nf") - with open(main_nf_path, "r") as fh: - content = fh.read() - new_content = re.sub(r"bioconda::star=\d.\d.\d\D?", r"bioconda::star=2.6.1d", content) - with open(main_nf_path, "w") as fh: - fh.write(new_content) - version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) - version_bumper.bump_versions(module="star/align") - assert len(version_bumper.failed) == 0 - - def test_modules_bump_versions_all_modules(self): - """ Test updating all modules """ - version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) - version_bumper.bump_versions(all_modules=True) - assert len(version_bumper.failed) == 0 - - def test_modules_bump_versions_fail(self): - """ Fail updating a module with wrong name""" - version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) - with pytest.raises(ModuleException) as excinfo: - version_bumper.bump_versions(module="no/module") - assert "Could not find the specified module:" in str(excinfo.value) - - def test_modules_bump_versions_fail_unknown_version(self): - """ Fail because of an unknown version """ - # Change the star/align version to an older version - main_nf_path = os.path.join(self.nfcore_modules, "software", "star", "align", "main.nf") - with open(main_nf_path, "r") as fh: - content = fh.read() - new_content = re.sub(r"bioconda::star=\d.\d.\d\D?", r"bioconda::star=xxx", content) - with open(main_nf_path, "w") as fh: - fh.write(new_content) - version_bumper = nf_core.modules.ModuleVersionBumper(pipeline_dir=self.nfcore_modules) - version_bumper.bump_versions(module="star/align") - assert "Conda package had unknown version" in version_bumper.failed[0][0] + ############################################ + # Test of the individual modules commands. # + ############################################ + + from modules.list import ( + test_modules_list_remote, + test_modules_list_pipeline, + test_modules_install_and_list_pipeline, + ) + + from modules.install import ( + test_modules_install_nopipeline, + test_modules_install_emptypipeline, + test_modules_install_nomodule, + test_modules_install_trimgalore, + test_modules_install_trimgalore_alternative_source, + test_modules_install_trimgalore_twice, + ) + + from modules.remove import ( + test_modules_remove_trimgalore, + test_modules_remove_trimgalore_alternative_source, + test_modules_remove_trimgalore_uninstalled, + ) + + from modules.lint import test_modules_lint_trimgalore, test_modules_lint_empty, test_modules_lint_new_modules + + from modules.create import ( + test_modules_create_succeed, + test_modules_create_fail_exists, + test_modules_create_nfcore_modules, + test_modules_create_nfcore_modules_subtool, + ) + + from modules.create_test_yml import ( + test_modules_custom_yml_dumper, + test_modules_test_file_dict, + test_modules_create_test_yml_get_md5, + test_modules_create_test_yml_entry_points, + test_modules_create_test_yml_check_inputs, + ) + + from modules.bump_versions import ( + test_modules_bump_versions_single_module, + test_modules_bump_versions_all_modules, + test_modules_bump_versions_fail, + test_modules_bump_versions_fail_unknown_version, + ) From 95b04b966b0acb82d53127f7a3173b7ec717abfa Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Wed, 7 Jul 2021 10:50:41 +0200 Subject: [PATCH 2/4] Remove dependencies on number of lint tests --- tests/lint/files_unchanged.py | 2 +- tests/lint/modules_json.py | 2 +- tests/lint/nextflow_config.py | 4 ++-- tests/test_lint.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/lint/files_unchanged.py b/tests/lint/files_unchanged.py index abf974b350..d890c217e7 100644 --- a/tests/lint/files_unchanged.py +++ b/tests/lint/files_unchanged.py @@ -24,6 +24,6 @@ def test_files_unchanged_fail(self): lint_obj = nf_core.lint.PipelineLint(new_pipeline) lint_obj._load() results = lint_obj.files_unchanged() - assert len(results["failed"]) == 1 + assert len(results["failed"]) > 0 assert failing_file in results["failed"][0] assert results["could_fix"] diff --git a/tests/lint/modules_json.py b/tests/lint/modules_json.py index a0d0c75745..94ff1c84a1 100644 --- a/tests/lint/modules_json.py +++ b/tests/lint/modules_json.py @@ -6,4 +6,4 @@ def test_modules_json_fail(self): results = self.lint_obj.modules_json() assert len(results.get("warned", [])) == 0 assert len(results.get("failed", [])) == 0 - assert len(results.get("passed", [])) == 1 + assert len(results.get("passed", [])) > 0 diff --git a/tests/lint/nextflow_config.py b/tests/lint/nextflow_config.py index 4836761c04..229586372d 100644 --- a/tests/lint/nextflow_config.py +++ b/tests/lint/nextflow_config.py @@ -24,7 +24,7 @@ def test_nextflow_config_bad_name_fail(self): lint_obj.nf_config["manifest.name"] = "bad_name" result = lint_obj.nextflow_config() - assert len(result["failed"]) == 1 + assert len(result["failed"]) > 0 assert len(result["warned"]) == 0 @@ -37,5 +37,5 @@ def test_nextflow_config_dev_in_release_mode_failed(self): lint_obj.release_mode = True lint_obj.nf_config["manifest.version"] = "dev_is_bad_name" result = lint_obj.nextflow_config() - assert len(result["failed"]) == 1 + assert len(result["failed"]) > 0 assert len(result["warned"]) == 0 diff --git a/tests/test_lint.py b/tests/test_lint.py index fbfca5c9e2..831f7a826c 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -128,8 +128,8 @@ def test_json_output(self): # Load created JSON file and check its contents with open(json_fn, "r") as fh: saved_json = json.load(fh) - assert saved_json["num_tests_pass"] == 2 - assert saved_json["num_tests_warned"] == 1 + assert saved_json["num_tests_pass"] > 0 + assert saved_json["num_tests_warned"] > 0 assert saved_json["num_tests_ignored"] == 0 assert saved_json["num_tests_failed"] == 0 assert saved_json["has_tests_pass"] @@ -223,7 +223,7 @@ def test_sphinx_rst_files(self): # def test_critical_missingfiles_example(self): # """Tests for missing nextflow config and main.nf files""" # lint_obj = nf_core.lint.run_linting(PATH_CRITICAL_EXAMPLE, False) -# assert len(lint_obj.failed) == 1 +# assert len(lint_obj.failed) > 0 # # def test_failing_missingfiles_example(self): # """Tests for missing files like Dockerfile or LICENSE""" From 744e8d5d00c07671b6b45a93c0462a3c20912dd8 Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Wed, 7 Jul 2021 10:52:51 +0200 Subject: [PATCH 3/4] Rename modules.json test --- tests/lint/modules_json.py | 2 +- tests/test_lint.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lint/modules_json.py b/tests/lint/modules_json.py index 94ff1c84a1..2ed33d9015 100644 --- a/tests/lint/modules_json.py +++ b/tests/lint/modules_json.py @@ -1,7 +1,7 @@ import nf_core.lint -def test_modules_json_fail(self): +def test_modules_json_pass(self): self.lint_obj._load() results = self.lint_obj.modules_json() assert len(results.get("warned", [])) == 0 diff --git a/tests/test_lint.py b/tests/test_lint.py index 831f7a826c..bca3970302 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -215,7 +215,7 @@ def test_sphinx_rst_files(self): from lint.version_consistency import test_version_consistency - from lint.modules_json import test_modules_json_fail + from lint.modules_json import test_modules_json_pass # TODO nf-core: Assess and strip out if no longer required for DSL2 From b737414fb999433655bc2708614a4449bb41bdff Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Wed, 7 Jul 2021 10:57:06 +0200 Subject: [PATCH 4/4] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe2eed755..83f3fb5fb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ #### Tests * Added a test for the `version_consistency` lint check +* Refactored modules tests into separate files, and removed direct comparisons with number of tests in `lint` tests ([#1158](https://github.com/nf-core/tools/issues/1158)) ## [v1.14 - Brass Chicken :chicken:](https://github.com/nf-core/tools/releases/tag/1.14) - [2021-05-11]