diff --git a/rockcraft/pebble.py b/rockcraft/pebble.py index f62e33ca3..87ff9cc67 100644 --- a/rockcraft/pebble.py +++ b/rockcraft/pebble.py @@ -194,16 +194,18 @@ def _get_check_tag(check: Mapping[str, Any] | _BaseCheck) -> str: return "tcp" if isinstance(check, ExecCheck): return "exec" + if not isinstance(check, Mapping): + raise CraftValidationError(f"Unknown check type for {check!r}.") tags = ("http", "tcp", "exec") - check_types = check.keys() & tags + check_types = [tag for tag in tags if tag in check] match len(check_types): case 0: raise CraftValidationError( f"Must specify exactly one of {', '.join(tags)} for each check." ) case 1: - return check_types.pop() + return check_types[0] case _: raise CraftValidationError( f"Multiple check types specified ({', '.join(sorted(check_types))}). " diff --git a/tests/unit/test_project.py b/tests/unit/test_project.py index 101a3a82f..fe6c4f151 100644 --- a/tests/unit/test_project.py +++ b/tests/unit/test_project.py @@ -19,7 +19,7 @@ import subprocess import warnings from pathlib import Path -from typing import cast +from typing import Any, cast import pydantic import pytest @@ -884,7 +884,8 @@ def test_project_marshal_exec_check_emits_no_pydantic_warning(): warnings.simplefilter("always") dumped = project.marshal() - assert dumped["checks"]["online"]["exec"]["command"] == "/bin/healthcheck" + checks = cast(dict[str, Any], dumped["checks"]) + assert checks["online"]["exec"]["command"] == "/bin/healthcheck" assert not any( "PydanticSerializationUnexpectedValue" in str(w.message) for w in caught )