Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions petab/v2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,27 @@ def validate(

return validation_results

def assert_valid(self, **kwargs) -> None:
"""Assert that the PEtab problem is valid.

:param kwargs: Additional arguments passed to :meth:`Problem.validate`.

:raises AssertionError: If the PEtab problem is not valid.
"""
from ..v2.lint import ValidationIssueSeverity

validation_results = self.validate(**kwargs)
errors = [
r
for r in validation_results
if r.level >= ValidationIssueSeverity.ERROR
]
if errors:
raise AssertionError(
"PEtab problem is not valid:\n"
+ "\n".join(e.message for e in errors)
)

def add_condition(
self, id_: str, name: str = None, **kwargs: Number | str | sp.Expr
):
Expand Down
10 changes: 10 additions & 0 deletions tests/v2/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def test_condition_table_round_trip():
assert conditions == conditions2


def test_assert_valid():
problem = petab1to2(example_dir_fujita / "Fujita.yaml")
problem.assert_valid()
problem.observable_tables[0] = ObservableTable()
with pytest.raises(
AssertionError, match="not defined in the observable table"
):
problem.assert_valid()


def test_experiment_add_periods():
"""Test operators for Experiment"""
exp = Experiment(id="exp1")
Expand Down
Loading