Skip to content

Commit 72afccb

Browse files
authored
Merge branch 'main' into validate_initial_changes
2 parents 48a4334 + 5c964a1 commit 72afccb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

petab/v2/core.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,27 @@ def validate(
19011901

19021902
return validation_results
19031903

1904+
def assert_valid(self, **kwargs) -> None:
1905+
"""Assert that the PEtab problem is valid.
1906+
1907+
:param kwargs: Additional arguments passed to :meth:`Problem.validate`.
1908+
1909+
:raises AssertionError: If the PEtab problem is not valid.
1910+
"""
1911+
from ..v2.lint import ValidationIssueSeverity
1912+
1913+
validation_results = self.validate(**kwargs)
1914+
errors = [
1915+
r
1916+
for r in validation_results
1917+
if r.level >= ValidationIssueSeverity.ERROR
1918+
]
1919+
if errors:
1920+
raise AssertionError(
1921+
"PEtab problem is not valid:\n"
1922+
+ "\n".join(e.message for e in errors)
1923+
)
1924+
19041925
def add_condition(
19051926
self, id_: str, name: str = None, **kwargs: Number | str | sp.Expr
19061927
):

tests/v2/test_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ def test_condition_table_round_trip():
5858
assert conditions == conditions2
5959

6060

61+
def test_assert_valid():
62+
problem = petab1to2(example_dir_fujita / "Fujita.yaml")
63+
problem.assert_valid()
64+
problem.observable_tables[0] = ObservableTable()
65+
with pytest.raises(
66+
AssertionError, match="not defined in the observable table"
67+
):
68+
problem.assert_valid()
69+
70+
6171
def test_experiment_add_periods():
6272
"""Test operators for Experiment"""
6373
exp = Experiment(id="exp1")

0 commit comments

Comments
 (0)