From d03b7ae235fd4b7de55b6c26bb57489a9b041399 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Thu, 30 Nov 2023 14:55:56 +0100 Subject: [PATCH] delete component from pytest_modules.yml --- nf_core/components/create.py | 11 +++++++++++ tests/modules/create.py | 11 +++++++++++ tests/subworkflows/create.py | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/nf_core/components/create.py b/nf_core/components/create.py index 70fcfb21a0..b85acdc57f 100644 --- a/nf_core/components/create.py +++ b/nf_core/components/create.py @@ -17,11 +17,13 @@ import jinja2 import questionary import rich +import yaml from packaging.version import parse as parse_version import nf_core import nf_core.utils from nf_core.components.components_command import ComponentCommand +from nf_core.lint_utils import run_prettier_on_file log = logging.getLogger(__name__) @@ -475,3 +477,12 @@ def _print_and_delete_pytest_files(self): "You can find more information about nf-test [link=https://nf-co.re/docs/contributing/modules#migrating-from-pytest-to-nf-test]at the nf-core web[/link].\n" f"Once done, make sure to delete the module pytest files to avoid linting errors: {pytest_dir}" ) + # Delete tags from pytest_modules.yml + modules_yml = Path(self.directory, "tests", "config", "pytest_modules.yml") + with open(modules_yml, "r") as fh: + yml_file = yaml.safe_load(fh) + yml_key = self.component_dir if self.component_type == "modules" else f"subworkflows/{self.component_dir}" + del yml_file[yml_key] + with open(modules_yml, "w") as fh: + yaml.dump(yml_file, fh) + run_prettier_on_file(modules_yml) diff --git a/tests/modules/create.py b/tests/modules/create.py index 062761d059..9c855a11e6 100644 --- a/tests/modules/create.py +++ b/tests/modules/create.py @@ -7,6 +7,7 @@ import pytest import requests_cache import responses +import yaml from git.repo import Repo import nf_core.modules @@ -105,6 +106,11 @@ def test_modules_migrate(self, mock_rich_ask): # Check that pytest folder is deleted assert not pytest_dir.is_dir() + # Check that pytest_modules.yml is updated + with open(Path(self.nfcore_modules, "tests", "config", "pytest_modules.yml")) as fh: + modules_yml = yaml.safe_load(fh) + assert "samtools/sort" not in modules_yml.keys() + @mock.patch("rich.prompt.Confirm.ask") def test_modules_migrate_no_delete(self, mock_rich_ask): @@ -123,3 +129,8 @@ def test_modules_migrate_no_delete(self, mock_rich_ask): # Check that pytest folder is not deleted assert pytest_dir.is_dir() + + # Check that pytest_modules.yml is updated + with open(Path(self.nfcore_modules, "tests", "config", "pytest_modules.yml")) as fh: + modules_yml = yaml.safe_load(fh) + assert "samtools/sort" not in modules_yml.keys() diff --git a/tests/subworkflows/create.py b/tests/subworkflows/create.py index 88f98b9453..2855e68e2c 100644 --- a/tests/subworkflows/create.py +++ b/tests/subworkflows/create.py @@ -5,6 +5,7 @@ from unittest import mock import pytest +import yaml from git.repo import Repo import nf_core.subworkflows @@ -75,6 +76,11 @@ def test_subworkflows_migrate(self, mock_rich_ask): # Check that pytest folder is deleted assert not pytest_dir.is_dir() + # Check that pytest_modules.yml is updated + with open(Path(self.nfcore_modules, "tests", "config", "pytest_modules.yml")) as fh: + modules_yml = yaml.safe_load(fh) + assert "subworkflows/bam_stats_samtools" not in modules_yml.keys() + @mock.patch("rich.prompt.Confirm.ask") def test_subworkflows_migrate_no_delete(self, mock_rich_ask): @@ -95,3 +101,8 @@ def test_subworkflows_migrate_no_delete(self, mock_rich_ask): # Check that pytest folder is not deleted assert pytest_dir.is_dir() + + # Check that pytest_modules.yml is updated + with open(Path(self.nfcore_modules, "tests", "config", "pytest_modules.yml")) as fh: + modules_yml = yaml.safe_load(fh) + assert "subworkflows/bam_stats_samtools" not in modules_yml.keys()