From 2439a4a226951d153c6a8a0a2775fdcb4fb7c2cb Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 12 Dec 2023 09:56:01 +0100 Subject: [PATCH 1/3] Don't fail linting if md5sum for empty files are found in a stub test --- CHANGELOG.md | 1 + nf_core/modules/lint/module_tests.py | 82 ++++++++++++------- .../subworkflows/lint/subworkflow_tests.py | 82 ++++++++++++------- 3 files changed, 103 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1279e9249..0334b468f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Correctly pass subworkflow linting test if `COMPONENT.out.versions` is used in the script ([#2448](https://github.com/nf-core/tools/pull/2448)) - Check for spaces in modules container URLs ([#2452](https://github.com/nf-core/tools/issues/2452)) - Correctly ignore `timeline.enabled`, `report.enabled`, `trace.enabled`, `dag.enabled` variables when linting a pipeline. ([#2507](https://github.com/nf-core/tools/pull/2507)) +- Don't fail linting if md5sum for empty files are found in a stub test ([]()) ### Modules diff --git a/nf_core/modules/lint/module_tests.py b/nf_core/modules/lint/module_tests.py index 1a18482972..86539ab995 100644 --- a/nf_core/modules/lint/module_tests.py +++ b/nf_core/modules/lint/module_tests.py @@ -1,6 +1,7 @@ """ Lint the tests of a module in nf-core/modules """ +import json import logging from pathlib import Path @@ -52,39 +53,58 @@ def module_tests(_, module: NFCoreComponent): ) # Validate no empty files with open(snap_file, "r") as snap_fh: - snap_content = snap_fh.read() - if "d41d8cd98f00b204e9800998ecf8427e" in snap_content: - module.failed.append( - ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, + snap_content = json.load(snap_fh) + for test_name in snap_content.keys(): + if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): + if "stub" not in test_name: + module.failed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found, but it is a stub test", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "no md5sum for empty file found", + snap_file, + ) ) - ) - else: - module.passed.append( - ( - "test_snap_md5sum", - "no md5sum for empty file found", - snap_file, + if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): + if "stub" not in test_name: + module.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found, but it is a stub test", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "no md5sum for compressed empty file found", + snap_file, + ) ) - ) - if "7029066c27ac6f5ef18d660d5741979a" in snap_content: - module.failed.append( - ( - "test_snap_md5sum", - "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", - snap_file, - ) - ) - else: - module.passed.append( - ( - "test_snap_md5sum", - "no md5sum for compressed empty file found", - snap_file, - ) - ) else: module.failed.append( ("test_snapshot_exists", "snapshot file `main.nf.test.snap` does not exist", snap_file) diff --git a/nf_core/subworkflows/lint/subworkflow_tests.py b/nf_core/subworkflows/lint/subworkflow_tests.py index 044c70b392..2f91efd259 100644 --- a/nf_core/subworkflows/lint/subworkflow_tests.py +++ b/nf_core/subworkflows/lint/subworkflow_tests.py @@ -1,6 +1,7 @@ """ Lint the tests of a subworkflow in nf-core/modules """ +import json import logging from pathlib import Path @@ -59,39 +60,58 @@ def subworkflow_tests(_, subworkflow: NFCoreComponent): subworkflow.passed.append(("test_snapshot_exists", "test `main.nf.test.snap` exists", snap_file)) # Validate no empty files with open(snap_file, "r") as snap_fh: - snap_content = snap_fh.read() - if "d41d8cd98f00b204e9800998ecf8427e" in snap_content: - subworkflow.failed.append( - ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, + snap_content = json.load(snap_fh) + for test_name in snap_content.keys(): + if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): + if "stub" not in test_name: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", + snap_file, + ) + ) + else: + subworkflow.passed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found, but it is a stub test", + snap_file, + ) + ) + else: + subworkflow.passed.append( + ( + "test_snap_md5sum", + "no md5sum for empty file found", + snap_file, + ) ) - ) - else: - subworkflow.passed.append( - ( - "test_snap_md5sum", - "no md5sum for empty file found", - snap_file, + if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): + if "stub" not in test_name: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", + snap_file, + ) + ) + else: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found, but it is a stub test", + snap_file, + ) + ) + else: + subworkflow.passed.append( + ( + "test_snap_md5sum", + "no md5sum for compressed empty file found", + snap_file, + ) ) - ) - if "7029066c27ac6f5ef18d660d5741979a" in snap_content: - subworkflow.failed.append( - ( - "test_snap_md5sum", - "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", - snap_file, - ) - ) - else: - subworkflow.passed.append( - ( - "test_snap_md5sum", - "no md5sum for compressed empty file found", - snap_file, - ) - ) else: subworkflow.failed.append( ("test_snapshot_exists", "test `main.nf.test.snap` does not exist", snap_file) From f5e00dda2d91aeaf397c7dc6c61d946dd23d2f8f Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 12 Dec 2023 09:58:16 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0334b468f9..c65e98231b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - Correctly pass subworkflow linting test if `COMPONENT.out.versions` is used in the script ([#2448](https://github.com/nf-core/tools/pull/2448)) - Check for spaces in modules container URLs ([#2452](https://github.com/nf-core/tools/issues/2452)) - Correctly ignore `timeline.enabled`, `report.enabled`, `trace.enabled`, `dag.enabled` variables when linting a pipeline. ([#2507](https://github.com/nf-core/tools/pull/2507)) -- Don't fail linting if md5sum for empty files are found in a stub test ([]()) +- Don't fail linting if md5sum for empty files are found in a stub test ([#2571](https://github.com/nf-core/tools/pull/2571)) ### Modules From 471107bb14039dab3c0474b9aef1c71ac164a9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Mir=20Pedrol?= Date: Tue, 12 Dec 2023 10:29:33 +0000 Subject: [PATCH 3/3] add dummy snapshot file content to fix tests --- nf_core/modules/lint/module_tests.py | 79 ++++++++++-------- .../subworkflows/lint/subworkflow_tests.py | 81 ++++++++++--------- tests/test_modules.py | 7 +- tests/test_subworkflows.py | 7 +- 4 files changed, 101 insertions(+), 73 deletions(-) diff --git a/nf_core/modules/lint/module_tests.py b/nf_core/modules/lint/module_tests.py index 86539ab995..1b55b87fcf 100644 --- a/nf_core/modules/lint/module_tests.py +++ b/nf_core/modules/lint/module_tests.py @@ -53,58 +53,67 @@ def module_tests(_, module: NFCoreComponent): ) # Validate no empty files with open(snap_file, "r") as snap_fh: - snap_content = json.load(snap_fh) - for test_name in snap_content.keys(): - if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): - if "stub" not in test_name: - module.failed.append( - ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, + try: + snap_content = json.load(snap_fh) + for test_name in snap_content.keys(): + if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): + if "stub" not in test_name: + module.failed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found, but it is a stub test", + snap_file, + ) ) - ) else: module.passed.append( ( "test_snap_md5sum", - "md5sum for empty file found, but it is a stub test", + "no md5sum for empty file found", snap_file, ) ) - else: - module.passed.append( - ( - "test_snap_md5sum", - "no md5sum for empty file found", - snap_file, - ) - ) - if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): - if "stub" not in test_name: - module.failed.append( - ( - "test_snap_md5sum", - "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", - snap_file, + if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): + if "stub" not in test_name: + module.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", + snap_file, + ) + ) + else: + module.passed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found, but it is a stub test", + snap_file, + ) ) - ) else: module.passed.append( ( "test_snap_md5sum", - "md5sum for compressed empty file found, but it is a stub test", + "no md5sum for compressed empty file found", snap_file, ) ) - else: - module.passed.append( - ( - "test_snap_md5sum", - "no md5sum for compressed empty file found", - snap_file, - ) + except json.decoder.JSONDecodeError as e: + module.failed.append( + ( + "test_snapshot_exists", + f"snapshot file `main.nf.test.snap` can't be read: {e}", + snap_file, ) + ) else: module.failed.append( ("test_snapshot_exists", "snapshot file `main.nf.test.snap` does not exist", snap_file) diff --git a/nf_core/subworkflows/lint/subworkflow_tests.py b/nf_core/subworkflows/lint/subworkflow_tests.py index 2f91efd259..a3bd347d70 100644 --- a/nf_core/subworkflows/lint/subworkflow_tests.py +++ b/nf_core/subworkflows/lint/subworkflow_tests.py @@ -60,58 +60,67 @@ def subworkflow_tests(_, subworkflow: NFCoreComponent): subworkflow.passed.append(("test_snapshot_exists", "test `main.nf.test.snap` exists", snap_file)) # Validate no empty files with open(snap_file, "r") as snap_fh: - snap_content = json.load(snap_fh) - for test_name in snap_content.keys(): - if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): - if "stub" not in test_name: - subworkflow.failed.append( - ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, + try: + snap_content = json.load(snap_fh) + for test_name in snap_content.keys(): + if "d41d8cd98f00b204e9800998ecf8427e" in str(snap_content[test_name]): + if "stub" not in test_name: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", + snap_file, + ) + ) + else: + subworkflow.passed.append( + ( + "test_snap_md5sum", + "md5sum for empty file found, but it is a stub test", + snap_file, + ) ) - ) else: subworkflow.passed.append( ( "test_snap_md5sum", - "md5sum for empty file found, but it is a stub test", + "no md5sum for empty file found", snap_file, ) ) - else: - subworkflow.passed.append( - ( - "test_snap_md5sum", - "no md5sum for empty file found", - snap_file, - ) - ) - if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): - if "stub" not in test_name: - subworkflow.failed.append( - ( - "test_snap_md5sum", - "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", - snap_file, + if "7029066c27ac6f5ef18d660d5741979a" in str(snap_content[test_name]): + if "stub" not in test_name: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a", + snap_file, + ) + ) + else: + subworkflow.failed.append( + ( + "test_snap_md5sum", + "md5sum for compressed empty file found, but it is a stub test", + snap_file, + ) ) - ) else: - subworkflow.failed.append( + subworkflow.passed.append( ( "test_snap_md5sum", - "md5sum for compressed empty file found, but it is a stub test", + "no md5sum for compressed empty file found", snap_file, ) ) - else: - subworkflow.passed.append( - ( - "test_snap_md5sum", - "no md5sum for compressed empty file found", - snap_file, - ) + except json.decoder.JSONDecodeError as e: + subworkflow.failed.append( + ( + "test_snapshot_exists", + f"snapshot file `main.nf.test.snap` can't be read: {e}", + snap_file, ) + ) else: subworkflow.failed.append( ("test_snapshot_exists", "test `main.nf.test.snap` does not exist", snap_file) diff --git a/tests/test_modules.py b/tests/test_modules.py index e2e024a751..6c45ca4412 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -46,12 +46,17 @@ def create_modules_repo_dummy(tmp_dir): # Remove doi from meta.yml which makes lint fail meta_yml_path = Path(root_dir, "modules", "nf-core", "bpipe", "test", "meta.yml") - Path(root_dir, "modules", "nf-core", "bpipe", "test", "tests", "main.nf.test.snap").touch() + with open(meta_yml_path, "r") as fh: meta_yml = yaml.safe_load(fh) del meta_yml["tools"][0]["bpipe"]["doi"] with open(meta_yml_path, "w") as fh: yaml.dump(meta_yml, fh) + # Add dummy content to main.nf.test.snap + test_snap_path = Path(root_dir, "modules", "nf-core", "bpipe", "test", "tests", "main.nf.test.snap") + test_snap_path.touch() + with open(test_snap_path, "w") as fh: + fh.write('{\n "my test": {}\n}') # remove "TODO" statements from main.nf main_nf_path = Path(root_dir, "modules", "nf-core", "bpipe", "test", "main.nf") diff --git a/tests/test_subworkflows.py b/tests/test_subworkflows.py index aaf4080a7b..19872ee168 100644 --- a/tests/test_subworkflows.py +++ b/tests/test_subworkflows.py @@ -33,7 +33,12 @@ def create_modules_repo_dummy(tmp_dir): subworkflow_create = nf_core.subworkflows.SubworkflowCreate(root_dir, "test_subworkflow", "@author", True) subworkflow_create.create() - Path(root_dir, "subworkflows", "nf-core", "test_subworkflow", "tests", "main.nf.test.snap").touch() + # Add dummy content to main.nf.test.snap + test_snap_path = Path(root_dir, "subworkflows", "nf-core", "test_subworkflow", "tests", "main.nf.test.snap") + test_snap_path.touch() + with open(test_snap_path, "w") as fh: + fh.write('{\n "my test": {}\n}') + return root_dir