forked from PEtab-dev/libpetab-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lint.py
More file actions
66 lines (49 loc) · 2.24 KB
/
test_lint.py
File metadata and controls
66 lines (49 loc) · 2.24 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
"""Test related to ``petab.v2.lint``."""
from copy import deepcopy
from petab.v2 import Problem
from petab.v2.lint import *
from petab.v2.models.sbml_model import SbmlModel
def test_check_experiments():
"""Test ``CheckExperimentTable``."""
problem = Problem()
check = CheckExperimentTable()
assert check.run(problem) is None
problem.add_experiment("e1", 0, "c1", 1, "c2")
problem.add_experiment("e2", "-inf", "c1", 1, "c2")
assert check.run(problem) is None
tmp_problem = deepcopy(problem)
tmp_problem["e1"].periods[0].time = tmp_problem["e1"].periods[1].time
assert check.run(tmp_problem) is not None
def test_check_incompatible_targets():
"""Multiple conditions with overlapping targets cannot be applied
at the same time."""
problem = Problem()
problem.model = SbmlModel.from_antimony("p1 = 1; p2 = 2")
problem.add_experiment("e1", 0, "c1", 1, "c2")
problem.add_condition("c1", p1="1")
problem.add_condition("c2", p1="2", p2="2")
check = CheckValidConditionTargets()
assert check.run(problem) is None
problem["e1"].periods[0].condition_ids.append("c2")
assert (error := check.run(problem)) is not None
assert "overlapping targets {'p1'}" in error.message
def test_invalid_model_id_in_measurements():
"""Test that measurements with an invalid model ID are caught."""
problem = Problem()
problem.models.append(SbmlModel.from_antimony("p1 = 1", model_id="model1"))
problem.add_observable("obs1", "A")
problem.add_measurement("obs1", experiment_id="e1", time=0, measurement=1)
check = CheckMeasurementModelId()
# Single model -> model ID is optional
assert (error := check.run(problem)) is None, error
# Two models -> model ID must be set
problem.models.append(SbmlModel.from_antimony("p2 = 2", model_id="model2"))
assert (error := check.run(problem)) is not None
assert "multiple models" in error.message
# Set model ID to a non-existing model ID
problem.measurements[0].model_id = "invalid_model_id"
assert (error := check.run(problem)) is not None
assert "does not match" in error.message
# Use a valid model ID
problem.measurements[0].model_id = "model1"
assert (error := check.run(problem)) is None, error