Skip to content

Commit

Permalink
Merge branch 'main' into math_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Jul 1, 2024
2 parents 47be74b + 07beeae commit 24d926d
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 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,32 @@ 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 24d926d

Please sign in to comment.