Просмотр исходного кода

Fixed minor issue with events and improved event tests

Nuwan Goonasekera 7 лет назад
Родитель
Сommit
3b7c0f6fd7
2 измененных файлов с 16 добавлено и 6 удалено
  1. 13 6
      cloudbridge/cloud/base/events.py
  2. 3 0
      test/test_event_system.py

+ 13 - 6
cloudbridge/cloud/base/events.py

@@ -14,9 +14,9 @@ class InterceptingEventHandler(EventHandler):
 
     def __init__(self, event_pattern, priority, callback):
         self.__dispatcher = None
-        self.event_pattern = event_pattern
-        self.priority = priority
-        self.callback = callback
+        self.__event_pattern = event_pattern
+        self.__priority = priority
+        self.__callback = callback
 
     def __lt__(self, other):
         # This is required for the bisect module to insert
@@ -33,14 +33,21 @@ class InterceptingEventHandler(EventHandler):
         else:
             return None
 
+    @property
     def event_pattern(self):
-        pass
+        return self.__event_pattern
 
+    @property
     def priority(self):
-        pass
+        return self.__priority
 
+    @property
     def callback(self):
-        pass
+        return self.__callback
+
+    @callback.setter
+    def callback(self, value):
+        self.__callback = value
 
     @property
     def dispatcher(self):

+ 3 - 0
test/test_event_system.py

@@ -29,6 +29,9 @@ class EventSystemTestCase(unittest.TestCase):
         dispatcher = SimpleEventDispatcher()
         handler = dispatcher.observe(event_pattern=EVENT_NAME, priority=1000,
                                      callback=my_callback)
+        assert handler.event_pattern == EVENT_NAME
+        assert handler.priority == 1000
+        assert handler.callback == my_callback
         self.assertIsInstance(handler, EventHandler)
         result = dispatcher.dispatch(self, EVENT_NAME, 'first_pos_arg',
                                      a_keyword_arg='another_thing')