-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_mip_config.py
149 lines (126 loc) · 4.19 KB
/
test_mip_config.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
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
"""Tests for the config functionality"""
import pytest
from trailblazer.mip import config as tb_config
from trailblazer.exc import ConfigError
def test_validate_config():
"""Test to validate a correct config"""
# GIVEN a correct config
sample = dict(
sample_id = "sample",
analysis_type = 'wes',
father = '0',
mother = '0',
phenotype = 'affected',
sex = 'male',
expected_coverage = 15,
capture_kit = 'agilent_sureselect_cre.v1',
)
config = dict(
case = "a_case",
default_gene_panels = ["a_panel"],
samples = [sample],
)
# WHEN validating the config
errors = tb_config.ConfigHandler.validate_config(config)
# THEN assert the errors is a dict
assert isinstance(errors, dict)
# THEN assert there where no errors
assert errors == {}
def test_validate_config_invalid_analysis_type():
"""Test to validate a invalid config with wrong analysis type"""
# GIVEN a correct config
sample = dict(
sample_id = "sample",
analysis_type = 'nonexisting',
father = '0',
mother = '0',
phenotype = 'affected',
sex = 'male',
expected_coverage = 15,
capture_kit = 'agilent_sureselect_cre.v1',
)
config = dict(
case = "a_case",
default_gene_panels = ["a_panel"],
samples = [sample],
)
# WHEN validating the config
with pytest.raises(ConfigError):
# THEN assert a config error is raised
tb_config.ConfigHandler.validate_config(config)
def test_validate_config_unknown_field():
"""Test to validate a config with a unspecified field.
This should work since we allow unspecified fields
"""
# GIVEN a correct config with a extra field
sample = dict(
sample_id = "sample",
sample_display_name = "ASAMPLENAME",
analysis_type = 'wes',
father = '0',
mother = '0',
phenotype = 'affected',
sex = 'male',
expected_coverage = 15,
capture_kit = 'agilent_sureselect_cre.v1',
)
config = dict(
case = "a_case",
default_gene_panels = ["a_panel"],
samples = [sample],
)
# WHEN validating the config
errors = tb_config.ConfigHandler.validate_config(config)
# THEN assert the errors is a dict
assert isinstance(errors, dict)
# THEN assert there where one error that could pass
assert len(errors) == 1
def test_validate_config_unknown_field_and_missing_sample_id():
"""Test to validate a config with a unspecified field and a missing mandatory field.
This should raise exception since we do not allow missing mandatory fields
"""
# GIVEN a config with missing sample_id and an extra field
sample = dict(
sample_display_name = "ASAMPLENAME",
analysis_type = 'wes',
father = '0',
mother = '0',
phenotype = 'affected',
sex = 'male',
expected_coverage = 15,
capture_kit = 'agilent_sureselect_cre.v1',
)
config = dict(
case = "a_case",
default_gene_panels = ["a_panel"],
samples = [sample],
)
# WHEN validating the config
with pytest.raises(ConfigError):
# THEN assert a config error is raised
tb_config.ConfigHandler.validate_config(config)
def test_validate_config_unknown_field_and_invalid_analysis_type():
"""Test to validate a config with a unspecified field and a missing mandatory field.
This should raise exception since we do not allow wrong analysis types
"""
# GIVEN a config with wrong analysis type and an extra field
sample = dict(
sample_id = "sample",
sample_display_name = "ASAMPLENAME",
analysis_type = 'nonexisting',
father = '0',
mother = '0',
phenotype = 'affected',
sex = 'male',
expected_coverage = 15,
capture_kit = 'agilent_sureselect_cre.v1',
)
config = dict(
case = "a_case",
default_gene_panels = ["a_panel"],
samples = [sample],
)
# WHEN validating the config
with pytest.raises(ConfigError):
# THEN assert a config error is raised
tb_config.ConfigHandler.validate_config(config)