def testSetEnum(self): event = Event(Event.ANY_EVENT) self.assertEqual(event.eventType(), Event.ANY_EVENT) event.setEventType(Event.BASIC_EVENT) self.assertEqual(event.eventType(), Event.BASIC_EVENT) event.setEventTypeByConstRef(Event.SOME_EVENT) self.assertEqual(event.eventType(), Event.SOME_EVENT)
def testEvent(self): '''C++ calling Python reimplementation of virtual in multiple inheritance''' obj = ImplementsBoth() self.assertTrue(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT))) self.assertTrue(obj.event_processed) self.assertEqual(obj.callSum1(1, 2, 3), 12)
def testCpp(self): '''C++ calling C++ virtual method in multiple inheritance scenario''' obj = ImplementsNone() self.assertTrue(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT))) self.assertRaises(AttributeError, getattr, obj, 'event_processed') self.assertEqual(obj.callSum0(1, 2, 3), 6)
def testEventLoop(self): '''Calling virtuals in a event loop''' objs = [ObjectType(), NoOverride(), Override()] evaluated = ObjectType.processEvent(objs, Event(Event.BASIC_EVENT)) self.assertEqual(evaluated, 3) self.assert_(objs[2].called)
def testBasic(self): '''Allowing threads and calling virtuals from C++''' number = 10 objs = [Producer() for x in range(number)] thread = Collector(objs) thread.start() evaluated = ObjectType.processEvent(objs, Event(Event.BASIC_EVENT)) thread.join() producer_data = [x.data for x in objs] self.assertEqual(evaluated, number) self.assertEqual(producer_data, thread.data)
def __init__(self): Event.__init__(self, Event.EventType(999))