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 tests for assignment and referencing of params in main.nf #2841

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -21,6 +21,7 @@
- Update GitHub Actions ([#2827](https://github.com/nf-core/tools/pull/2827))
- Switch to setup-nf-test ([#2834](https://github.com/nf-core/tools/pull/2834))
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.3.2 ([#2836](https://github.com/nf-core/tools/pull/2836))
- Add tests for assignment and referencing of params in main.nf ([#2841](https://github.com/nf-core/tools/pull/2841))

## [v2.13.1 - Tin Puppy Patch](https://github.com/nf-core/tools/releases/tag/2.13) - [2024-02-29]

Expand Down
2 changes: 2 additions & 0 deletions nf_core/pipeline-template/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ workflow {
params.input
)

params.max_time == 42
asp8200 marked this conversation as resolved.
Show resolved Hide resolved

//
// WORKFLOW: Run main workflow
//
Expand Down
30 changes: 30 additions & 0 deletions tests/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ def test_default_values_fail(self):
)


def test_catch_params_assignment_in_main_nf(self):
"""Test linting fails if main.nf contains an assignment to a parameter from nextflow_schema.json."""
new_pipeline = self._make_pipeline_copy()
# Change reference of params.max_time to assignment
main_nf_file = Path(new_pipeline) / "main.nf"
with open(main_nf_file) as f:
content = f.read()
fail_content = re.sub(r"params.max_time ==", "params.max_time =", content)
asp8200 marked this conversation as resolved.
Show resolved Hide resolved
print(fail_content)
with open(main_nf_file, "w") as f:
f.write(fail_content)
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()
result = lint_obj.nextflow_config()
assert len(result["failed"]) == 1
assert (
result["failed"][0]
== "Config default value incorrect: `params.max_time` is set as `240.h` in `nextflow_schema.json` but is `null` in `nextflow.config`."
)


def test_allow_params_reference_in_main_nf(self):
"""Test linting allows for references like `params.aligner == 'bwa'` in main.nf. The test will detect if the bug mentioned in GitHub-issue #2833 reemerges."""
new_pipeline = self._make_pipeline_copy()
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()
result = lint_obj.nextflow_config()
assert len(result["failed"]) == 0


def test_default_values_ignored(self):
"""Test ignoring linting of default values."""
new_pipeline = self._make_pipeline_copy()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def test_sphinx_md_files(self):
test_multiqc_incorrect_export_plots,
)
from .lint.nextflow_config import ( # type: ignore[misc]
test_allow_params_reference_in_main_nf,
test_catch_params_assignment_in_main_nf,
test_default_values_fail,
test_default_values_float,
test_default_values_float_fail,
Expand Down
Loading