def test_simple(self): subject = create_class(['event_a', 'event_b', ])() observer = create_class([], ['on_event_a', 'on_event_b', ])() connections = list(nmevent.discover_handlers(observer, subject, "on_")) self.assertEqual(len(connections), 2) self.assertTrue(isinstance(connections[0][0], nmevent.InstanceEvent)) self.assertEqual(connections[0][1], observer.on_event_a) self.assertTrue(isinstance(connections[1][0], nmevent.InstanceEvent)) self.assertEqual(connections[1][1], observer.on_event_b)
def test_nested(self): subject = create_class(['some_event'], [], { 'attr1': create_class([], [], { 'attr2': create_class(['some_event', ]) }), })() observer = create_class([], ['on_attr1__attr2__some_event', ])() connections = list(nmevent.discover_handlers(observer, subject, "on_")) self.assertEqual(len(connections), 1) self.assertEqual(connections[0][1], observer.on_attr1__attr2__some_event)