Skip to content

Commit

Permalink
Merge pull request #1761 from fabianegli/dirs-exist-ok
Browse files Browse the repository at this point in the history
workaround for shutil.copytree's lack of dirs_exist_ok in Python3.7 + added tests for module patch
  • Loading branch information
ewels authored Aug 23, 2022
2 parents dcd03f3 + 651c629 commit 8fc04a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nf_core/modules/lint/module_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions tests/modules/lint.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 8fc04a7

Please sign in to comment.