Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that event is set when using an _Event object #26

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
tonyandrewmeyer marked this conversation as resolved.
Show resolved Hide resolved
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
Loading