def test_register_handler_twice(self): """ Multiple registrations have no effect. """ dispatcher = self.dispatcher element = uml2.Class() # Add some properties: element.ownedOperation = uml2.Operation() p = element.ownedOperation[0].formalParameter = uml2.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_register_handler(self): dispatcher = self.dispatcher element = uml2.Class() dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 1 assert list(dispatcher._handlers.keys())[0] == (element, uml2.Class.ownedOperation) # Add some properties: # 1: element.ownedOperation = uml2.Operation() # 2: p = element.ownedOperation[0].formalParameter = uml2.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 = uml2.Class() o = element.ownedOperation = uml2.Operation() p = element.ownedOperation[0].formalParameter = uml2.Parameter() p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 3 assert dispatcher._handlers[element, uml2.Class.ownedOperation] assert dispatcher._handlers[o, uml2.Operation.parameter] assert dispatcher._handlers[p, uml2.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, uml2.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 = uml2.Class() o = element.ownedOperation = uml2.Operation() p = element.ownedOperation[0].formalParameter = uml2.Parameter() p.name = 'func' dispatcher.register_handler(self._handler, element, 'ownedOperation.parameter.name') assert len(dispatcher._handlers) == 3 assert not self.events element.ownedOperation = uml2.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