Repository: canonical/operator
Pull request #203 (2020-04-01 08:46:19)

ops, test: revert the EventSet change, make EventsBase ObjectEvents
Feedback from users is that the EventSet isn't good, both because of
new inconsistency (why FrameworkEventSet and not CharmEventSet), and
because they aren't sets in the python sense.

@stub42 suggested ObjectEvents as a reasonable name for what used to
be EventsBase, and we're running with it.

dshcherb: It makes more sense but also carves `Object` in stone.

Patch:
diff --git a/ops/charm.py b/ops/charm.py
index e4db6aa..905a444 100755
--- a/ops/charm.py
+++ b/ops/charm.py
@@ -16,7 +16,7 @@ import os
 
 import yaml
 
-from ops.framework import Object, EventSource, EventBase, EventSetBase
+from ops.framework import Object, EventSource, EventBase, ObjectEvents
 
 
 class HookEvent(EventBase):
@@ -378,7 +378,7 @@ class StorageDetachingEvent(StorageEvent):
     pass
 
 
-class CharmEvents(EventSetBase):
+class CharmEvents(ObjectEvents):
     """The events that are generated by Juju in response to the lifecycle of an application."""
 
     install = EventSource(InstallEvent)
diff --git a/ops/framework.py b/ops/framework.py
index 343d81d..857035d 100755
--- a/ops/framework.py
+++ b/ops/framework.py
@@ -275,7 +275,7 @@ class Object(metaclass=_Metaclass):
         return self.framework.model
 
 
-class EventSetBase(Object):
+class ObjectEvents(Object):
     """Convenience type to allow defining .on attributes at class level."""
 
     handle_kind = "on"
@@ -362,7 +362,7 @@ class CommitEvent(EventBase):
     pass
 
 
-class FrameworkEventSet(EventSetBase):
+class FrameworkEvents(ObjectEvents):
     pre_commit = EventSource(PreCommitEvent)
     commit = EventSource(CommitEvent)
 
@@ -488,7 +488,7 @@ More details at https://discourse.jujucharms.com/t/debugging-charm-hooks
 
 class Framework(Object):
 
-    on = FrameworkEventSet()
+    on = FrameworkEvents()
 
     # Override properties from Object so that we can set them in __init__.
     model = None


Test patch:
diff --git a/test/test_framework.py b/test/test_framework.py
index 699b64b..85143fd 100644
--- a/test/test_framework.py
+++ b/test/test_framework.py
@@ -29,7 +29,7 @@ from ops.framework import (
     BoundStoredState,
     CommitEvent,
     EventBase,
-    EventSetBase,
+    ObjectEvents,
     EventSource,
     Framework,
     Handle,
@@ -392,7 +392,7 @@ class TestFramework(unittest.TestCase):
         class MyEvent(EventBase):
             pass
 
-        class MyEvents(EventSetBase):
+        class MyEvents(ObjectEvents):
             foo = EventSource(MyEvent)
 
         class MyNotifier(Object):
@@ -489,7 +489,7 @@ class TestFramework(unittest.TestCase):
         class MyEvent(EventBase):
             pass
 
-        class MyEvents(EventSetBase):
+        class MyEvents(ObjectEvents):
             foo = EventSource(MyEvent)
             bar = EventSource(MyEvent)
 
@@ -527,11 +527,11 @@ class TestFramework(unittest.TestCase):
 
         event = EventSource(MyEvent)
 
-        class MyEvents(EventSetBase):
+        class MyEvents(ObjectEvents):
             foo = event
 
         with self.assertRaises(RuntimeError) as cm:
-            class OtherEvents(EventSetBase):
+            class OtherEvents(ObjectEvents):
                 foo = event
         self.assertEqual(
             str(cm.exception),
@@ -596,7 +596,7 @@ class TestFramework(unittest.TestCase):
         class MyBar(EventBase):
             pass
 
-        class MyEvents(EventSetBase):
+        class MyEvents(ObjectEvents):
             foo = EventSource(MyFoo)
 
         class MyNotifier(Object):
@@ -633,10 +633,10 @@ class TestFramework(unittest.TestCase):
     def test_dynamic_event_types(self):
         framework = self.create_framework()
 
-        class MyEventsA(EventSetBase):
+        class MyEventsA(ObjectEvents):
             handle_kind = 'on_a'
 
-        class MyEventsB(EventSetBase):
+        class MyEventsB(ObjectEvents):
             handle_kind = 'on_b'
 
         class MyNotifier(Object):
@@ -770,12 +770,12 @@ class TestFramework(unittest.TestCase):
         # this can not be saved, as it has not simple types!
         to_be_saved = {"bar": TestFramework}
 
-        class FooEvent(EventSetBase):
+        class FooEvent(EventBase):
             def snapshot(self):
                 return to_be_saved
 
         handle = Handle(None, "a_foo", "some_key")
-        event = FooEvent()
+        event = FooEvent(handle)
 
         framework = self.create_framework()
         framework.register_type(FooEvent, None, handle.kind)