def test_register_handler_twice(self): """ Multiple registrations have no effect. """ dispatcher = self.dispatcher element = UML.Class() # Add some properties: element.ownedOperation = UML.Operation() p = element.ownedOperation[0].formalParameter = UML.Parameter() dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') n_handlers = len(dispatcher._handlers) self.assertEquals(0, len(self.events)) dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') self.assertEquals(n_handlers, len(dispatcher._handlers)) dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') self.assertEquals(n_handlers, len(dispatcher._handlers)) dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') self.assertEquals(n_handlers, len(dispatcher._handlers)) p.name = 'func' self.assertEquals(1, len(self.events))
def test_association_endType(factory): c1 = UML.Class() c2 = UML.Class() a = UML.Association() a.memberEnd = UML.Property() a.memberEnd = UML.Property() a.memberEnd[0].type = c1 a.memberEnd[1].type = c2 c1.ownedAttribute = a.memberEnd[0] c2.ownedAttribute = a.memberEnd[1] assert c1 in a.endType assert c2 in a.endType c3 = UML.Class() a.memberEnd[1].type = c3 assert c1 in a.endType assert c3 in a.endType
def test_notification_with_composition(self): """ Test unregister with composition. Use Class.ownedOperation.precondition. """ dispatcher = self.dispatcher element = UML.Class() o = element.ownedOperation = UML.Operation() p = element.ownedOperation[0].precondition = UML.Constraint() p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.precondition.name') assert len(dispatcher._handlers) == 3 assert not self.events del element.ownedOperation[o] assert len(dispatcher._handlers) == 1
def test_register_handler(self): dispatcher = self.dispatcher element = UML.Class() dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 1 assert dispatcher._handlers.keys()[0] == (element, UML.Class.ownedOperation) # Add some properties: # 1: element.ownedOperation = UML.Operation() # 2: p = element.ownedOperation[0].formalParameter = UML.Parameter() # 3: p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') self.assertEquals(3, len(self.events)) self.assertEquals(3, len(dispatcher._handlers))
def test_unregister_handler(self): # First some setup: dispatcher = self.dispatcher element = UML.Class() o = element.ownedOperation = UML.Operation() p = element.ownedOperation[0].formalParameter = UML.Parameter() p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 3 assert dispatcher._handlers[element, UML.Class.ownedOperation] assert dispatcher._handlers[o, UML.Operation.parameter] assert dispatcher._handlers[p, UML.Parameter.name] dispatcher.unregister_handler(self._handler) assert len(dispatcher._handlers) == 0, dispatcher._handlers assert len(dispatcher._reverse) == 0, dispatcher._reverse #assert dispatcher._handlers.keys()[0] == (element, UML.Class.ownedOperation) # Should not fail here too: dispatcher.unregister_handler(self._handler)
def test_notification(self): """ Test notifications with Class object. """ dispatcher = self.dispatcher element = UML.Class() o = element.ownedOperation = UML.Operation() p = element.ownedOperation[0].formalParameter = UML.Parameter() p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 3 assert not self.events element.ownedOperation = UML.Operation() assert len(self.events) == 1, self.events assert len(dispatcher._handlers) == 4 p.name = 'othername' assert len(self.events) == 2, self.events del element.ownedOperation[o] assert len(dispatcher._handlers) == 2