Repository navigation
Expand file tree
/
Copy pathtest_config.py
More file actions
155 lines (117 loc) · 4.29 KB
/
Copy pathtest_config.py
File metadata and controls
155 lines (117 loc) · 4.29 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
"""Test the configuration interface."""
from pathlib import Path
import pytest
from micom.batch import Configuration
def test_config():
"""Test the configuration interface."""
conf = Configuration()
assert conf.simulation.flux_method == "minimal imports"
assert conf.tolerance == 1e-6
def test_simulation_config():
"""Test the simulation configuration interface."""
conf = Configuration()
conf.simulation.flux_method = "pFBA"
assert conf.simulation.flux_method == "pFBA"
with pytest.raises(ValueError):
conf.simulation.flux_method = "invalid"
def test_dbs_config():
"""Test the dbs configuration interface."""
conf = Configuration()
assert conf.dbs.microbial is not None
conf.dbs.microbial = None
assert conf.dbs.microbial is None
with pytest.raises(ValueError):
conf.dbs.microbial = 12
conf.dbs.host = {
"enterocytes": "/home/test/test.sbml",
"goblet_cells": "/home/test/goblet_cells.xml",
}
assert conf.dbs.host["enterocytes"].name == "test.sbml"
with pytest.raises(ValueError):
conf.dbs.host = "default://test.sbml"
conf.dbs.download_location = Path("/home/test/downloads")
assert conf.dbs.download_location.name == "downloads"
with pytest.raises(ValueError):
conf.dbs.download_location = None
def test_media_config():
"""Test the media configuration interface."""
conf = Configuration()
assert conf.media.max_import == 10.0
conf.media.max_import = 5.0
assert conf.media.max_import == 5.0
with pytest.raises(ValueError):
conf.media.max_import = "large"
def test_coupling_config():
"""Test the coupling configuration interface."""
conf = Configuration()
assert conf.coupling.enabled is True
conf.coupling.enabled = False
assert conf.coupling.enabled is False
with pytest.raises(ValueError):
conf.coupling.strategy = "invalid"
conf.coupling.strategy = "resource constraint"
assert conf.coupling.strategy == "resource constraint"
with pytest.raises(ValueError):
conf.coupling.constraint = "high"
def test_build_config():
"""Test the build configuration interface."""
conf = Configuration()
assert conf.build.cutoff == 1e-4
conf.build.cutoff = 1e-3
assert conf.build.cutoff == 1e-3
with pytest.raises(ValueError):
conf.build.cutoff = "low"
def test_config_json(tmp_path):
"""Test the configuration json interface."""
conf = Configuration()
conf.simulation.flux_method = "pFBA"
conf.dbs.microbial = None
conf.media.max_import = 5.0
conf.coupling.enabled = False
conf.build.cutoff = 1e-3
conf_file = tmp_path / "config.json"
conf.to_json(conf_file)
assert conf_file.exists()
new_conf = Configuration.from_json(conf_file)
assert new_conf.simulation.flux_method == "pFBA"
assert new_conf.dbs.microbial is None
assert new_conf.media.max_import == 5.0
assert new_conf.coupling.enabled is False
assert new_conf.build.cutoff == 1e-3
def test_config_yaml(tmp_path):
"""Test the configuration yaml interface."""
conf = Configuration()
conf.simulation.flux_method = "pFBA"
conf.dbs.microbial = None
conf.media.max_import = 5.0
conf.coupling.enabled = False
conf.build.cutoff = 1e-3
conf_file = tmp_path / "config.yaml"
conf.to_yaml(conf_file)
assert conf_file.exists()
new_conf = Configuration.from_yaml(conf_file)
assert new_conf.simulation.flux_method == "pFBA"
assert new_conf.dbs.microbial is None
assert new_conf.media.max_import == 5.0
assert new_conf.coupling.enabled is False
assert new_conf.build.cutoff == 1e-3
def test_config_str():
"""Test the configuration string representation."""
conf = Configuration()
conf_str = str(conf)
assert "Configuration" in conf_str
assert "simulation" in conf_str
assert "coupling" in conf_str
assert "build" in conf_str
assert "dbs" in conf_str
assert "media" in conf_str
def test_config_repr_html():
"""Test the configuration HTML representation."""
conf = Configuration()
html_str = conf._repr_html_()
assert "<li>" in html_str
assert "simulation" in html_str
assert "coupling" in html_str
assert "build" in html_str
assert "dbs" in html_str
assert "media" in html_str