Skip to content

Commit

Permalink
Merge pull request #67 from tonyandrewmeyer/allow-integer-action-params
Browse files Browse the repository at this point in the history
feat: allow 'integer' as an action param type
  • Loading branch information
PietroPasotti committed Oct 19, 2023
2 parents 55cb4e0 + 29e545b commit ca13b72
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
Expand Up @@ -227,6 +227,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
Expand Up @@ -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():
Expand Down

0 comments on commit ca13b72

Please sign in to comment.