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
6 changes: 4 additions & 2 deletions petab/petablint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from jsonschema.exceptions import ValidationError as SchemaValidationError

import petab.v1 as petab
from petab.v1 import validate_yaml_semantics, validate_yaml_syntax
from petab.v1.C import FORMAT_VERSION
from petab.v1.yaml import validate
from petab.versions import get_major_version

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -159,7 +159,7 @@ def main():

if args.yaml_file_name:
try:
validate(args.yaml_file_name)
validate_yaml_syntax(args.yaml_file_name)
except SchemaValidationError as e:
path = ""
if e.absolute_path:
Expand All @@ -181,6 +181,8 @@ def main():

match get_major_version(args.yaml_file_name):
case 1:
validate_yaml_semantics(args.yaml_file_name)

if petab.is_composite_problem(args.yaml_file_name):
# TODO: further checking:
# https://github.com/ICB-DCM/PEtab/issues/191
Expand Down
41 changes: 41 additions & 0 deletions tests/v2/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
import tempfile
from pathlib import Path

Expand Down Expand Up @@ -666,3 +667,43 @@ def test_generate_path():
else:
assert gp(Path("foo"), "/bar") == "/bar/foo"
assert gp("/foo", "bar") == "/foo"


def test_petablint_v2(tmpdir):
"""Test that petablint runs on a valid v2 problem without errors."""
problem = Problem()
problem.model = SbmlModel.from_antimony("""
model conversion
species A, B;
A = 10;
B = 0;
k1 = 1;
k2 = 0.5;
R1: A -> B; k1 * A;
R2: B -> A; k2 * B;
end
""")
problem.add_observable("obs_A", "A", noise_formula="sd_A")
problem.add_parameter(
"k1", estimate=True, lb=1e-5, ub=1e5, nominal_value=1
)
problem.add_parameter(
"k2", estimate=True, lb=1e-5, ub=1e5, nominal_value=0.5
)
problem.add_parameter(
"sd_A", estimate=True, lb=0.01, ub=10, nominal_value=1
)
problem.add_measurement(
"obs_A", time=10, measurement=2.5, experiment_id=""
)
assert problem.validate() == []

problem.config = ProblemConfig(filepath="problem.yaml")
problem.models[0].rel_path = "model.xml"
problem.parameter_tables[0].rel_path = "parameters.tsv"
problem.observable_tables[0].rel_path = "observables.tsv"
problem.measurement_tables[0].rel_path = "measurements.tsv"
problem.to_files(Path(tmpdir))

result = subprocess.run(["petablint", str(Path(tmpdir, "problem.yaml"))]) # noqa: S603,S607
assert result.returncode == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine as is, but I would normally opt for asserting that more specific output is the same, rather than something that might be coincidentally the same, like a return code of 0. e.g. see the same error in problem.validate and result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's specifically to check that there is no uncaught exception. This feels sufficient and avoids having to update the test if some message changes.

Copy link
Member

@dilpath dilpath Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks good then. Could add that to the description or test name.

Loading