diff --git a/nf_core/modules/lint/module_changes.py b/nf_core/modules/lint/module_changes.py index b6e9978198..74e5df064e 100644 --- a/nf_core/modules/lint/module_changes.py +++ b/nf_core/modules/lint/module_changes.py @@ -24,7 +24,8 @@ def module_changes(module_lint_object, module): if module.is_patched: # If the module is patched, we need to apply # the patch in reverse before comparing with the remote - tempdir = Path(tempfile.mkdtemp()) + tempdir_parent = Path(tempfile.mkdtemp()) + tempdir = tempdir_parent / "tmp_module_dir" shutil.copytree(module.module_dir, tempdir) try: new_lines = ModulesDiffer.try_apply_patch( diff --git a/tests/modules/lint.py b/tests/modules/lint.py index 64b5f2ff0f..d5793dfd05 100644 --- a/tests/modules/lint.py +++ b/tests/modules/lint.py @@ -1,8 +1,11 @@ +import os + import pytest import nf_core.modules from ..utils import GITLAB_URL +from .patch import BISMARK_ALIGN, PATCH_BRANCH, setup_patch def test_modules_lint_trimgalore(self): @@ -48,3 +51,26 @@ def test_modules_lint_gitlab_modules(self): assert len(module_lint.failed) == 0 assert len(module_lint.passed) > 0 assert len(module_lint.warned) >= 0 + + +def test_modules_lint_patched_modules(self): + """ + Test creating a patch file and applying it to a new version of the the files + """ + setup_patch(self.pipeline_dir, True) + + # Create a patch file + patch_obj = nf_core.modules.ModulePatch(self.pipeline_dir, GITLAB_URL, PATCH_BRANCH) + patch_obj.patch(BISMARK_ALIGN) + + # change temporarily working directory to the pipeline directory + # to avoid error from try_apply_patch() during linting + wd_old = os.getcwd() + os.chdir(self.pipeline_dir) + module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir, remote_url=GITLAB_URL) + module_lint.lint(print_results=False, all_modules=True) + os.chdir(wd_old) + + assert len(module_lint.failed) == 0 + assert len(module_lint.passed) > 0 + assert len(module_lint.warned) >= 0 diff --git a/tests/test_modules.py b/tests/test_modules.py index c8dbf948f3..52ca197bd7 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -115,6 +115,7 @@ def test_modulesrepo_class(self): test_modules_lint_gitlab_modules, test_modules_lint_new_modules, test_modules_lint_no_gitlab, + test_modules_lint_patched_modules, test_modules_lint_trimgalore, ) from .modules.list import (