From fb307e7b9421f4909ab677aa0e438cc4f96daf23 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 16 Oct 2023 16:50:42 +1300 Subject: [PATCH] Allow 'integer' as an action param type. --- scenario/consistency_checker.py | 1 + tests/test_consistency_checker.py | 33 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/scenario/consistency_checker.py b/scenario/consistency_checker.py index 52d62649..f4a89425 100644 --- a/scenario/consistency_checker.py +++ b/scenario/consistency_checker.py @@ -199,6 +199,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 e26fb3ad..159d4964 100644 --- a/tests/test_consistency_checker.py +++ b/tests/test_consistency_checker.py @@ -303,22 +303,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():