File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff 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 ):
Original file line number Diff line number Diff line change @@ -59,6 +59,16 @@ def test_condition_table_round_trip():
5959 assert conditions == conditions2
6060
6161
62+ def test_assert_valid ():
63+ problem = petab1to2 (example_dir_fujita / "Fujita.yaml" )
64+ problem .assert_valid ()
65+ problem .observable_tables [0 ] = ObservableTable ()
66+ with pytest .raises (
67+ AssertionError , match = "not defined in the observable table"
68+ ):
69+ problem .assert_valid ()
70+
71+
6272def test_experiment_add_periods ():
6373 """Test operators for Experiment"""
6474 exp = Experiment (id = "exp1" )
You can’t perform that action at this time.
0 commit comments