Exemplo n.º 1
0
    def test_class_type_attribute(self):
        attribute_type = CMetaclass("AttrType")
        attribute_value = CClass(attribute_type, "attribute_value")
        self.stereotype.attributes = {"attrTypeCl": attribute_type}
        class_attribute = self.stereotype.get_attribute("attrTypeCl")
        class_attribute.default = attribute_value
        attributes = self.stereotype.attributes
        eq_(set(attributes), {class_attribute})

        bool_attr = CAttribute(default=True)
        self.stereotype.attributes = {
            "attrTypeCl": class_attribute,
            "isBoolean": bool_attr
        }
        attributes = self.stereotype.attributes
        eq_(set(attributes), {class_attribute, bool_attr})
        eq_(self.stereotype.attribute_names, ["attrTypeCl", "isBoolean"])
        class_attribute = self.stereotype.get_attribute("attrTypeCl")
        eq_(class_attribute.type, attribute_type)
        default = class_attribute.default
        ok_(isinstance(default, CClass))
        eq_(default, attribute_value)

        self.stereotype.attributes = {
            "attrTypeCl": attribute_value,
            "isBoolean": bool_attr
        }
        eq_(self.stereotype.attribute_names, ["attrTypeCl", "isBoolean"])
        # using the CClass in attributes causes a new CAttribute to be created != class_attribute
        neq_(self.stereotype.get_attribute("attrTypeCl"), class_attribute)
Exemplo n.º 2
0
    def test_object_type_attribute(self):
        attribute_type = CClass(self.mcl, "AttrType")
        attribute_value = CObject(attribute_type, "attribute_value")
        self.stereotype.attributes = {"attrTypeObj": attribute_value}
        object_attribute = self.stereotype.get_attribute("attrTypeObj")
        attributes = self.stereotype.attributes
        eq_(set(attributes), {object_attribute})

        bool_attr = CAttribute(default=True)
        self.stereotype.attributes = {
            "attrTypeObj": object_attribute,
            "isBoolean": bool_attr
        }
        attributes = self.stereotype.attributes
        eq_(set(attributes), {object_attribute, bool_attr})
        eq_(self.stereotype.attribute_names, ["attrTypeObj", "isBoolean"])
        object_attribute = self.stereotype.get_attribute("attrTypeObj")
        eq_(object_attribute.type, attribute_type)
        default = object_attribute.default
        ok_(isinstance(default, CObject))
        eq_(default, attribute_value)

        self.stereotype.attributes = {
            "attrTypeObj": attribute_value,
            "isBoolean": bool_attr
        }
        eq_(self.stereotype.attribute_names, ["attrTypeObj", "isBoolean"])
        # using the CObject in attributes causes a new CAttribute to be created != object_attribute
        neq_(self.stereotype.get_attribute("attrTypeObj"), object_attribute)