Skip to content

Commit

Permalink
Support pre-petab.v1
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Jul 1, 2024
1 parent a5baf29 commit 892ebfa
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions petabtests/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import petab
import yaml
from petab.C import * # noqa: F403
from petab.v1.lint import lint_problem as lint_problem_v1
from petab.v2.lint import lint_problem as lint_problem_v2
from .C import * # noqa: F403

__all__ = [
Expand Down Expand Up @@ -185,17 +183,28 @@ def write_problem(
with open(yaml_path, 'w') as outfile:
yaml.dump(config, outfile, default_flow_style=False)

# validate written PEtab files
if format_version == 1:
# PEtab v1
problem = petab.Problem.from_yaml(yaml_path)
if lint_problem_v1(problem):
raise RuntimeError("Invalid PEtab problem, see messages above.")
else:
# v2
validation_result = lint_problem_v2(yaml_path)
if validation_result:
print(validation_result)
# FIXME Until a first libpetab with petab.v1 subpackage is released
try:
# new petab version
from petab.v1.lint import lint_problem as lint_problem_v1
from petab.v2.lint import lint_problem as lint_problem_v2

# validate written PEtab files
if format_version == 1:
# PEtab v1
problem = petab.Problem.from_yaml(yaml_path)
if lint_problem_v1(problem):
raise RuntimeError("Invalid PEtab problem, see messages above.")
else:
# v2
validation_result = lint_problem_v2(yaml_path)
if validation_result:
print(validation_result)
raise RuntimeError("Invalid PEtab problem, see messages above.")
except ModuleNotFoundError:
# old petab version (will fail validation for some v2 tests)
problem = petab.Problem.from_yaml(os.path.join(dir_, yaml_file))
if petab.lint_problem(problem):
raise RuntimeError("Invalid PEtab problem, see messages above.")


Expand Down

0 comments on commit 892ebfa

Please sign in to comment.