Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version check in snapshot file #2888

Merged
merged 17 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Linting

- Only match assignments of params in `main.nf` and not references like `params.aligner == <something>` ([#2833](https://github.com/nf-core/tools/pull/2833))
- Include test for presence of versions in snapshot ([#2888](https://github.com/nf-core/tools/pull/2888))

### Download

Expand Down
16 changes: 16 additions & 0 deletions nf_core/modules/lint/module_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ def module_tests(_, module: NFCoreComponent):
snap_file,
)
)
if "versions" in str(snap_content[test_name]):
mashehu marked this conversation as resolved.
Show resolved Hide resolved
module.passed.append(
(
"test_snap_versions",
"versions found in snapshot file",
snap_file,
)
)
else:
module.failed.append(
(
"test_snap_versions",
"versions not found in snapshot file",
snap_file,
)
)
except json.decoder.JSONDecodeError as e:
module.failed.append(
(
Expand Down
16 changes: 16 additions & 0 deletions nf_core/subworkflows/lint/subworkflow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def subworkflow_tests(_, subworkflow: NFCoreComponent):
snap_file,
)
)
if "versions" in str(snap_content[test_name]):
subworkflow.passed.append(
(
"test_snap_versions",
"versions found in snapshot file",
snap_file,
)
)
else:
subworkflow.warned.append(
(
"test_snap_versions",
"versions not found in snapshot file",
snap_file,
)
)
except json.decoder.JSONDecodeError as e:
subworkflow.failed.append(
(
Expand Down
21 changes: 21 additions & 0 deletions tests/modules/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,24 @@ def test_nftest_failing_linting(self):
assert module_lint.failed[2].lint_test == "test_main_tags"
assert "kallisto/index" in module_lint.failed[2].message
assert module_lint.failed[3].lint_test == "test_tags_yml"


def test_modules_absent_version(self):
"""Test linting a nf-test module if the versions is absent in the snapshot file `"""
with open(Path(self.nfcore_modules, "modules", "nf-core", "bpipe", "test", "tests", "main.nf.test.snap")) as fh:
content = fh.read()
new_content = content.replace("versions", "foo")
with open(
Path(self.nfcore_modules, "modules", "nf-core", "bpipe", "test", "tests", "main.nf.test.snap"), "w"
) as fh:
fh.write(new_content)
module_lint = nf_core.modules.ModuleLint(dir=self.nfcore_modules)
module_lint.lint(print_results=False, module="bpipe/test")
with open(
Path(self.nfcore_modules, "modules", "nf-core", "bpipe", "test", "tests", "main.nf.test.snap"), "w"
) as fh:
fh.write(content)
assert len(module_lint.failed) == 1, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
assert len(module_lint.passed) >= 0
assert len(module_lint.warned) >= 0
assert module_lint.failed[0].lint_test == "test_snap_versions"
19 changes: 19 additions & 0 deletions tests/subworkflows/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,22 @@ def test_subworkflows_lint_capitalization_fail(self):

# cleanup
self.subworkflow_remove.remove("bam_stats_samtools", force=True)


def test_subworkflows_absent_version(self):
"""Test linting a nf-test module if the versions is absent in the snapshot file `"""
self.subworkflow_install.install("fastq_align_dna")
with open(Path(self.pipeline_dir, "subworkflows", "nf-core", "fastq_align_dna", "test", "main.nf.test.snap")) as fh:
content = fh.read()
new_content = content.replace("versions", "foo")
with open(
Path(self.pipeline_dir, "subworkflows", "nf-core", "fastq_align_dna", "test", "main.nf.test.snap"), "w"
) as fh:
fh.write(new_content)

subworkflow_lint = nf_core.subworkflows.SubworkflowLint(dir=self.pipeline_dir)
subworkflow_lint.lint(print_results=False, subworkflow="fastq_align_dna")
assert len(subworkflow_lint.failed) == 0
assert len(subworkflow_lint.passed) > 0
assert len(subworkflow_lint.warned) >= 0, f"Linting failed with {[x.__dict__ for x in subworkflow_lint.failed]}"
assert any([x.lint_test == "test_snap_versions" for x in subworkflow_lint.warned])
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def test_modulesrepo_class(self):
test_modules_install_trimgalore_twice,
)
from .modules.lint import ( # type: ignore[misc]
test_modules_absent_version,
test_modules_environment_yml_file_doesnt_exists,
test_modules_environment_yml_file_name_mismatch,
test_modules_environment_yml_file_not_array,
Expand Down
1 change: 1 addition & 0 deletions tests/test_subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def tearDown(self):
test_subworkflows_install_tracking_added_super_subworkflow,
)
from .subworkflows.lint import ( # type: ignore[misc]
test_subworkflows_absent_version,
test_subworkflows_lint,
test_subworkflows_lint_capitalization_fail,
test_subworkflows_lint_empty,
Expand Down
Loading