Skip to content

Commit 28e129e

Browse files
committed
Fix petablint for v2 problems
Skip `validate_yaml_semantics` for PEtab v2. Those errors will be caught elsewhere. Closes #428.
1 parent 876c781 commit 28e129e

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

petab/petablint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from jsonschema.exceptions import ValidationError as SchemaValidationError
1313

1414
import petab.v1 as petab
15+
from petab.v1 import validate_yaml_semantics, validate_yaml_syntax
1516
from petab.v1.C import FORMAT_VERSION
16-
from petab.v1.yaml import validate
1717
from petab.versions import get_major_version
1818

1919
logger = logging.getLogger(__name__)
@@ -159,7 +159,7 @@ def main():
159159

160160
if args.yaml_file_name:
161161
try:
162-
validate(args.yaml_file_name)
162+
validate_yaml_syntax(args.yaml_file_name)
163163
except SchemaValidationError as e:
164164
path = ""
165165
if e.absolute_path:
@@ -181,6 +181,8 @@ def main():
181181

182182
match get_major_version(args.yaml_file_name):
183183
case 1:
184+
validate_yaml_semantics(args.yaml_file_name)
185+
184186
if petab.is_composite_problem(args.yaml_file_name):
185187
# TODO: further checking:
186188
# https://github.com/ICB-DCM/PEtab/issues/191

tests/v2/test_core.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import subprocess
12
import tempfile
23
from pathlib import Path
34

@@ -651,3 +652,43 @@ def test_generate_path():
651652
else:
652653
assert gp(Path("foo"), "/bar") == "/bar/foo"
653654
assert gp("/foo", "bar") == "/foo"
655+
656+
657+
def test_petablint_v2(tmpdir):
658+
"""Test petablint on a v2 problem."""
659+
problem = Problem()
660+
problem.model = SbmlModel.from_antimony("""
661+
model conversion
662+
species A, B;
663+
A = 10;
664+
B = 0;
665+
k1 = 1;
666+
k2 = 0.5;
667+
R1: A -> B; k1 * A;
668+
R2: B -> A; k2 * B;
669+
end
670+
""")
671+
problem.add_observable("obs_A", "A", noise_formula="sd_A")
672+
problem.add_parameter(
673+
"k1", estimate=True, lb=1e-5, ub=1e5, nominal_value=1
674+
)
675+
problem.add_parameter(
676+
"k2", estimate=True, lb=1e-5, ub=1e5, nominal_value=0.5
677+
)
678+
problem.add_parameter(
679+
"sd_A", estimate=True, lb=0.01, ub=10, nominal_value=1
680+
)
681+
problem.add_measurement(
682+
"obs_A", time=10, measurement=2.5, experiment_id=""
683+
)
684+
assert problem.validate() == []
685+
686+
problem.config = ProblemConfig(filepath="problem.yaml")
687+
problem.models[0].rel_path = "model.xml"
688+
problem.parameter_tables[0].rel_path = "parameters.tsv"
689+
problem.observable_tables[0].rel_path = "observables.tsv"
690+
problem.measurement_tables[0].rel_path = "measurements.tsv"
691+
problem.to_files(Path(tmpdir))
692+
693+
result = subprocess.run(["petablint", str(Path(tmpdir, "problem.yaml"))]) # noqa: S603,S607
694+
assert result.returncode == 0

0 commit comments

Comments
 (0)