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
5 changes: 5 additions & 0 deletions petab/v1/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def get_path(filename):
config = ProblemConfig(
**yaml_config, base_path=base_path, filepath=filepath
)
if not config.problems:
raise ValueError(
"The 'problems' section of the PEtab problem YAML file "
"must not be empty."
)
problem0 = config.problems[0]
# currently required for handling PEtab v2 in here
problem0_ = yaml_config["problems"][0]
Expand Down
2 changes: 1 addition & 1 deletion petab/v1/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def is_composite_problem(yaml_config: dict | str | Path) -> bool:
yaml_config: PEtab configuration as dictionary or YAML file name
"""
yaml_config = load_yaml(yaml_config)
return len(yaml_config[PROBLEMS]) > 1
return len(yaml_config.get(PROBLEMS, [])) > 1


def assert_single_condition_and_sbml_file(problem_config: dict) -> None:
Expand Down
23 changes: 23 additions & 0 deletions tests/v1/test_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,29 @@ def test_problem_from_yaml_v1_empty():
petab.Problem.from_yaml(yaml_config)


@pytest.mark.parametrize(
"yaml_config",
[
"""
format_version: 1
parameter_file:
""",
"""
format_version: 1
parameter_file:
problems: []
""",
],
)
def test_problem_from_yaml_v1_empty_problems(yaml_config):
"""Test loading PEtab version 1 yaml with a missing or empty
`problems` section raises a helpful error instead of a raw
KeyError/IndexError"""
yaml_config = safe_load(StringIO(yaml_config))
with pytest.raises(ValueError, match="problems"):
petab.Problem.from_yaml(yaml_config)


def test_problem_from_yaml_v1_multiple_files():
"""Test loading PEtab version 1 yaml with multiple condition / measurement
/ observable files
Expand Down
Loading