Example #1
0
def test_parse_operation(factory):
    """Test parsing simple operation."""
    o = factory.create(UML.Operation)
    parse(o, "myfunc()")
    assert "myfunc" == o.name
    assert not o.returnResult[0].typeValue
    assert not o.formalParameter
Example #2
0
def test_parse_operation_return(factory):
    """Test parsing operation with return value."""
    o = factory.create(UML.Operation)
    parse(o, "+ myfunc(): int")
    assert "myfunc" == o.name
    assert "int" == o.ownedParameter[0].typeValue
    assert "public" == o.visibility
Example #3
0
def test_parse_operation_with_spaces(factory):
    o = factory.create(UML.Operation)
    parse(o, "- name with space (param with space: some node ): return value")
    assert "name with space" == o.name
    assert "return value" == o.ownedParameter[0].typeValue
    assert "param with space" == o.ownedParameter[1].name
    assert "some node" == o.ownedParameter[1].typeValue
Example #4
0
def test_parse_property_with_space_in_name(factory):
    a = factory.create(UML.Property)

    parse(a, "+ name with space : str")

    assert "public" == a.visibility
    assert "name with space" == a.name
    assert "str" == a.typeValue
Example #5
0
def test_parse_property_simple(factory):
    """Test simple property parsing."""
    a = factory.create(UML.Property)
    parse(a, "myattr")
    assert not a.isDerived
    assert "myattr" == a.name
    assert a.typeValue is None, a.typeValue
    assert a.lowerValue is None, a.lowerValue
    assert a.upperValue is None, a.upperValue
    assert a.defaultValue is None, a.defaultValue
Example #6
0
def test_parse_operation_1_param(factory):
    """Test parsing of operation with one parameter."""
    o = factory.create(UML.Operation)
    parse(o, "- myfunc2 (a: node): double")
    assert "myfunc2" == o.name
    assert "double" == o.returnResult[0].typeValue
    assert "private" == o.visibility
    assert len(o.formalParameter) == 1
    assert "a" == o.formalParameter[0].name
    assert "node" == o.formalParameter[0].typeValue
    assert o.formalParameter[0].defaultValue is None
Example #7
0
def test_parse_property_invalid(factory):
    """Test parsing property with invalid syntax."""
    a = factory.create(UML.Property)

    parse(a, '+ name = str[*] = "aap" { static }')
    assert '+ name = str[*] = "aap" { static }' == a.name
    assert not a.isDerived
    assert not a.typeValue
    assert not a.lowerValue
    assert not a.upperValue
    assert not a.defaultValue
Example #8
0
def test_parse_association_end_multiplicity(factory):
    """Test parsing of multiplicity."""
    a = factory.create(UML.Association)
    p = factory.create(UML.Property)
    p.association = a
    parse(p, "0..2 { tag }")
    assert p.name is None
    assert not p.typeValue
    assert "0" == p.lowerValue
    assert "2" == p.upperValue
    assert not p.defaultValue
Example #9
0
def test_parse_property_complex(factory):
    """Test complex property parsing."""
    a = factory.create(UML.Property)

    parse(a, '+ / name : str[0..*] = "aap" { static }')
    assert "public" == a.visibility
    assert a.isDerived
    assert "name" == a.name
    assert "str" == a.typeValue
    assert "0" == a.lowerValue
    assert "*" == a.upperValue
    assert '"aap"' == a.defaultValue
Example #10
0
def test_parse_association_end(factory):
    """Test parsing of association end."""
    a = factory.create(UML.Association)
    p = factory.create(UML.Property)
    p.association = a

    parse(p, "end")
    assert "end" == p.name
    assert not p.typeValue
    assert not p.lowerValue
    assert not p.upperValue
    assert not p.defaultValue
Example #11
0
def test_operation_parameter_deletion(factory):
    assert 0 == len(factory.lselect())

    c = factory.create(UML.Class)
    c.name = "Class"
    o = factory.create(UML.Operation)
    c.ownedOperation = o
    parse(o, "a(x: int, y: int)")

    c.unlink()

    assert len(factory.lselect()) == 0, factory.lselect()
Example #12
0
 def _set_object_value(self, row, col, value):
     attr = row[-1]
     if col == 0:
         parse(attr, value)
         row[0] = format(attr)
     elif col == 1:
         attr.isStatic = not attr.isStatic
         row[1] = attr.isStatic
     elif col == 2:
         # Value in attribute object changed:
         row[0] = format(attr)
         row[1] = attr.isStatic
Example #13
0
def test_class_with_attributes(diagram, element_factory):
    cls = element_factory.create(UML.Class)
    attr = element_factory.create(UML.Property)
    parse(attr, "- attr: str")
    cls.ownedAttribute = attr

    cls_item = diagram.create(ClassItem, subject=cls)

    new_items = copy_clear_and_paste({cls_item}, diagram, element_factory)
    new_cls_item = new_items.pop()

    assert isinstance(new_cls_item, ClassItem)
    assert format(new_cls_item.subject.ownedAttribute[0]) == "- attr: str"
Example #14
0
def test_parse_association_end_derived_end(factory):
    """Test parsing derived association end."""
    a = factory.create(UML.Association)
    p = factory.create(UML.Property)
    p.association = a
    parse(p, "-/end[*] { mytag}")
    assert "private" == p.visibility
    assert p.isDerived
    assert "end" == p.name
    assert not p.typeValue
    assert not p.lowerValue
    assert "*" == p.upperValue
    assert not p.defaultValue
Example #15
0
def test_parse_operation_2_params(factory):
    """Test parsing of operation with two parameters."""
    o = factory.create(UML.Operation)
    parse(o, "# myfunc2 (a: str, b: int = 3 {  static}): float")
    assert "myfunc2" == o.name
    assert "float" == o.returnResult[0].typeValue
    assert "protected" == o.visibility
    assert len(o.formalParameter) == 2
    assert "a" == o.formalParameter[0].name
    assert "str" == o.formalParameter[0].typeValue
    assert o.formalParameter[0].defaultValue is None
    assert "b" == o.formalParameter[1].name
    assert "int" == o.formalParameter[1].typeValue
    assert "3" == o.formalParameter[1].defaultValue
Example #16
0
    def _text_edited(self, cell, path_str, new_text):
        """The text has been edited.

        This method updates the data object. Note that 'path_str' is a
        string where the fields are separated by colons ':', like this:
        '0:1:1'. We first turn them into a tuple.
        """
        model = self.get_property("model")
        iter = model.get_iter_from_string(path_str)
        element = model.get_value(iter, 0)
        try:
            parse(element, new_text)
        except TypeError:
            log.debug(f"No parser for {element}")
Example #17
0
def test_class_with_operation(diagram, element_factory):
    cls = element_factory.create(UML.Class)
    oper = element_factory.create(UML.Operation)
    parse(oper, "- oper(inout param: str): str")
    cls.ownedOperation = oper

    cls_item = diagram.create(ClassItem, subject=cls)

    new_items = copy_clear_and_paste({cls_item}, diagram, element_factory)
    new_cls_item = new_items.pop()

    assert isinstance(new_cls_item, ClassItem)
    assert (format(new_cls_item.subject.ownedOperation[0]) ==
            "- oper(inout param: str): str")
Example #18
0
 def _set_object_value(self, row, col, value):
     operation = row[-1]
     if col == 0:
         parse(operation, value)
         row[0] = format(operation)
     elif col == 1:
         operation.isAbstract = not operation.isAbstract
         row[1] = operation.isAbstract
     elif col == 2:
         operation.isStatic = not operation.isStatic
         row[2] = operation.isStatic
     elif col == 3:
         row[0] = format(operation)
         row[1] = operation.isAbstract
         row[2] = operation.isStatic
Example #19
0
def test_interface_with_attributes_and_operation(diagram, element_factory):
    iface = element_factory.create(UML.Interface)

    attr = element_factory.create(UML.Property)
    parse(attr, "- attr: str")
    iface.ownedAttribute = attr

    oper = element_factory.create(UML.Operation)
    parse(oper, "- oper(inout param: str): str")
    iface.ownedOperation = oper

    iface_item = diagram.create(InterfaceItem, subject=iface)

    new_items = copy_clear_and_paste({iface_item}, diagram, element_factory)
    new_iface_item = new_items.pop()

    assert isinstance(new_iface_item, InterfaceItem)
    assert format(new_iface_item.subject.ownedAttribute[0]) == "- attr: str"
    assert (format(new_iface_item.subject.ownedOperation[0]) ==
            "- oper(inout param: str): str")
Example #20
0
 def _on_end_name_change(self, entry, end):
     if not self.semaphore:
         self.semaphore += 1
         parse(end.subject, entry.get_text())
         self.semaphore -= 1
Example #21
0
def test_parse_operation_with_spaces(factory):
    o = factory.create(UML.Operation)
    parse(o, "- name with space (param with space: some node ): double")
    assert "name with space" == o.name
    assert "param with space" == o.formalParameter[0].name
    assert "some node" == o.formalParameter[0].typeValue
Example #22
0
 def update_end_text(text):
     assert end_item
     parse(end_item.subject, text)
     return True
Example #23
0
 def escape():
     assert end_item
     parse(end_item.subject, text)
Example #24
0
def test_parse_operation(factory):
    """Test parsing simple operation."""
    o = factory.create(UML.Operation)
    parse(o, "myfunc()")
    assert "myfunc" == o.name
    assert not o.ownedParameter
Example #25
0
def test_parse_operation_invalid_syntax(factory):
    """Test operation parsing with invalid syntax."""
    o = factory.create(UML.Operation)
    parse(o, "- myfunc2: myType2")
    assert "- myfunc2: myType2" == o.name