Repository: canonical/operator
Pull request #191 (2020-03-26 18:38:01)

Renamed EventsBase to EventSetBase (and derivatives)
This is per what we discussed in Frankfurt, as EventsBase was too confusing with EventBase, and we agreed on Signal to name it EventSetBase.

Also for the files I changed I updated copyright years, and removed execution infrastructure of the test (as we're using proper test runners).

chipaca: @jameinel hm, I think we should also rename the remaining three, don't you?
That is: `CharmEvents`, `PrefixedEvents`, and `StoredStateEvents`.

jameinel: CharmEvents honestly reads quite nicely. I'm not opposed to calling it
ChamEventSet, but CharmEvents does read better to me.


On Mon, Mar 30, 2020 at 1:05 PM John R. Lenton <notifications@github.com>
wrote:

> @jameinel <https://github.com/jameinel> hm, I think we should also rename
> the remaining three, don't you?
> That is: CharmEvents, PrefixedEvents, and StoredStateEvents.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/canonical/operator/pull/191#issuecomment-605875917>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AABRQ7PFXB3YM2TDLMZ3B53RKBOENANCNFSM4LUONUHA>
> .
>

chipaca: that's a good point, there isn't the tension there was with `EventBase` vs `EventsBase`; `FooEvents` is probably fine.
OK.

Patch:
diff --git a/ops/charm.py b/ops/charm.py
index e88286a..a85b37c 100755
--- a/ops/charm.py
+++ b/ops/charm.py
@@ -1,4 +1,4 @@
-# Copyright 2019 Canonical Ltd.
+# Copyright 2019-2020 Canonical Ltd.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@ import os
 
 import yaml
 
-from ops.framework import Object, EventSource, EventBase, EventsBase
+from ops.framework import Object, EventSource, EventBase, EventSetBase
 
 
 class HookEvent(EventBase):
@@ -369,7 +369,7 @@ class StorageDetachingEvent(StorageEvent):
     pass
 
 
-class CharmEvents(EventsBase):
+class CharmEvents(EventSetBase):
     """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 b83d551..abdd1fe 100755
--- a/ops/framework.py
+++ b/ops/framework.py
@@ -271,7 +271,7 @@ class Object(metaclass=_Metaclass):
         return self.framework.model
 
 
-class EventsBase(Object):
+class EventSetBase(Object):
     """Convenience type to allow defining .on attributes at class level."""
 
     handle_kind = "on"
@@ -358,7 +358,7 @@ class CommitEvent(EventBase):
     pass
 
 
-class FrameworkEvents(EventsBase):
+class FrameworkEventSet(EventSetBase):
     pre_commit = EventSource(PreCommitEvent)
     commit = EventSource(CommitEvent)
 
@@ -474,7 +474,7 @@ class SQLiteStorage:
 
 class Framework(Object):
 
-    on = FrameworkEvents()
+    on = FrameworkEventSet()
 
     # Override properties from Object so that we can set them in __init__.
     model = None
@@ -729,7 +729,7 @@ class StoredStateChanged(EventBase):
     pass
 
 
-class StoredStateEvents(EventsBase):
+class StoredStateEvents(EventSetBase):
     changed = EventSource(StoredStateChanged)
 
 


Test patch:
diff --git a/test/test_framework.py b/test/test_framework.py
old mode 100755
new mode 100644
index bf27f2e..7671075
--- a/test/test_framework.py
+++ b/test/test_framework.py
@@ -1,5 +1,4 @@
-#!/usr/bin/python3
-# Copyright 2019 Canonical Ltd.
+# Copyright 2019-2020 Canonical Ltd.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -22,8 +21,20 @@ import datetime
 from pathlib import Path
 
 from ops.framework import (
-    Framework, Handle, EventSource, EventsBase, EventBase, Object, PreCommitEvent, CommitEvent,
-    NoSnapshotError, StoredState, StoredList, BoundStoredState, StoredStateData, SQLiteStorage
+    BoundStoredState,
+    CommitEvent,
+    EventBase,
+    EventSetBase,
+    EventSource,
+    Framework,
+    Handle,
+    NoSnapshotError,
+    Object,
+    PreCommitEvent,
+    SQLiteStorage,
+    StoredList,
+    StoredState,
+    StoredStateData,
 )
 
 
@@ -376,7 +387,7 @@ class TestFramework(unittest.TestCase):
         class MyEvent(EventBase):
             pass
 
-        class MyEvents(EventsBase):
+        class MyEvents(EventSetBase):
             foo = EventSource(MyEvent)
 
         class MyNotifier(Object):
@@ -473,7 +484,7 @@ class TestFramework(unittest.TestCase):
         class MyEvent(EventBase):
             pass
 
-        class MyEvents(EventsBase):
+        class MyEvents(EventSetBase):
             foo = EventSource(MyEvent)
             bar = EventSource(MyEvent)
 
@@ -511,11 +522,11 @@ class TestFramework(unittest.TestCase):
 
         event = EventSource(MyEvent)
 
-        class MyEvents(EventsBase):
+        class MyEvents(EventSetBase):
             foo = event
 
         with self.assertRaises(RuntimeError) as cm:
-            class OtherEvents(EventsBase):
+            class OtherEvents(EventSetBase):
                 foo = event
         self.assertEqual(
             str(cm.exception),
@@ -580,7 +591,7 @@ class TestFramework(unittest.TestCase):
         class MyBar(EventBase):
             pass
 
-        class MyEvents(EventsBase):
+        class MyEvents(EventSetBase):
             foo = EventSource(MyFoo)
 
         class MyNotifier(Object):
@@ -617,10 +628,10 @@ class TestFramework(unittest.TestCase):
     def test_dynamic_event_types(self):
         framework = self.create_framework()
 
-        class MyEventsA(EventsBase):
+        class MyEventsA(EventSetBase):
             handle_kind = 'on_a'
 
-        class MyEventsB(EventsBase):
+        class MyEventsB(EventSetBase):
             handle_kind = 'on_b'
 
         class MyNotifier(Object):
@@ -1208,7 +1219,3 @@ class TestStoredState(unittest.TestCase):
         self.assertEqual(parent.state.bar, 4)
         # TODO: jam 2020-01-30 is there a clean way to tell that
         #       parent.state._data.dirty is False?
-
-
-if __name__ == "__main__":
-    unittest.main()