From 691d8ac5526f8b04869aeaf89443a12b6d9a4699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Mir=20Pedrol?= Date: Tue, 26 Aug 2025 11:10:31 +0200 Subject: [PATCH 1/3] add pytest for get_wf_files --- tests/test_utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d8e9eb4351..f5563ca3eb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -212,10 +212,10 @@ def test_set_wd(self): def test_set_wd_revert_on_raise(self): wd_before_context = Path().resolve() - with pytest.raises(Exception): - with nf_core.utils.set_wd(self.tmp_dir): - raise Exception - assert wd_before_context == Path().resolve() + with mock.patch("nf_core.utils.set_wd", side_effect=Exception("mocked exception")): + with pytest.raises(Exception): + with nf_core.utils.set_wd(self.tmp_dir): + assert wd_before_context == Path().resolve() @mock.patch("nf_core.utils.run_cmd") def test_fetch_wf_config(self, mock_run_cmd): @@ -224,3 +224,11 @@ def test_fetch_wf_config(self, mock_run_cmd): config = nf_core.utils.fetch_wf_config(".", False) assert len(config.keys()) == 1 assert "params.param2" in list(config.keys()) + + def test_get_wf_files(self): + files = nf_core.utils.get_wf_files(self.pipeline_obj.wf_path) + assert str(Path(self.pipeline_dir, "main.nf")) in files + + def test_get_wf_files_no_gitignore(self): + files = nf_core.utils.get_wf_files(Path("random/path")) + assert files == [] From 53072ff297a5e23ea44a5164c117d17acc4a1810 Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Tue, 26 Aug 2025 09:12:34 +0000 Subject: [PATCH 2/3] [automated] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd80da643..798d8969e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Validation of meta.yaml in cross-org repos ([#3680](https://github.com/nf-core/tools/pull/3680)) - Replace arm profile with arm64 and emulate_amd64 profiles ([#3689](https://github.com/nf-core/tools/pull/3689)) - Remove workflow.trace from nf-test snapshot ([#3721](https://github.com/nf-core/tools/pull/3721)) +- add pytest for get_wf_files ([#3725](https://github.com/nf-core/tools/pull/3725)) ## [v3.3.2 - Tungsten Tamarin Patch 2](https://github.com/nf-core/tools/releases/tag/3.3.2) - [2025-07-08] From 361ac35880a040984b9998b23e9e43bf40c3c96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Mir=20Pedrol?= Date: Wed, 27 Aug 2025 12:15:01 +0200 Subject: [PATCH 3/3] improve test_get_wf_files test and fix get_wf_files function --- nf_core/utils.py | 9 +++++++-- tests/test_utils.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nf_core/utils.py b/nf_core/utils.py index f8ef904fcc..f4b2e464e4 100644 --- a/nf_core/utils.py +++ b/nf_core/utils.py @@ -1573,13 +1573,18 @@ def get_wf_files(wf_path: Path): """Return a list of all files in a directory (ignores .gitigore files)""" wf_files = [] - try: with open(Path(wf_path, ".gitignore")) as f: lines = f.read().splitlines() - ignore = [line for line in lines if line and not line.startswith("#")] + print(lines) + ignore = [ + (str(wf_path / line) + "*" if line.endswith("/") else str(wf_path / line)) + for line in lines + if line and not line.startswith("#") + ] except FileNotFoundError: ignore = [] + print(ignore) for path in Path(wf_path).rglob("*"): if any(fnmatch.fnmatch(str(path), pattern) for pattern in ignore): diff --git a/tests/test_utils.py b/tests/test_utils.py index f5563ca3eb..8ef3c61eb8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -226,8 +226,13 @@ def test_fetch_wf_config(self, mock_run_cmd): assert "params.param2" in list(config.keys()) def test_get_wf_files(self): + (self.pipeline_obj.wf_path / "work").mkdir() + (self.pipeline_obj.wf_path / "work" / "file.txt").touch() + (self.pipeline_obj.wf_path / ".nextflow.log").touch() files = nf_core.utils.get_wf_files(self.pipeline_obj.wf_path) assert str(Path(self.pipeline_dir, "main.nf")) in files + assert str(Path(self.pipeline_dir, "work", "file.txt")) not in files + assert str(Path(self.pipeline_dir, ".nextflow.log")) not in files def test_get_wf_files_no_gitignore(self): files = nf_core.utils.get_wf_files(Path("random/path"))