def test_write_properties_no_attribute(filename, element_factory): """Test for no property written with no attributes.""" book = element_factory.create(UML.Class) write_properties(book, filename) assert filename.data == ""
def test_write_properties_no_name(filename, element_factory): """Test writing a property when its attribute has no name.""" book = element_factory.create(UML.Class) book.ownedAttribute = element_factory.create(UML.Property) write_properties(book, filename) assert filename.data == ""
def test_write_properties_for_attribute(filename, element_factory): """Test writing a property for a normal attribute.""" book = element_factory.create(UML.Class) book.name = "Book" book.ownedAttribute = element_factory.create(UML.Property) book.ownedAttribute[0].name = "title" book.ownedAttribute[0].typeValue = "str" a = book.ownedAttribute[0] write_properties(book, filename) assert (filename.data == f'{book.name}.{a.name} = attribute("{a.name}", {a.typeValue})\n')
def test_write_properties_for_association(filename, element_factory): """Test writing property for an association.""" patron = element_factory.create(UML.Class) patron.ownedAttribute = element_factory.create(UML.Property) a = patron.ownedAttribute[0] a.name = "libraryCard" type_value = a.typeValue = "Card" a.upperValue = "1" a.aggregation = "composite" upper = f", upper={a.upperValue}" composite = ", composite=True" lower = opposite = "" write_properties(patron, filename) assert ( filename.data == f'{patron.name}.{a.name} = association("{a.name}", {type_value}{lower}{upper}{composite}{opposite})\n' )
def test_write_properties_for_enumeration(filename, element_factory): """Test writing property for an enumeration.""" book = element_factory.create(UML.Class) book.name = "Book" book.ownedAttribute = element_factory.create(UML.Property) book.ownedAttribute[0].name = "duration" book.ownedAttribute[0].typeValue = "loanDurationKind" a = book.ownedAttribute[0] enum = element_factory.create(UML.Class) enum.name = "loanDurationKind" enum.ownedAttribute = element_factory.create(UML.Property) enum.ownedAttribute[0].name = "14" e = enum.ownedAttribute[0] enumerations = {enum.name: enum} write_properties(book, filename, enumerations) assert ( filename.data == f'{book.name}.{a.name} = enumeration("kind", (\'{e.name}\',), "{e.name}")\n' )