Skip to content

Commit

Permalink
Merge pull request #26 from tonyandrewmeyer/fix-event-type
Browse files Browse the repository at this point in the history
fix: ensure that `event` is set when using an `_Event` object
  • Loading branch information
tonyandrewmeyer authored Sep 25, 2024
2 parents d86bb2a + 36a8e1a commit 7d71c97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions interface_tester/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ def _cast_event(self, raw_event: Union[str, _Event], relation: Relation):
raise InvalidTestCaseError(
f"Bad interface test specification: event {raw_event} is not a relation event."
)
else:
event = raw_event

# todo: if the user passes a relation event that is NOT about the relation
# interface that this test is about, at this point we are injecting the wrong
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pytest-interface-tester"

version = "3.1.1"
version = "3.1.2"
authors = [
{ name = "Pietro Pasotti", email = "[email protected]" },
]
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ def test_data_on_changed():
tester.run()


def test_run_with_charmevents():
tester = _setup_with_test_file(
dedent(
"""
from scenario import State, Relation
from scenario.context import CharmEvents
from interface_tester.interface_test import Tester
def test_data_on_changed():
relation = Relation(
endpoint='foobadooble',
interface='tracing',
remote_app_name='remote',
local_app_data={},
)
t = Tester(State(relations={relation}))
state_out = t.run(CharmEvents.relation_changed(relation))
t.assert_schema_valid()
"""
)
)

with pytest.raises(NoSchemaError):
tester.run()


def test_error_if_assert_schema_without_schema():
tester = _setup_with_test_file(
dedent(
Expand Down

0 comments on commit 7d71c97

Please sign in to comment.