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 @@ -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+
6171def test_experiment_add_periods ():
6272 """Test operators for Experiment"""
6373 exp = Experiment (id = "exp1" )
You can’t perform that action at this time.
0 commit comments