Skip to content

Commit

Permalink
Allow 'integer' as an action param type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Oct 16, 2023
1 parent 9a7a706 commit fb307e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions scenario/consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _check_action_param_types(
to_python_type = {
"string": str,
"boolean": bool,
"integer": int,
"number": Number,
"array": Sequence,
"object": dict,
Expand Down
33 changes: 23 additions & 10 deletions tests/test_consistency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit fb307e7

Please sign in to comment.