def remove_listener(self, listener): """ Unregister an iPOPO event listener. :param listener: The listener to register :return: True if the listener has been removed from the registry """ with self.__listeners_lock: return remove_listener(self.__listeners, listener)
def testAddRemoveListener(self): """ Tests add/remove listener methods """ registry = [] values = (42, "test", (1, 2, 3)) # None value self.assertFalse(utilities.add_listener(registry, None), "None value must not be accepted") self.assertFalse(utilities.remove_listener(registry, None), "None value must not be accepted") for value in values: # Non-present value self.assertFalse(utilities.remove_listener(registry, value), "Non-present value removed") # Add value self.assertTrue(utilities.add_listener(registry, value), "Value has been refused") self.assertEqual(registry.count(value), 1, "Value not inserted in registry") # Second add self.assertFalse(utilities.add_listener(registry, value), "Value has been added twice") self.assertEqual(registry.count(value), 1, "Value has been added twice") for value in values: # Remove value self.assertTrue(utilities.remove_listener(registry, value), "Value has not been removed") # Ensure the value has been remove self.assertEqual(registry.count(value), 0, "Value has not been removed") # Second removal self.assertFalse(utilities.remove_listener(registry, value), "Value has been removed twice")