diff --git a/CHANGELOG.md b/CHANGELOG.md index c453c79abd..80e28b6da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,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 ([#2571](https://github.com/nf-core/tools/pull/2571)) ### Modules diff --git a/nf_core/modules/lint/module_tests.py b/nf_core/modules/lint/module_tests.py index 1a18482972..1b55b87fcf 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,36 +53,64 @@ 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: + 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", + "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, + ) + ) + except json.decoder.JSONDecodeError as e: module.failed.append( ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, - ) - ) - else: - module.passed.append( - ( - "test_snap_md5sum", - "no md5sum for 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", + "test_snapshot_exists", + f"snapshot file `main.nf.test.snap` can't be read: {e}", snap_file, ) ) diff --git a/nf_core/subworkflows/lint/subworkflow_tests.py b/nf_core/subworkflows/lint/subworkflow_tests.py index 044c70b392..a3bd347d70 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,36 +60,64 @@ 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: + 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", + "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, + ) + ) + except json.decoder.JSONDecodeError as e: subworkflow.failed.append( ( - "test_snap_md5sum", - "md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e", - snap_file, - ) - ) - else: - subworkflow.passed.append( - ( - "test_snap_md5sum", - "no md5sum for 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", + "test_snapshot_exists", + f"snapshot file `main.nf.test.snap` can't be read: {e}", 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