예제 #1
0
    def test_event_unregister(self):
        """Tests that an event can be registered, and then unregistered."""
        def event_listener(_):
            self.called_event = False

        registration_id = event_bus.register(Event, event_listener)
        event_bus.unregister(registration_id)
        event_bus.post(Event())

        self.assertFalse(self.called_event)
예제 #2
0
 def unregister(self):
     """Unregisters all subscriptions managed by this SubscriptionBundle."""
     if not self.registered:
         return
     with self._subscription_lock:
         self._registered = False
         for subscription, registration_id in self.subscriptions.items():
             if registration_id is None:
                 logging.warning('Unregistered subscription found in '
                                 'registered SubscriptionBundle: %s, %s' %
                                 (subscription, registration_id))
             event_bus.unregister(subscription)
             self.subscriptions[subscription] = None
예제 #3
0
    def remove_subscription(self, subscription):
        """Removes a subscription from the SubscriptionBundle.

        If the SubscriptionBundle is registered, removing the subscription will
        also unregister it.
        """
        if subscription not in self.subscriptions.keys():
            return False
        with self._subscription_lock:
            if self.registered:
                event_bus.unregister(self.subscriptions[subscription])
            del self.subscriptions[subscription]
        return True
예제 #4
0
    def test_unregister_given_an_event_subscription(self):
        """Tests that unregister can unregister a given EventSubscription."""
        mock_event = Mock()
        bus = event_bus._event_bus
        subscription = EventSubscription(type(mock_event), lambda _: None)
        bus._registration_id_map[id(subscription)] = subscription
        bus._subscriptions[type(mock_event)] = [subscription]

        val = event_bus.unregister(subscription)

        self.assertTrue(val)
        self.assertTrue(subscription not in bus._registration_id_map)
        self.assertTrue(
            subscription not in bus._subscriptions[type(mock_event)])
 def __on_test_class_end(self, event):
     """Tears down the proxy for a test class and removes subscriptions."""
     self._teardown_proxy(event)
     event_bus.unregister(self.__on_test_class_begin)
     event_bus.unregister(self.__on_test_class_end)
 def __on_test_class_end(self, event):
     """Cleans up the subscriptions at the end of a class."""
     event_bus.unregister(self.__on_test_case_begin)
     event_bus.unregister(self.__on_test_case_end)
     event_bus.unregister(self.__on_test_class_end)
예제 #7
0
 def test_unregister_given_invalid_registration_id(self):
     """Asserts that a false is returned upon invalid registration_id."""
     val = event_bus.unregister(9)
     self.assertFalse(val)
예제 #8
0
 def test_unregister_given_object_that_is_not_a_subscription(self):
     """Asserts that a ValueError is raised upon invalid arguments."""
     with self.assertRaises(ValueError):
         event_bus.unregister(Mock())