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

chore: update framework tests to pass under Python 3.12 #1081

Merged
merged 2 commits into from
Nov 23, 2023
Merged
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
14 changes: 12 additions & 2 deletions test/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,26 @@ class MyEvents(ops.ObjectEvents):
with self.assertRaises(RuntimeError) as cm:
class OtherEvents(ops.ObjectEvents): # type: ignore
foo = event
# Python 3.12+ raises the original exception with a note, but earlier
# Python chains the exceptions.
if hasattr(cm.exception, "__notes__"):
cause = str(cm.exception)
else:
cause = str(cm.exception.__cause__)
self.assertEqual(
str(cm.exception.__cause__),
cause,
"EventSource(MyEvent) reused as MyEvents.foo and OtherEvents.foo")

with self.assertRaises(RuntimeError) as cm:
class MyNotifier(ops.Object): # type: ignore
on = MyEvents() # type: ignore
bar = event
if hasattr(cm.exception, "__notes__"):
cause = str(cm.exception)
else:
cause = str(cm.exception.__cause__)
self.assertEqual(
str(cm.exception.__cause__),
cause,
"EventSource(MyEvent) reused as MyEvents.foo and MyNotifier.bar")

def test_reemit_ignores_unknown_event_type(self):
Expand Down
Loading