forked from nf-core/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.py
More file actions
218 lines (186 loc) · 5.94 KB
/
lint.py
File metadata and controls
218 lines (186 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import os
from pathlib import Path
import pytest
import nf_core.modules
from nf_core.modules.lint import main_nf
from ..utils import GITLAB_URL, set_wd
from .patch import BISMARK_ALIGN, CORRECT_SHA, PATCH_BRANCH, REPO_NAME, modify_main_nf
def setup_patch(pipeline_dir, modify_module):
install_obj = nf_core.modules.ModuleInstall(
pipeline_dir, prompt=False, force=False, remote_url=GITLAB_URL, branch=PATCH_BRANCH, sha=CORRECT_SHA
)
# Install the module
install_obj.install(BISMARK_ALIGN)
if modify_module:
# Modify the module
module_path = Path(pipeline_dir, "modules", REPO_NAME, BISMARK_ALIGN)
modify_main_nf(module_path / "main.nf")
def test_modules_lint_trimgalore(self):
"""Test linting the TrimGalore! module"""
self.mods_install.install("trimgalore")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir)
module_lint.lint(print_results=False, module="trimgalore")
assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
def test_modules_lint_empty(self):
"""Test linting a pipeline with no modules installed"""
self.mods_remove.remove("fastqc", force=True)
self.mods_remove.remove("multiqc", force=True)
self.mods_remove.remove("custom/dumpsoftwareversions", force=True)
with pytest.raises(LookupError):
nf_core.modules.ModuleLint(dir=self.pipeline_dir)
def test_modules_lint_new_modules(self):
"""lint a new module"""
module_lint = nf_core.modules.ModuleLint(dir=self.nfcore_modules)
module_lint.lint(print_results=True, all_modules=True)
assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
def test_modules_lint_no_gitlab(self):
"""Test linting a pipeline with no modules installed"""
self.mods_remove.remove("fastqc", force=True)
self.mods_remove.remove("multiqc", force=True)
self.mods_remove.remove("custom/dumpsoftwareversions", force=True)
with pytest.raises(LookupError):
nf_core.modules.ModuleLint(dir=self.pipeline_dir, remote_url=GITLAB_URL)
def test_modules_lint_gitlab_modules(self):
"""Lint modules from a different remote"""
self.mods_install_gitlab.install("fastqc")
self.mods_install_gitlab.install("multiqc")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir, remote_url=GITLAB_URL)
module_lint.lint(print_results=False, all_modules=True)
assert len(module_lint.failed) == 2
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
def test_modules_lint_multiple_remotes(self):
"""Lint modules from a different remote"""
self.mods_install_gitlab.install("multiqc")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir, remote_url=GITLAB_URL)
module_lint.lint(print_results=False, all_modules=True)
assert len(module_lint.failed) == 1
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
def test_modules_lint_patched_modules(self):
"""
Test creating a patch file and applying it to a new version of the the files
"""
setup_patch(self.pipeline_dir, True)
# Create a patch file
patch_obj = nf_core.modules.ModulePatch(self.pipeline_dir, GITLAB_URL, PATCH_BRANCH)
patch_obj.patch(BISMARK_ALIGN)
# change temporarily working directory to the pipeline directory
# to avoid error from try_apply_patch() during linting
with set_wd(self.pipeline_dir):
module_lint = nf_core.modules.ModuleLint(
dir=self.pipeline_dir, remote_url=GITLAB_URL, branch=PATCH_BRANCH, hide_progress=True
)
module_lint.lint(
print_results=False,
all_modules=True,
)
assert len(module_lint.failed) == 1
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
# A skeleton object with the passed/warned/failed list attrs
# Use this in place of a ModuleLint object to test behaviour of
# linting methods which don't need the full setup
class MockModuleLint:
def __init__(self):
self.passed = []
self.warned = []
self.failed = []
self.main_nf = "main_nf"
PROCESS_LABEL_GOOD = (
"""
label process_high
cpus 12
""",
1,
0,
0,
)
PROCESS_LABEL_NON_ALPHANUMERIC = (
"""
label a:label:with:colons
cpus 12
""",
0,
2,
0,
)
PROCESS_LABEL_GOOD_CONFLICTING = (
"""
label process_high
label process_low
cpus 12
""",
0,
1,
0,
)
PROCESS_LABEL_GOOD_DUPLICATES = (
"""
label process_high
label process_high
cpus 12
""",
0,
2,
0,
)
PROCESS_LABEL_GOOD_AND_NONSTANDARD = (
"""
label process_high
label process_extra_label
cpus 12
""",
1,
1,
0,
)
PROCESS_LABEL_NONSTANDARD = (
"""
label process_extra_label
cpus 12
""",
0,
2,
0,
)
PROCESS_LABEL_NONSTANDARD_DUPLICATES = (
"""
label process_extra_label
label process_extra_label
cpus 12
""",
0,
3,
0,
)
PROCESS_LABEL_NONE_FOUND = (
"""
cpus 12
""",
0,
1,
0,
)
PROCESS_LABEL_TEST_CASES = [
PROCESS_LABEL_GOOD,
PROCESS_LABEL_NON_ALPHANUMERIC,
PROCESS_LABEL_GOOD_CONFLICTING,
PROCESS_LABEL_GOOD_DUPLICATES,
PROCESS_LABEL_GOOD_AND_NONSTANDARD,
PROCESS_LABEL_NONSTANDARD,
PROCESS_LABEL_NONSTANDARD_DUPLICATES,
PROCESS_LABEL_NONE_FOUND,
]
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