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 all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
- 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))
- optimize layers in dockerfile ([#2842](https://github.com/nf-core/tools/pull/2842))
- Add tests for assignment and referencing of params in main.nf ([#2841](https://github.com/nf-core/tools/pull/2841))
- Optimize layers in dockerfile ([#2842](https://github.com/nf-core/tools/pull/2842))
- Update gitpod/workspace-base Docker digest to 1e133e5 ([#2843](https://github.com/nf-core/tools/pull/2843))

## [v2.13.1 - Tin Puppy Patch](https://github.com/nf-core/tools/releases/tag/2.13) - [2024-02-29]
Expand Down
1 change: 0 additions & 1 deletion nf_core/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ def nextflow_config(self):
schema.load_schema()
schema.get_schema_defaults() # Get default values from schema
schema.get_schema_types() # Get types from schema
self.nf_config.keys() # Params in nextflow.config
for param_name in schema.schema_defaults.keys():
param = "params." + param_name
if param in ignore_defaults:
Expand Down
31 changes: 30 additions & 1 deletion tests/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def test_default_values_fail(self):
with open(nf_schema_file) as f:
content = f.read()
fail_content = re.sub(r'"default": "128.GB"', '"default": "18.GB"', content)
print(fail_content)
with open(nf_schema_file, "w") as f:
f.write(fail_content)
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
Expand All @@ -100,6 +99,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()
# Add parameter assignment in main.nf
main_nf_file = Path(new_pipeline) / "main.nf"
with open(main_nf_file, "a") as f:
f.write("params.max_time = 42")
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()
# Add parameter reference in main.nf
main_nf_file = Path(new_pipeline) / "main.nf"
with open(main_nf_file, "a") as f:
f.write("params.max_time == 42")
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