Skip to content

Commit de974ba

Browse files
authored
Fix petablint for v2 problems (#432)
Skip `validate_yaml_semantics` for PEtab v2. Those errors will be caught elsewhere. Closes #428.
1 parent 89e9fec commit de974ba

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

@@ -666,3 +667,43 @@ def test_generate_path():
666667
else:
667668
assert gp(Path("foo"), "/bar") == "/bar/foo"
668669
assert gp("/foo", "bar") == "/foo"
670+
671+
672+
def test_petablint_v2(tmpdir):
673+
"""Test that petablint runs on a valid v2 problem without errors."""
674+
problem = Problem()
675+
problem.model = SbmlModel.from_antimony("""
676+
model conversion
677+
species A, B;
678+
A = 10;
679+
B = 0;
680+
k1 = 1;
681+
k2 = 0.5;
682+
R1: A -> B; k1 * A;
683+
R2: B -> A; k2 * B;
684+
end
685+
""")
686+
problem.add_observable("obs_A", "A", noise_formula="sd_A")
687+
problem.add_parameter(
688+
"k1", estimate=True, lb=1e-5, ub=1e5, nominal_value=1
689+
)
690+
problem.add_parameter(
691+
"k2", estimate=True, lb=1e-5, ub=1e5, nominal_value=0.5
692+
)
693+
problem.add_parameter(
694+
"sd_A", estimate=True, lb=0.01, ub=10, nominal_value=1
695+
)
696+
problem.add_measurement(
697+
"obs_A", time=10, measurement=2.5, experiment_id=""
698+
)
699+
assert problem.validate() == []
700+
701+
problem.config = ProblemConfig(filepath="problem.yaml")
702+
problem.models[0].rel_path = "model.xml"
703+
problem.parameter_tables[0].rel_path = "parameters.tsv"
704+
problem.observable_tables[0].rel_path = "observables.tsv"
705+
problem.measurement_tables[0].rel_path = "measurements.tsv"
706+
problem.to_files(Path(tmpdir))
707+
708+
result = subprocess.run(["petablint", str(Path(tmpdir, "problem.yaml"))]) # noqa: S603,S607
709+
assert result.returncode == 0

0 commit comments

Comments
 (0)