def test_notification_of_change(self): """ Test notifications with Transition object. """ dispatcher = self.dispatcher element = uml2.Transition() g = element.guard = uml2.Constraint() dispatcher.register_handler(self._handler, element, 'guard.specification') assert len(dispatcher._handlers) == 2 assert not self.events g.specification = 'x' assert len(self.events) == 1, self.events element.guard = uml2.Constraint() assert len(self.events) == 2, self.events
def test_notification_with_composition(self): """ Test unregister with composition. Use Class.ownedOperation.precondition. """ dispatcher = self.dispatcher element = uml2.Class() o = element.ownedOperation = uml2.Operation() p = element.ownedOperation[0].precondition = uml2.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_notification_with_incompatible_elements(self): """ Test unregister with composition. Use Class.ownedOperation.precondition. """ dispatcher = self.dispatcher element = uml2.Transition() g = element.guard = uml2.Constraint() dispatcher.register_handler(self._handler, element, 'guard.specification') assert len(dispatcher._handlers) == 2 assert not self.events assert (element.guard, uml2.Constraint.specification) in list(dispatcher._handlers.keys()), list(dispatcher._handlers.keys()) g.specification = 'x' assert len(self.events) == 1, self.events g.specification = 'a' assert len(self.events) == 2, self.events