Skip to content

Commit

Permalink
Merge pull request #2571 from mirpedrol/empty-file-stub
Browse files Browse the repository at this point in the history
Don't fail linting if md5sum for empty files are found in a stub test
  • Loading branch information
mirpedrol authored Dec 14, 2023
2 parents e2b66c0 + 40ee3b2 commit cb787dd
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
85 changes: 57 additions & 28 deletions nf_core/modules/lint/module_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Lint the tests of a module in nf-core/modules
"""
import json
import logging
from pathlib import Path

Expand Down Expand Up @@ -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,
)
)
Expand Down
85 changes: 57 additions & 28 deletions nf_core/subworkflows/lint/subworkflow_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Lint the tests of a subworkflow in nf-core/modules
"""
import json
import logging
from pathlib import Path

Expand Down Expand Up @@ -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,
)
)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion tests/test_subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit cb787dd

Please sign in to comment.