def test_unsubscribe_with_publisher(self): event = Event('unsubscribe nuke') # noinspection PyShadowingNames,PyUnusedLocal @event.subscribe(Publisher('nuke')) async def i_feel_no_regret(message, publisher, event): return ['received', publisher, event] self.assertEqual(len(event.pub_sub), 1) event.unsubscribe(i_feel_no_regret, Publisher('nuke')) self.assertEqual(len(event.pub_sub), 0)
def test_unsubscribe(self): event = Event('unsubscribe me') # noinspection PyShadowingNames,PyUnusedLocal @event.subscribe() async def i_will_do_it(message, publisher, event): return ['received', publisher, event] self.assertEqual(len(event.pub_sub), 1) event.unsubscribe(i_will_do_it) self.assertEqual(len(event.pub_sub), 0)