def test_association_end_with_applied_stereotype(factory): a = factory.create(UML.Property) a.association = factory.create(UML.Association) parse(a, "myattr[1]") add_tag_is_foo_metadata_field(a, factory) assert ("+ myattr", '1 { tag = "foo" }') == format(a)
def test_association_end(factory, text, name_part, mult_part): """Test simple attribute formatting.""" a = factory.create(UML.Property) a.association = factory.create(UML.Association) parse(a, text) assert (name_part, mult_part) == format_association_end(a)
def test_attribute(factory, text, formatted_text): """Test simple attribute formatting """ a = factory.create(UML.Property) parse(a, text) assert formatted_text == format(a)
def test_operation(factory, text, formatted_text): """Test simple operation formatting """ o = factory.create(UML.Operation) parse(o, text) assert formatted_text == format(o)
def test_parse_operation(self): """Test parsing simple operation """ o = factory.create(uml2.Operation) parse(o, 'myfunc()') self.assertEquals('myfunc', o.name) self.assertTrue(not o.returnResult[0].typeValue) self.assertFalse(o.formalParameter)
def add_tag_is_foo_metadata_field(e, factory): s = factory.create(UML.Stereotype) s.ownedAttribute = factory.create(UML.Property) parse(s.ownedAttribute[0], "tag: str") instance_spec = model.apply_stereotype(e, s) slot = model.add_slot(instance_spec, s.ownedAttribute[0]) slot.value = "foo" return slot
def test_parse_operation_return(self): """Test parsing operation with return value """ o = factory.create(uml2.Operation) 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(self): """Test simple property parsing """ a = factory.create(uml2.Property) 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_operation_1_param(self): """Test parsing of operation with one parameter """ o = factory.create(uml2.Operation) 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_multiplicity2(self): """Test parsing of multiplicity with multiline constraints """ a = factory.create(uml2.Association) p = factory.create(uml2.Property) p.association = a 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(uml2.Property) 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(self): factory = elementfactory.ElementFactory() self.assertEquals(0, len(factory.lselect())) c = factory.create(uml2.Class) c.name = 'Class' o = factory.create(uml2.Operation) c.ownedOperation = o umllex.parse(o, 'a(x: int, y: int)') c.unlink() self.assertEquals(0, len(factory.lselect()), factory.lselect())
def test_parse_property_complex(self): """Test complex property parsing """ a = factory.create(uml2.Property) 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_parse_association_end(self): """Test parsing of association end """ a = factory.create(uml2.Association) p = factory.create(uml2.Property) p.association = a 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_parse_derived_end(self): """Test parsing derived association end """ a = factory.create(uml2.Association) p = factory.create(uml2.Property) p.association = a 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(self): """Test parsing of operation with two parameters """ o = factory.create(uml2.Operation) 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 _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. """ try: model = self.get_property("model") iter = model.get_iter_from_string(path_str) element = model.get_value(iter, 0) if isinstance(element, (UML.Property, UML.Operation)): parse(element, new_text) else: element.name = new_text except Exception: log.error(f'Could not create path from string "{path_str}"')
def testAttribute(self): """ Test how attribute is updated """ attr = self.element_factory.create(uml2.Property) umllex.parse(attr, '-name:myType') clazzitem = self.create(ClassItem, uml2.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 test_attribute_with_applied_stereotype(factory): a = factory.create(UML.Property) parse(a, "myattr: int") add_tag_is_foo_metadata_field(a, factory) assert '+ myattr: int { tag = "foo" }' == format(a, tags=True)
def test_slot(factory): a = factory.create(UML.Property) parse(a, "myattr: int") slot = add_tag_is_foo_metadata_field(a, factory) assert 'tag = "foo"' == format(slot)
def test_parse_operation_invalid_syntax(self): """Test operation parsing with invalid syntax """ o = factory.create(uml2.Operation) parse(o, '- myfunc2: myType2') self.assertEquals('- myfunc2: myType2', o.name)
def update_text(self, text): umllex.parse(editable(self._edit.subject), text)