Skip to content

Commit

Permalink
Handle Python 3.12 behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Nov 23, 2023
1 parent 26c6e95 commit 43d0a91
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit 43d0a91

Please sign in to comment.