-
Notifications
You must be signed in to change notification settings - Fork 182
/
module_tests.py
87 lines (73 loc) · 3.5 KB
/
module_tests.py
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
"""
Lint the tests of a module in nf-core/modules
"""
import logging
import os
import yaml
log = logging.getLogger(__name__)
def module_tests(_, module):
"""
Lint the tests of a module in ``nf-core/modules``
It verifies that the test directory exists
and contains a ``main.nf`` and a ``test.yml``,
and that the module is present in the ``pytest_modules.yml``
file.
"""
if os.path.exists(module.test_dir):
module.passed.append(("test_dir_exists", "Test directory exists", module.test_dir))
else:
module.failed.append(("test_dir_exists", "Test directory is missing", module.test_dir))
return
# Lint the test main.nf file
test_main_nf = os.path.join(module.test_dir, "main.nf")
if os.path.exists(test_main_nf):
module.passed.append(("test_main_exists", "test `main.nf` exists", module.test_main_nf))
else:
module.failed.append(("test_main_exists", "test `main.nf` does not exist", module.test_main_nf))
# Check that entry in pytest_modules.yml exists
try:
pytest_yml_path = os.path.join(module.base_dir, "tests", "config", "pytest_modules.yml")
with open(pytest_yml_path, "r") as fh:
pytest_yml = yaml.safe_load(fh)
if module.component_name in pytest_yml.keys():
module.passed.append(("test_pytest_yml", "correct entry in pytest_modules.yml", pytest_yml_path))
else:
module.failed.append(("test_pytest_yml", "missing entry in pytest_modules.yml", pytest_yml_path))
except FileNotFoundError:
module.failed.append(("test_pytest_yml", "Could not open pytest_modules.yml file", pytest_yml_path))
# Lint the test.yml file
try:
with open(module.test_yml, "r") as fh:
test_yml = yaml.safe_load(fh)
# Verify that tags are correct
all_tags_correct = True
for test in test_yml:
for tag in test["tags"]:
if not tag in [module.component_name, module.component_name.split("/")[0]]:
all_tags_correct = False
# Look for md5sums of empty files
for tfile in test.get("files", []):
if tfile.get("md5sum") == "d41d8cd98f00b204e9800998ecf8427e":
module.failed.append(
(
"test_yml_md5sum",
"md5sum for empty file found: d41d8cd98f00b204e9800998ecf8427e",
module.test_yml,
)
)
if tfile.get("md5sum") == "7029066c27ac6f5ef18d660d5741979a":
module.failed.append(
(
"test_yml_md5sum",
"md5sum for compressed empty file found: 7029066c27ac6f5ef18d660d5741979a",
module.test_yml,
)
)
if all_tags_correct:
module.passed.append(("test_yml_tags", "tags adhere to guidelines", module.test_yml))
else:
module.failed.append(("test_yml_tags", "tags do not adhere to guidelines", module.test_yml))
# Test that the file exists
module.passed.append(("test_yml_exists", "Test `test.yml` exists", module.test_yml))
except FileNotFoundError:
module.failed.append(("test_yml_exists", "Test `test.yml` does not exist", module.test_yml))