Skip to content

Commit

Permalink
Fix test cases and ensure test is run. Make sure label linting method…
Browse files Browse the repository at this point in the history
… is called
  • Loading branch information
awgymer committed Apr 26, 2023
1 parent ee0b95b commit d593f86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 4 additions & 3 deletions nf_core/modules/lint/main_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def check_process_section(self, lines, fix_version, progress_bar):
self.failed.append(("process_capitals", "Process name is not in capital letters", self.main_nf))

# Check that process labels are correct
check_process_labels(self, lines)

# Deprecated enable_conda
for i, l in enumerate(lines):
Expand Down Expand Up @@ -393,13 +394,13 @@ def check_process_section(self, lines, fix_version, progress_bar):

def check_process_labels(self, lines):
correct_process_labels = ["process_single", "process_low", "process_medium", "process_high", "process_long"]
all_labels = [l for l in lines if l.lstrip().startswith("label ")]
all_labels = [l.strip() for l in lines if l.lstrip().startswith("label ")]
bad_labels = []
good_labels = []
if len(all_labels) > 0:
for label in all_labels:
try:
label = re.match("^label\s+([a-zA-Z0-9_-]+)", label).group(1)
label = re.match("^label\s+([a-zA-Z0-9_-]+)$", label).group(1)
except AttributeError:
self.warned.append(
(
Expand Down Expand Up @@ -427,7 +428,7 @@ def check_process_labels(self, lines):
self.warned.append(("process_standard_label", "Standard process label not found", self.main_nf))
if len(bad_labels) > 0:
self.warned.append(
("process_standard_label", f"Non-standard labels found: `{'`,`'.join(good_labels)}`", self.main_nf)
("process_standard_label", f"Non-standard labels found: `{'`,`'.join(bad_labels)}`", self.main_nf)
)
if len(all_labels) > len(set(all_labels)):
self.warned.append(
Expand Down
23 changes: 13 additions & 10 deletions tests/modules/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __init__(self):
self.warned = []
self.failed = []

self.main_nf = "main_nf"


PROCESS_LABEL_GOOD = (
"""
Expand All @@ -133,7 +135,7 @@ def __init__(self):
cpus 12
""",
0,
1,
2,
0,
)
PROCESS_LABEL_GOOD_CONFLICTING = (
Expand Down Expand Up @@ -163,7 +165,7 @@ def __init__(self):
cpus 12
""",
1,
2,
1,
0,
)
PROCESS_LABEL_NONSTANDARD = (
Expand All @@ -172,7 +174,7 @@ def __init__(self):
cpus 12
""",
0,
1,
2,
0,
)
PROCESS_LABEL_NONSTANDARD_DUPLICATES = (
Expand Down Expand Up @@ -206,10 +208,11 @@ def __init__(self):
]


@pytest.mark.parametrize("lines,passed,warned,failed", PROCESS_LABEL_TEST_CASES)
def test_modules_lint_check_process_labels(self, lines, passed, warned, failed):
mocked_ModuleLint = MockModuleLint()
main_nf.check_process_labels(mocked_ModuleLint, lines)
assert len(mocked_ModuleLint.passed) == passed
assert len(mocked_ModuleLint.warned) == warned
assert len(mocked_ModuleLint.failed) == failed
def test_modules_lint_check_process_labels(self):
for test_case in PROCESS_LABEL_TEST_CASES:
process, passed, warned, failed = test_case
mocked_ModuleLint = MockModuleLint()
main_nf.check_process_labels(mocked_ModuleLint, process.splitlines())
assert len(mocked_ModuleLint.passed) == passed
assert len(mocked_ModuleLint.warned) == warned
assert len(mocked_ModuleLint.failed) == failed
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_modulesrepo_class(self):
test_modules_install_trimgalore_twice,
)
from .modules.lint import (
test_modules_lint_check_process_labels,
test_modules_lint_empty,
test_modules_lint_gitlab_modules,
test_modules_lint_multiple_remotes,
Expand Down

0 comments on commit d593f86

Please sign in to comment.