def test_commentline_relationship_disconnect(create): """Test comment line to a relationship item connection and unlink. Demonstrates defect #103. """ clazz1 = create(ClassItem, UML.Class) clazz2 = create(ClassItem, UML.Class) gen = create(GeneralizationItem) connect(gen, gen.head, clazz1) connect(gen, gen.tail, clazz2) assert gen.subject # now, connect comment to a generalization (relationship) comment = create(CommentItem, Comment) line = create(CommentLineItem) connect(line, line.head, comment) connect(line, line.tail, gen) assert gen.subject in comment.subject.annotatedElement assert comment.subject in gen.subject.comment disconnect(gen, gen.head) assert gen.subject is None assert not comment.subject.annotatedElement
def test_disconnect_execution_specification_with_execution_specification_from_lifeline( diagram, element_factory): def elements_of_kind(type): return element_factory.lselect(type) lifeline, parent_exec_spec = create_lifeline_with_execution_specification( diagram, element_factory) child_exec_spec = diagram.create(ExecutionSpecificationItem) grand_child_exec_spec = diagram.create(ExecutionSpecificationItem) connect( child_exec_spec, child_exec_spec.handles()[0], parent_exec_spec, parent_exec_spec.ports()[0], ) connect( grand_child_exec_spec, grand_child_exec_spec.handles()[0], child_exec_spec, child_exec_spec.ports()[0], ) disconnect(parent_exec_spec, parent_exec_spec.handles()[0]) assert lifeline.subject assert parent_exec_spec.subject is None assert child_exec_spec.subject is None assert grand_child_exec_spec.subject is None assert elements_of_kind(UML.ExecutionSpecification) == [] assert elements_of_kind(UML.ExecutionOccurrenceSpecification) == []
def test_disconnect_of_second_association_should_leave_model_in_tact( connected_association, clone): asc, c1, c2 = connected_association new = clone(asc) disconnect(new, new.head) assert asc.subject.memberEnd[0].type is c1.subject assert asc.subject.memberEnd[1].type is c2.subject assert new.subject is asc.subject
def test_disconnect_should_disconnect_model(connected_association): asc, c1, c2 = connected_association disconnect(asc, asc.head) disconnect(asc, asc.tail) assert c1 is not get_connected(asc, asc.head) assert c2 is not get_connected(asc, asc.tail) assert asc.subject assert len(asc.subject.memberEnd) == 2 assert asc.subject.memberEnd[0].type is None assert asc.subject.memberEnd[1].type is None
def test_commentline_element_disconnect(create, diagram): """Test comment line connecting to comment and disconnecting actor item.""" comment = create(CommentItem, Comment) line = create(CommentLineItem) ac = create(ActorItem, UML.Actor) connect(line, line.head, comment) connect(line, line.tail, ac) assert diagram.canvas.get_connection(line.tail).connected is ac disconnect(line, line.tail) assert not diagram.canvas.get_connection(line.tail)
def test_disconnect_execution_specification_from_lifeline( diagram, element_factory): def elements_of_kind(type): return element_factory.lselect(type) lifeline, exec_spec = create_lifeline_with_execution_specification( diagram, element_factory) disconnect(exec_spec, exec_spec.handles()[0]) assert lifeline.subject assert exec_spec.subject is None assert exec_spec.canvas assert elements_of_kind(UML.ExecutionSpecification) == [] assert elements_of_kind(UML.ExecutionOccurrenceSpecification) == []
def test_disconnect_connector_from_proxy_port( connector_item: ConnectorItem, head_proxy_port_item: ProxyPortItem, tail_proxy_port_item: ProxyPortItem, element_factory, ): connect(connector_item, connector_item.handles()[0], head_proxy_port_item) connect(connector_item, connector_item.handles()[1], tail_proxy_port_item) disconnect(connector_item, connector_item.handles()[0]) assert not connector_item.subject assert element_factory.lselect(UML.Connector) == [] assert element_factory.lselect(UML.ConnectorEnd) == [] assert head_proxy_port_item.subject in element_factory.select(UML.Port) assert tail_proxy_port_item.subject in element_factory.select(UML.Port)
def test_dependency_disconnect(create, element_factory): actor1 = create(ActorItem, UML.Actor) actor2 = create(ActorItem, UML.Actor) dep = create(DependencyItem) connect(dep, dep.head, actor1) connect(dep, dep.tail, actor2) dep_subj = dep.subject disconnect(dep, dep.tail) assert dep.subject is None assert get_connected(dep, dep.tail) is None assert dep_subj not in element_factory.select() assert dep_subj not in actor1.subject.supplierDependency assert dep_subj not in actor2.subject.clientDependency
def test_disconnection(diagram): """Test message disconnection.""" ll1 = diagram.create(LifelineItem) ll2 = diagram.create(LifelineItem) msg = diagram.create(MessageItem) connect(msg, msg.head, ll1) connect(msg, msg.tail, ll2) # one side disconnection disconnect(msg, msg.head) assert msg.subject is not None, f"{msg.subject}" # 2nd side disconnection disconnect(msg, msg.tail) assert msg.subject is None, f"{msg.subject}"
def test_lifetime_connectivity_on_head(diagram, element_factory): """Test lifeline's lifetime connectivity change on head connection.""" ll = diagram.create(LifelineItem, subject=element_factory.create(UML.Lifeline)) msg = diagram.create(MessageItem) # connect message to lifeline's head, lifeline's lifetime # visibility and connectivity should change connect(msg, msg.head, ll) assert not ll.lifetime.visible assert not ll.lifetime.connectable assert ll.lifetime.MIN_LENGTH == ll.lifetime.min_length # ... and disconnection disconnect(msg, msg.head) assert ll.lifetime.connectable assert ll.lifetime.MIN_LENGTH == ll.lifetime.min_length
def test_disconnect_of_navigable_end_should_remove_owner_relationship( connected_association, ): asc, c1, c2 = connected_association UML.model.set_navigability(asc.subject, asc.head_subject, True) assert asc.head_subject in c2.subject.ownedAttribute disconnect(asc, asc.head) assert asc.subject assert len(asc.subject.memberEnd) == 2 assert asc.subject.memberEnd[0].type is None assert asc.head_subject not in c2.subject.ownedAttribute assert asc.tail_subject not in c1.subject.ownedAttribute assert asc.head_subject.type is None assert asc.tail_subject.type is None
def test_commentline_element_reconnect(create, diagram): """Test comment line connecting to comment and actor items.""" comment = create(CommentItem, Comment) line = create(CommentLineItem) ac = create(ActorItem, UML.Actor) connect(line, line.head, comment) connect(line, line.tail, ac) assert diagram.connections.get_connection(line.tail).connected is ac assert 1 == len(comment.subject.annotatedElement) assert ac.subject in comment.subject.annotatedElement ac2 = create(ActorItem, UML.Actor) disconnect(line, line.tail) connect(line, line.tail, ac2) assert diagram.connections.get_connection(line.tail).connected is ac2 assert len(comment.subject.annotatedElement) == 1 assert ac2.subject in comment.subject.annotatedElement
def test_dependency_reconnect(create): """Test dependency reconnection using two actor items.""" actor1 = create(ActorItem, UML.Actor) actor2 = create(ActorItem, UML.Actor) dep = create(DependencyItem) connect(dep, dep.head, actor1) connect(dep, dep.tail, actor2) dep_subj = dep.subject disconnect(dep, dep.tail) # reconnect connect(dep, dep.tail, actor2) assert dep.subject is not None assert dep.subject is not dep_subj # the old subject has been deleted assert dep.subject in actor1.subject.supplierDependency assert dep.subject in actor2.subject.clientDependency
def test_lifetime_connectivity_on_lifetime(diagram, element_factory): """Test lifeline's lifetime connectivity change on lifetime connection """ ll = diagram.create(LifelineItem, subject=element_factory.create(UML.Lifeline)) msg = diagram.create(MessageItem) ll.lifetime.visible = True # connect message to lifeline's lifetime, lifeline's lifetime # visibility and connectivity should be unchanged connect(msg, msg.head, ll, ll.lifetime.port) assert ll.lifetime.connectable assert ll.lifetime.MIN_LENGTH_VISIBLE == ll.lifetime.min_length # ... and disconnection disconnect(msg, msg.head) assert ll.lifetime.connectable assert ll.lifetime.visible assert ll.lifetime.MIN_LENGTH == ll.lifetime.min_length
def test_disconnect_execution_specification_from_lifeline( diagram, element_factory): def elements_of_kind(type): return element_factory.lselect(lambda e: e.isKindOf(type)) lifeline = diagram.create(LifelineItem, subject=element_factory.create(UML.Lifeline)) lifeline.lifetime.visible = True exec_spec = diagram.create(ExecutionSpecificationItem) connect(exec_spec, exec_spec.handles()[0], lifeline, lifeline.lifetime.port) disconnect(exec_spec, exec_spec.handles()[0]) assert lifeline.subject assert exec_spec.subject is None assert exec_spec.canvas assert elements_of_kind(UML.ExecutionSpecification) == [] assert elements_of_kind(UML.ExecutionOccurrenceSpecification) == []
def test_message_disconnect_from_execution_specification( diagram, element_factory): """Test gluing message on sequence diagram.""" lifeline = diagram.create(LifelineItem, subject=element_factory.create(UML.Lifeline)) exec_spec = diagram.create(ExecutionSpecificationItem) message = diagram.create(MessageItem) connect(exec_spec, exec_spec.handles()[0], lifeline, lifeline.lifetime.port) connect(message, message.head, exec_spec, exec_spec.ports()[0]) disconnect(message, message.head) messages = element_factory.lselect(UML.Message) occurrences = element_factory.lselect( lambda e: e.isKindOf(UML.MessageOccurrenceSpecification)) assert not message.subject assert not len(messages) assert not len(occurrences)
def test_lifetime_connectivity_on_lifetime(diagram, element_factory): """Test lifeline's lifetime connectivity change on lifetime connection.""" ll = diagram.create(LifelineItem, subject=element_factory.create(UML.Lifeline)) ll.lifetime.visible = True ll.handles()[-1].pos.y = 500 msg = diagram.create(MessageItem) msg.head.pos.y = 400 # connect message to lifeline's lifetime, lifeline's lifetime # visibility and connectivity should be unchanged connect(msg, msg.head, ll) assert diagram.connections.get_connection(msg.head).port is ll.ports()[-1] assert ll.lifetime.connectable assert ll.lifetime.MIN_LENGTH_VISIBLE == ll.lifetime.min_length # ... and disconnection disconnect(msg, msg.head) assert ll.lifetime.connectable assert ll.lifetime.visible assert ll.lifetime.MIN_LENGTH == ll.lifetime.min_length
def test_relation_allow_connect_disconnect_cycle(diagram, element_factory, item_class): req1 = element_factory.create(sysml.Requirement) req2 = element_factory.create(sysml.Requirement) req_item1 = diagram.create(RequirementItem, subject=req1) req_item2 = diagram.create(RequirementItem, subject=req2) relation = diagram.create(item_class) assert allow(relation, relation.handles()[0], req_item1) assert allow(relation, relation.handles()[1], req_item2) connect(relation, relation.handles()[0], req_item1) connect(relation, relation.handles()[1], req_item2) assert relation.subject assert relation.subject.sourceContext is req_item1.subject assert relation.subject.targetContext is req_item2.subject disconnect(relation, relation.handles()[0]) assert not relation.subject