Skip to content

Commit

Permalink
Merge pull request #2478 from fa2k/add-test-for-test-profile
Browse files Browse the repository at this point in the history
Add lint test to check existence of test profile
  • Loading branch information
fa2k authored Oct 18, 2023
2 parents 873da41 + 9457021 commit 66dbf0b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions nf_core/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def nextflow_config(self):
lint:
nextflow_config: False
**The configuration should contain the following or the test will fail:**
* A ``test`` configuration profile should exist.
"""
passed = []
warned = []
Expand Down Expand Up @@ -312,4 +317,32 @@ def nextflow_config(self):
)
)

# Check for the availability of the "test" configuration profile by parsing nextflow.config
with open(os.path.join(self.wf_path, "nextflow.config"), "r") as f:
content = f.read()

# Remove comments
cleaned_content = re.sub(r"//.*", "", content)
cleaned_content = re.sub(r"/\*.*?\*/", "", content, flags=re.DOTALL)

match = re.search(r"\bprofiles\s*{", cleaned_content)
if not match:
failed.append("nextflow.config does not contain `profiles` scope, but `test` profile is required")
else:
# Extract profiles scope content and check for test profile
start = match.end()
end = start
brace_count = 1
while brace_count > 0 and end < len(content):
if cleaned_content[end] == "{":
brace_count += 1
elif cleaned_content[end] == "}":
brace_count -= 1
end += 1
profiles_content = cleaned_content[start : end - 1].strip()
if re.search(r"\btest\s*{", profiles_content):
passed.append("nextflow.config contains configuration profile `test`")
else:
failed.append("nextflow.config does not contain configuration profile `test`")

return {"passed": passed, "warned": warned, "failed": failed, "ignored": ignored}
20 changes: 20 additions & 0 deletions tests/lint/nextflow_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import re

import nf_core.create
import nf_core.lint

Expand Down Expand Up @@ -33,3 +36,20 @@ def test_nextflow_config_dev_in_release_mode_failed(self):
result = lint_obj.nextflow_config()
assert len(result["failed"]) > 0
assert len(result["warned"]) == 0


def test_nextflow_config_missing_test_profile_failed(self):
"""Test failure if config file does not contain `test` profile."""
new_pipeline = self._make_pipeline_copy()
# Change the name of the test profile so there is no such profile
nf_conf_file = os.path.join(new_pipeline, "nextflow.config")
with open(nf_conf_file, "r") as f:
content = f.read()
fail_content = re.sub(r"\btest\b", "testfail", content)
with open(nf_conf_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"]) > 0
assert len(result["warned"]) == 0
1 change: 1 addition & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_sphinx_md_files(self):
test_nextflow_config_bad_name_fail,
test_nextflow_config_dev_in_release_mode_failed,
test_nextflow_config_example_pass,
test_nextflow_config_missing_test_profile_failed,
)
from .lint.version_consistency import test_version_consistency

Expand Down

0 comments on commit 66dbf0b

Please sign in to comment.