diff --git a/scenario/consistency_checker.py b/scenario/consistency_checker.py index 9a0ffdd0..b48a16c6 100644 --- a/scenario/consistency_checker.py +++ b/scenario/consistency_checker.py @@ -227,6 +227,7 @@ def _check_action_param_types( to_python_type = { "string": str, "boolean": bool, + "integer": int, "number": Number, "array": Sequence, "object": dict, diff --git a/tests/test_consistency_checker.py b/tests/test_consistency_checker.py index 062f32d4..8afc84c9 100644 --- a/tests/test_consistency_checker.py +++ b/tests/test_consistency_checker.py @@ -304,22 +304,35 @@ def test_action_name(): ) -def test_action_params_type(): - action = Action("foo", params={"bar": "baz"}) +_ACTION_TYPE_CHECKS = [ + ("string", "baz", None), + ("boolean", True, "baz"), + ("integer", 42, 1.5), + ("number", 28.8, "baz"), + ("array", ["a", "b", "c"], 1.5), # A string is an acceptable array. + ("object", {"k": "v"}, "baz"), +] + + +@pytest.mark.parametrize("ptype,good,bad", _ACTION_TYPE_CHECKS) +def test_action_params_type(ptype, good, bad): + action = Action("foo", params={"bar": good}) assert_consistent( State(), action.event, _CharmSpec( - MyCharm, meta={}, actions={"foo": {"params": {"bar": {"type": "string"}}}} - ), - ) - assert_inconsistent( - State(), - action.event, - _CharmSpec( - MyCharm, meta={}, actions={"foo": {"params": {"bar": {"type": "boolean"}}}} + MyCharm, meta={}, actions={"foo": {"params": {"bar": {"type": ptype}}}} ), ) + if bad is not None: + action = Action("foo", params={"bar": bad}) + assert_inconsistent( + State(), + action.event, + _CharmSpec( + MyCharm, meta={}, actions={"foo": {"params": {"bar": {"type": ptype}}}} + ), + ) def test_duplicate_relation_ids():