def test_parse_operation(factory): """Test parsing simple operation.""" o = factory.create(UML.Operation) UML.parse(o, "myfunc()") assert "myfunc" == o.name assert not o.returnResult[0].typeValue assert not o.formalParameter
def test_parse_operation(self): """Test parsing simple operation """ o = factory.create(UML.Operation) UML.parse(o, "myfunc()") self.assertEqual("myfunc", o.name) self.assertTrue(not o.returnResult[0].typeValue) self.assertFalse(o.formalParameter)
def test_parse_operation_return(factory): """Test parsing operation with return value.""" o = factory.create(UML.Operation) UML.parse(o, "+ myfunc(): int") assert "myfunc" == o.name assert "int" == o.returnResult[0].typeValue assert "public" == o.visibility assert not o.formalParameter
def test_parse_operation(self): """Test parsing simple operation """ o = factory.create(UML.Operation) UML.parse(o, 'myfunc()') self.assertEquals('myfunc', o.name) self.assertTrue(not o.returnResult[0].typeValue) self.assertFalse(o.formalParameter)
def test_parse_operation_return(self): """Test parsing operation with return value """ o = factory.create(UML.Operation) UML.parse(o, "+ myfunc(): int") self.assertEqual("myfunc", o.name) self.assertEqual("int", o.returnResult[0].typeValue) self.assertEqual("public", o.visibility) self.assertTrue(not o.formalParameter)
def test_parse_operation_return(self): """Test parsing operation with return value """ o = factory.create(UML.Operation) UML.parse(o, '+ myfunc(): int') self.assertEquals('myfunc', o.name) self.assertEquals('int', o.returnResult[0].typeValue) self.assertEquals('public', o.visibility) self.assertTrue(not o.formalParameter)
def test_parse_property_simple(factory): """Test simple property parsing.""" a = factory.create(UML.Property) UML.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
def test_parse_property_simple(self): """Test simple property parsing """ a = factory.create(UML.Property) UML.parse(a, 'myattr') self.assertFalse(a.isDerived) self.assertEquals('myattr', a.name) self.assertTrue(a.typeValue is None, a.typeValue) self.assertTrue(a.lowerValue is None, a.lowerValue) self.assertTrue(a.upperValue is None, a.upperValue) self.assertTrue(a.defaultValue is None, a.defaultValue)
def test_parse_property_invalid(factory): """Test parsing property with invalid syntax.""" a = factory.create(UML.Property) UML.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
def test_parse_operation_1_param(factory): """Test parsing of operation with one parameter.""" o = factory.create(UML.Operation) UML.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
def test_parse_association_end_multiplicity(factory): """Test parsing of multiplicity.""" a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.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
def test_parse_property_simple(self): """Test simple property parsing """ a = factory.create(UML.Property) UML.parse(a, "myattr") self.assertFalse(a.isDerived) self.assertEqual("myattr", a.name) self.assertTrue(a.typeValue is None, a.typeValue) self.assertTrue(a.lowerValue is None, a.lowerValue) self.assertTrue(a.upperValue is None, a.upperValue) self.assertTrue(a.defaultValue is None, a.defaultValue)
def test_parse_multiplicity2(self): """Test parsing of multiplicity with multiline constraints """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "0..2 { tag1, \ntag2}") self.assertTrue(p.name is None) self.assertTrue(not p.typeValue) self.assertEqual("0", p.lowerValue) self.assertEqual("2", p.upperValue) self.assertTrue(not p.defaultValue)
def _set_object_value(self, row, col, value): attr = row[-1] if col == 0: UML.parse(attr, value) row[0] = UML.format(attr) elif col == 1: attr.isStatic = not attr.isStatic row[1] = attr.isStatic elif col == 2: # Value in attribute object changed: row[0] = UML.format(attr) row[1] = attr.isStatic
def test_parse_property_complex(factory): """Test complex property parsing.""" a = factory.create(UML.Property) UML.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
def test_parse_association_end(factory): """Test parsing of association end.""" a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "end") assert "end" == p.name assert not p.typeValue assert not p.lowerValue assert not p.upperValue assert not p.defaultValue
def test_parse_property_invalid(self): """Test parsing property with invalid syntax """ a = factory.create(UML.Property) UML.parse(a, '+ name = str[*] = "aap" { static }') self.assertEqual('+ name = str[*] = "aap" { static }', a.name) self.assertFalse(a.isDerived) self.assertTrue(not a.typeValue) self.assertTrue(not a.lowerValue) self.assertTrue(not a.upperValue) self.assertTrue(not a.defaultValue)
def test_parse_operation_1_param(self): """Test parsing of operation with one parameter """ o = factory.create(UML.Operation) UML.parse(o, "- myfunc2 (a: node): double") self.assertEqual("myfunc2", o.name) self.assertEqual("double", o.returnResult[0].typeValue) self.assertEqual("private", o.visibility) self.assertEqual(1, len(o.formalParameter)) self.assertEqual("a", o.formalParameter[0].name) self.assertEqual("node", o.formalParameter[0].typeValue) self.assertTrue(o.formalParameter[0].defaultValue is None)
def test_parse_multiplicity(self): """Test parsing of multiplicity """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "0..2 { tag }") self.assertTrue(p.name is None) self.assertTrue(not p.typeValue) self.assertEqual("0", p.lowerValue) self.assertEqual("2", p.upperValue) self.assertTrue(not p.defaultValue)
def test_parse_operation_1_param(self): """Test parsing of operation with one parameter """ o = factory.create(UML.Operation) UML.parse(o, '- myfunc2 (a: node): double') self.assertEquals('myfunc2', o.name) self.assertEquals('double', o.returnResult[0].typeValue) self.assertEquals('private', o.visibility) self.assertEquals(1, len(o.formalParameter)) self.assertEquals('a', o.formalParameter[0].name) self.assertEquals('node', o.formalParameter[0].typeValue) self.assertTrue(o.formalParameter[0].defaultValue is None)
def test_parse_multiplicity(self): """Test parsing of multiplicity """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "0..2 { tag }") self.assertTrue(p.name is None) self.assertTrue(not p.typeValue) self.assertEquals("0", p.lowerValue.value) self.assertEquals("2", p.upperValue.value) self.assertTrue(not p.defaultValue)
def test_parse_multiplicity2(self): """Test parsing of multiplicity with multiline constraints """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, '0..2 { tag1, \ntag2}') self.assertTrue(p.name is None) self.assertTrue(not p.typeValue) self.assertEquals('0', p.lowerValue) self.assertEquals('2', p.upperValue) self.assertTrue(not p.defaultValue)
def test_parse_property_invalid(self): """Test parsing property with invalid syntax """ a = factory.create(UML.Property) UML.parse(a, '+ name = str[*] = "aap" { static }') self.assertEquals('+ name = str[*] = "aap" { static }', a.name) self.assertFalse(a.isDerived) self.assertTrue(not a.typeValue) self.assertTrue(not a.lowerValue) self.assertTrue(not a.upperValue) self.assertTrue(not a.defaultValue)
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 UML.parse(o, "a(x: int, y: int)") c.unlink() assert 0 == len(factory.lselect()), factory.lselect()
def test_parse_association_end(self): """Test parsing of association end """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, 'end') self.assertEquals('end', p.name) self.assertTrue(not p.typeValue) self.assertTrue(not p.lowerValue) self.assertTrue(not p.upperValue) self.assertTrue(not p.defaultValue)
def test_class_with_attributes(diagram, element_factory): cls = element_factory.create(UML.Class) attr = element_factory.create(UML.Property) UML.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 UML.format(new_cls_item.subject.ownedAttribute[0]) == "- attr: str"
def test_operation_parameter_deletion(self): factory = UML.ElementFactory() self.assertEquals(0, len(factory.lselect())) c = factory.create(UML.Class) c.name = 'Class' o = factory.create(UML.Operation) c.ownedOperation = o UML.parse(o, 'a(x: int, y: int)') c.unlink() self.assertEquals(0, len(factory.lselect()), factory.lselect())
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 UML.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
def test_parse_property_complex(self): """Test complex property parsing """ a = factory.create(UML.Property) UML.parse(a, '+ / name : str[0..*] = "aap" { static }') self.assertEqual("public", a.visibility) self.assertTrue(a.isDerived) self.assertEqual("name", a.name) self.assertEqual("str", a.typeValue) self.assertEqual("0", a.lowerValue) self.assertEqual("*", a.upperValue) self.assertEqual('"aap"', a.defaultValue)
def test_parse_association_end(self): """Test parsing of association end """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "end") self.assertEqual("end", p.name) self.assertTrue(not p.typeValue) self.assertTrue(not p.lowerValue) self.assertTrue(not p.upperValue) self.assertTrue(not p.defaultValue)
def test_parse_property_complex(self): """Test complex property parsing """ a = factory.create(UML.Property) UML.parse(a, '+ / name : str[0..*] = "aap" { static }') self.assertEquals('public', a.visibility) self.assertTrue(a.isDerived) self.assertEquals('name', a.name) self.assertEquals('str', a.typeValue) self.assertEquals('0', a.lowerValue) self.assertEquals('*', a.upperValue) self.assertEquals('"aap"', a.defaultValue)
def test_class_with_operation(diagram, element_factory): cls = element_factory.create(UML.Class) oper = element_factory.create(UML.Operation) UML.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 (UML.format(new_cls_item.subject.ownedOperation[0]) == "- oper(inout param: str): str")
def test_parse_derived_end(self): """Test parsing derived association end """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, '-/end[*] { mytag}') self.assertEquals('private', p.visibility) self.assertTrue(p.isDerived) self.assertEquals('end', p.name) self.assertTrue(not p.typeValue) self.assertTrue(not p.lowerValue) self.assertEquals('*', p.upperValue) self.assertTrue(not p.defaultValue)
def test_parse_operation_2_params(factory): """Test parsing of operation with two parameters.""" o = factory.create(UML.Operation) UML.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
def test_parse_derived_end(self): """Test parsing derived association end """ a = factory.create(UML.Association) p = factory.create(UML.Property) p.association = a UML.parse(p, "-/end[*] { mytag}") self.assertEqual("private", p.visibility) self.assertTrue(p.isDerived) self.assertEqual("end", p.name) self.assertTrue(not p.typeValue) self.assertTrue(not p.lowerValue) self.assertEqual("*", p.upperValue) self.assertTrue(not p.defaultValue)
def test_parse_operation_2_params(self): """Test parsing of operation with two parameters """ o = factory.create(UML.Operation) UML.parse(o, "# myfunc2 (a: str, b: int = 3 { static}): float") self.assertEqual("myfunc2", o.name) self.assertEqual("float", o.returnResult[0].typeValue) self.assertEqual("protected", o.visibility) self.assertEqual(2, len(o.formalParameter)) self.assertEqual("a", o.formalParameter[0].name) self.assertEqual("str", o.formalParameter[0].typeValue) self.assertTrue(o.formalParameter[0].defaultValue is None) self.assertEqual("b", o.formalParameter[1].name) self.assertEqual("int", o.formalParameter[1].typeValue) self.assertEqual("3", o.formalParameter[1].defaultValue)
def _set_object_value(self, row, col, value): operation = row[-1] if col == 0: UML.parse(operation, value) row[0] = UML.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] = UML.format(operation) row[1] = operation.isAbstract row[2] = operation.isStatic
def test_parse_operation_2_params(self): """Test parsing of operation with two parameters """ o = factory.create(UML.Operation) UML.parse(o, '# myfunc2 (a: str, b: int = 3 { static}): float') self.assertEquals('myfunc2', o.name) self.assertEquals('float', o.returnResult[0].typeValue) self.assertEquals('protected', o.visibility) self.assertEquals(2, len(o.formalParameter)) self.assertEquals('a', o.formalParameter[0].name) self.assertEquals('str', o.formalParameter[0].typeValue) self.assertTrue(o.formalParameter[0].defaultValue is None) self.assertEquals('b', o.formalParameter[1].name) self.assertEquals('int', o.formalParameter[1].typeValue) self.assertEquals('3', o.formalParameter[1].defaultValue)
def testAttribute(self): """ Test how attribute is updated """ attr = self.element_factory.create(UML.Property) UML.parse(attr, '-name:myType') clazzitem = self.create(ClassItem, UML.Class) clazzitem.subject.ownedAttribute = attr self.assertEquals(1, len(clazzitem._compartments[0])) item = clazzitem._compartments[0][0] self.assertTrue(isinstance(item, FeatureItem)) size = item.get_size() self.assertNotEquals((0, 0), size) attr.defaultValue = 'myDefault' self.diagram.canvas.update() self.assertTrue(size < item.get_size())
def testAttribute(self): """ Test how attribute is updated """ attr = self.element_factory.create(UML.Property) UML.parse(attr, "-name:myType") clazzitem = self.create(ClassItem, UML.Class) clazzitem.subject.ownedAttribute = attr assert 1 == len(clazzitem._compartments[0]) item = clazzitem._compartments[0][0] assert isinstance(item, FeatureItem) size = item.get_size() assert (0, 0) != size attr.defaultValue = "myDefault" self.diagram.canvas.update() assert size < item.get_size()
def update_text(self, text): UML.parse(self._edit.subject, text)
def _on_end_name_change(self, entry): UML.parse(self.subject, entry.get_text())
def update_text(self, text): UML.parse(editable(self._edit.subject), text)
def test_parse_operation_invalid_syntax(self): """Test operation parsing with invalid syntax """ o = factory.create(UML.Operation) UML.parse(o, "- myfunc2: myType2") self.assertEqual("- myfunc2: myType2", o.name)