示例#1
0
 def test_enum_get_values(self):
     enum_values = ["A", "B", "C"]
     enum_obj = CEnum("ABCEnum", values=enum_values)
     eq_(["A", "B", "C"], enum_obj.values)
     ok_("A" in enum_obj.values)
     ok_(not ("X" in enum_obj.values))
     enum_values = [1, 2, 3]
     enum_obj = CEnum("123Enum", values=enum_values)
     eq_([1, 2, 3], enum_obj.values)
示例#2
0
 def test_bundle_delete_enum(self):
     e1 = CEnum("E1", bundles=self.b1)
     e2 = CEnum("E2", bundles=self.b1)
     e3 = CEnum("E3", bundles=self.b1)
     self.b1.delete()
     eq_(set(self.b1.elements), set())
     eq_(e1.bundles, [])
     eq_(e1.name, "E1")
     eq_(e2.bundles, [])
     eq_(e3.bundles, [])
示例#3
0
 def test_delete_enum_having_two_bundles(self):
     b1 = CBundle("B1")
     b2 = CBundle("B2")
     e1 = CEnum("e1", bundles=[b1, b2])
     e2 = CEnum("e2", bundles=[b2])
     e1.delete()
     eq_(set(b1.get_elements(type=CEnum)), set())
     eq_(set(b2.get_elements(type=CEnum)), {e2})
     eq_(set(e1.bundles), set())
     eq_(set(e2.bundles), {b2})
示例#4
0
 def test_creation_of_unnamed_enum_in_bundle(self):
     e1 = CEnum()
     e2 = CEnum()
     e3 = CEnum("x")
     mcl = CMetaclass()
     self.b1.elements = [e1, e2, e3, mcl]
     eq_(set(self.b1.get_elements(type=CEnum)), {e1, e2, e3})
     eq_(self.b1.get_element(type=CEnum, name=None), e1)
     eq_(set(self.b1.get_elements(type=CEnum, name=None)), {e1, e2})
     eq_(set(self.b1.get_elements(name=None)), {e1, e2, mcl})
示例#5
0
 def test_enum_defined_bundles(self):
     eq_(set(self.b1.get_elements()), set())
     e1 = CEnum("E1", values=["A", "B", "C"], bundles=self.b1)
     eq_(set(self.b1.get_elements()), {e1})
     e2 = CEnum("E2", values=["A", "B", "C"], bundles=[self.b1])
     e3 = CEnum("E3", values=["A", "B", "C"], bundles=[self.b1, self.b2])
     mcl = CMetaclass("MCL", bundles=self.b1)
     eq_(set(self.b1.get_elements(type=CEnum)), {e1, e2, e3})
     eq_(set(self.b1.elements), {e1, e2, e3, mcl})
     eq_(set(self.b2.get_elements(type=CEnum)), {e3})
     eq_(set(self.b2.elements), {e3})
示例#6
0
 def test_get_enum_elements_by_name(self):
     eq_(set(self.b1.get_elements(name="E1")), set())
     e1 = CEnum("E1", bundles=self.b1)
     eq_(set(self.b1.get_elements(name="E1")), {e1})
     m = CMetaclass("E1", bundles=self.b1)
     eq_(set(self.b1.get_elements(name="E1")), {m, e1})
     e2 = CEnum("E1", bundles=self.b1)
     eq_(set(self.b1.get_elements(name="E1")), {m, e1, e2})
     ok_(e1 != e2)
     e3 = CEnum("E1", bundles=self.b1)
     eq_(set(self.b1.get_elements(name="E1")), {m, e1, e2, e3})
     eq_(self.b1.get_element(name="E1"), e1)
示例#7
0
 def test_default_init_after_instance_creation(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     self.st.attributes = {"e1": enum_type, "e2": enum_type}
     e2 = self.st.get_attribute("e2")
     e2.default = "A"
     eq_(self.cl.get_tagged_value("e1"), None)
     eq_(self.cl.get_tagged_value("e2"), "A")
示例#8
0
 def test_bundle_defined_enums(self):
     e1 = CEnum("E1", values=["A", "B", "C"])
     e2 = CEnum("E2", values=["A", "B", "C"])
     e3 = CEnum("E3", values=["A", "B", "C"])
     eq_(set(self.b1.get_elements(type=CEnum)), set())
     b1 = CBundle("B1", elements=[e1, e2, e3])
     eq_(set(b1.elements), {e1, e2, e3})
     self.mcl.bundles = b1
     eq_(set(b1.elements), {e1, e2, e3, self.mcl})
     eq_(set(b1.get_elements(type=CEnum)), {e1, e2, e3})
     b2 = CBundle("B2")
     b2.elements = [e2, e3]
     eq_(set(b2.get_elements(type=CEnum)), {e2, e3})
     eq_(set(e1.bundles), {b1})
     eq_(set(e2.bundles), {b1, b2})
     eq_(set(e3.bundles), {b1, b2})
示例#9
0
 def test_delete_bundle_from_two_bundles(self):
     b1 = CBundle("B1")
     b2 = CBundle("B2")
     e1 = CEnum("e1", bundles=[b1, b2])
     b1.delete()
     eq_(set(b1.get_elements(type=CEnum)), set())
     eq_(set(b2.get_elements(type=CEnum)), {e1})
     eq_(set(e1.bundles), {b2})
示例#10
0
 def test_enum_name_fail(self):
     try:
         # noinspection PyTypeChecker
         CEnum(self.mcl)
         exception_expected_()
     except CException as e:
         ok_(e.value.startswith("is not a name string: '"))
         ok_(e.value.endswith(" MCL'"))
示例#11
0
 def test_default_init_after_instance_creation(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     mcl = CMetaclass(attributes={"e1": enum_type, "e2": enum_type})
     cl = CClass(mcl, "C")
     e2 = mcl.get_attribute("e2")
     e2.default = "A"
     eq_(cl.get_value("e1"), None)
     eq_(cl.get_value("e2"), "A")
示例#12
0
 def test_bundle_that_is_deleted(self):
     b1 = CBundle("B1")
     b1.delete()
     try:
         CEnum("E1", bundles=b1)
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
    def test_remove_class_from_bundle(self):
        b1 = CBundle("B1")
        b2 = CBundle("B2")
        cl1 = CClass(self.mcl, "CL1", bundles=b1)
        try:
            # noinspection PyTypeChecker
            b1.remove(None)
            exception_expected_()
        except CException as e:
            eq_("'None' is not an element of the bundle", e.value)
        try:
            b1.remove(CEnum("A"))
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        try:
            b2.remove(cl1)
            exception_expected_()
        except CException as e:
            eq_("'CL1' is not an element of the bundle", e.value)
        b1.remove(cl1)
        eq_(set(b1.get_elements(type=CClass)), set())

        cl1 = CClass(self.mcl, "CL1", bundles=b1)
        cl2 = CClass(self.mcl, "CL2", bundles=b1)
        cl3 = CClass(self.mcl,
                     "CL3",
                     superclasses=cl2,
                     attributes={"i": 1},
                     bundles=b1)
        cl3.set_value("i", 7)
        o = CObject(cl3, bundles=b1)

        b1.remove(cl1)
        try:
            b1.remove(CClass(CMetaclass("MCL", bundles=b2), "CL2", bundles=b2))
            exception_expected_()
        except CException as e:
            eq_("'CL2' is not an element of the bundle", e.value)
        try:
            b1.remove(cl1)
            exception_expected_()
        except CException as e:
            eq_("'CL1' is not an element of the bundle", e.value)

        eq_(set(b1.get_elements(type=CClass)), {cl2, cl3})
        b1.remove(cl3)
        eq_(set(b1.get_elements(type=CClass)), {cl2})

        eq_(cl3.superclasses, [cl2])
        eq_(cl2.subclasses, [cl3])
        eq_(cl3.attribute_names, ["i"])
        eq_(cl3.metaclass, self.mcl)
        eq_(cl3.objects, [o])
        eq_(cl3.name, "CL3")
        eq_(cl3.bundles, [])
        eq_(b1.get_elements(type=CObject), [o])
        eq_(cl3.get_value("i"), 7)
 def test_attribute_value_type_check_enum(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     self.cl.attributes = {"t": enum_type}
     o = CObject(self.cl, "o")
     try:
         o.set_value("t", True)
         exception_expected_()
     except CException as e:
         eq_(f"value type for attribute 't' does not match attribute type", e.value)
示例#15
0
 def test_enum_no_list(self):
     enum_values = {"A", "B", "C"}
     try:
         CEnum("ABCEnum", values=enum_values)
         exception_expected_()
     except CException as e:
         ok_(
             re.match(
                 "^an enum needs to be initialized with a list of values, but got:([ {}'CAB,]+)$",
                 e.value))
示例#16
0
 def test_delete_enum_that_is_an_attribute_type(self):
     b1 = CBundle("B1")
     CBundle("B2")
     e1 = CEnum("E1", bundles=b1)
     e2 = CEnum("E2", bundles=b1)
     e3 = CEnum("E3", values=["1", "2"], bundles=b1)
     ea1 = CAttribute(type=e3, default="1")
     ea2 = CAttribute(type=e3)
     cl = CClass(self.mcl, attributes={"letters1": ea1, "letters2": ea2})
     o = CObject(cl, "o")
     e1.delete()
     e3.delete()
     try:
         ea1.default = "3"
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
     try:
         ea1.type = e1
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
     try:
         ea1.default = "3"
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
     try:
         ea1.type = e1
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
     try:
         ea1.type = e2
         exception_expected_()
     except CException as e:
         eq_("default value '1' incompatible with attribute's type 'E2'",
             e.value)
     try:
         o.set_value("letters1", "1")
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
     try:
         o.get_value("letters1")
         exception_expected_()
     except CException as e:
         eq_("cannot access named element that has been deleted", e.value)
 def test_default_init_after_instance_creation(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     cl = CClass(self.mcl, "C", attributes={
         "e1": enum_type,
         "e2": enum_type})
     o = CObject(cl, "o")
     e2 = cl.get_attribute("e2")
     e2.default = "A"
     eq_(o.get_value("e1"), None)
     eq_(o.get_value("e2"), "A")
示例#18
0
 def test_attribute_value_type_check_enum(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     self.st.attributes = {"t": enum_type}
     cl = CClass(self.mcl, "C", stereotype_instances=self.st)
     try:
         cl.set_tagged_value("t", True)
         exception_expected_()
     except CException as e:
         eq_(f"value type for attribute 't' does not match attribute type",
             e.value)
示例#19
0
 def test_set_attribute_default_value(self):
     enum_obj = CEnum("ABCEnum", values=["A", "B", "C"])
     self.mcl.attributes = {"letters": enum_obj, "b": bool}
     letters = self.mcl.get_attribute("letters")
     b = self.mcl.get_attribute("b")
     eq_(letters.default, None)
     eq_(b.default, None)
     letters.default = "B"
     b.default = False
     eq_(letters.default, "B")
     eq_(b.default, False)
     eq_(letters.type, enum_obj)
     eq_(b.type, bool)
    def test_remove_metaclass_from_bundle(self):
        b1 = CBundle("B1")
        b2 = CBundle("B2")
        m1 = CMetaclass("M1", bundles=b1)
        try:
            # noinspection PyTypeChecker
            b1.remove(None)
            exception_expected_()
        except CException as e:
            eq_("'None' is not an element of the bundle", e.value)
        try:
            b1.remove(CEnum("A"))
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        try:
            b2.remove(m1)
            exception_expected_()
        except CException as e:
            eq_("'M1' is not an element of the bundle", e.value)
        b1.remove(m1)
        eq_(set(b1.get_elements(type=CMetaclass)), set())

        m1 = CMetaclass("M1", bundles=b1)
        m2 = CMetaclass("M1", bundles=b1)
        m3 = CMetaclass("M1", superclasses=m2, attributes={"i": 1}, bundles=b1)
        c = CClass(m3, bundles=b1)

        b1.remove(m1)
        try:
            b1.remove(CMetaclass("M2", bundles=b2))
            exception_expected_()
        except CException as e:
            eq_("'M2' is not an element of the bundle", e.value)
        try:
            b1.remove(m1)
            exception_expected_()
        except CException as e:
            eq_("'M1' is not an element of the bundle", e.value)

        eq_(set(b1.get_elements(type=CMetaclass)), {m2, m3})
        b1.remove(m3)
        eq_(set(b1.get_elements(type=CMetaclass)), {m2})

        eq_(m3.superclasses, [m2])
        eq_(m2.subclasses, [m3])
        eq_(m3.attribute_names, ["i"])
        eq_(m3.classes, [c])
        eq_(m3.name, "M1")
        eq_(m3.bundles, [])
        eq_(b1.get_elements(type=CClass), [c])
 def test_values_on_attributes_with_no_default_values(self):
     attribute_type = CClass(self.mcl, "AttrType")
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     cl = CClass(self.mcl, "C", attributes={
         "b": bool,
         "i": int,
         "f": float,
         "s": str,
         "l": list,
         "o": attribute_type,
         "e": enum_type})
     o = CObject(cl, "o")
     for n in ["b", "i", "f", "s", "l", "o", "e"]:
         eq_(o.get_value(n), None)
    def test_remove_bundle_from_bundle(self):
        b1 = CBundle("B1")
        b2 = CBundle("B2")
        ba = CBundle("A", bundles=b1)
        try:
            # noinspection PyTypeChecker
            b1.remove(None)
            exception_expected_()
        except CException as e:
            eq_("'None' is not an element of the bundle", e.value)
        try:
            b1.remove(CEnum("A"))
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        try:
            b2.remove(ba)
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        b1.remove(ba)
        eq_(set(b1.get_elements(type=CBundle)), set())

        mcl1 = CMetaclass("MCL")
        cl1 = CClass(mcl1, "CL")

        ba = CBundle("PA", bundles=b1)
        bb = CBundle("PB", bundles=b1)
        bc = CBundle("PC", bundles=b1, elements=[mcl1, cl1])

        b1.remove(ba)
        try:
            b1.remove(CBundle("PB", bundles=b2))
            exception_expected_()
        except CException as e:
            eq_("'PB' is not an element of the bundle", e.value)
        try:
            b1.remove(ba)
            exception_expected_()
        except CException as e:
            eq_("'PA' is not an element of the bundle", e.value)

        eq_(set(b1.get_elements(type=CBundle)), {bb, bc})
        b1.remove(bc)
        eq_(set(b1.get_elements(type=CBundle)), {bb})

        eq_(bc.get_elements(type=CBundle), [])
        eq_(bc.get_elements(type=CBundle), [])
        eq_(bc.elements, [mcl1, cl1])
示例#23
0
    def test_use_enum_type_attribute(self):
        enum_values = ["A", "B", "C"]
        enum_obj = CEnum("ABCEnum", values=enum_values)
        ea1 = CAttribute(type=enum_obj, default="A")
        ea2 = CAttribute(type=enum_obj)
        self.mcl.attributes = {"letters1": ea1, "letters2": ea2}
        eq_(set(self.mcl.attributes), {ea1, ea2})
        ok_(isinstance(ea1.type, CEnum))

        self.mcl.attributes = {"letters1": ea1, "isBool": True, "letters2": ea2}
        bool_attr = self.mcl.get_attribute("isBool")
        l1 = self.mcl.get_attribute("letters1")
        eq_(set(self.mcl.attributes), {l1, ea2, bool_attr})
        eq_(l1.default, "A")
        eq_(ea2.default, None)
示例#24
0
 def test_enum_type_attribute_values(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     self.st.attributes = {"e1": enum_type, "e2": enum_type}
     e2 = self.st.get_attribute("e2")
     e2.default = "A"
     eq_(self.cl.get_tagged_value("e1"), None)
     eq_(self.cl.get_tagged_value("e2"), "A")
     self.cl.set_tagged_value("e1", "B")
     self.cl.set_tagged_value("e2", "C")
     eq_(self.cl.get_tagged_value("e1"), "B")
     eq_(self.cl.get_tagged_value("e2"), "C")
     try:
         self.cl.set_tagged_value("e1", "X")
         exception_expected_()
     except CException as e:
         eq_(e.value, "value 'X' is not element of enumeration")
示例#25
0
 def test_tagged_values_on_attributes_with_no_default_values(self):
     attribute_type = CClass(self.mcl, "AttrType")
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     st = CStereotype("S",
                      attributes={
                          "b": bool,
                          "i": int,
                          "f": float,
                          "s": str,
                          "l": list,
                          "C": attribute_type,
                          "e": enum_type
                      })
     mcl = CMetaclass("M", stereotypes=st)
     cl = CClass(mcl, "C", stereotype_instances=st)
     for n in ["b", "i", "f", "s", "l", "C", "e"]:
         eq_(cl.get_tagged_value(n), None)
示例#26
0
 def test_enum_type_attribute_values(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     mcl = CMetaclass(attributes={"e1": enum_type, "e2": enum_type})
     e2 = mcl.get_attribute("e2")
     e2.default = "A"
     cl = CClass(mcl, "C")
     eq_(cl.get_value("e1"), None)
     eq_(cl.get_value("e2"), "A")
     cl.set_value("e1", "B")
     cl.set_value("e2", "C")
     eq_(cl.get_value("e1"), "B")
     eq_(cl.get_value("e2"), "C")
     try:
         cl.set_value("e1", "X")
         exception_expected_()
     except CException as e:
         eq_(e.value, "value 'X' is not element of enumeration")
示例#27
0
 def test_enum_defined_bundle_change(self):
     e1 = CEnum("E1", bundles=self.b1)
     e2 = CEnum("E2", bundles=self.b1)
     e3 = CEnum("E3", bundles=self.b1)
     mcl = CMetaclass("MCL", bundles=self.b1)
     b = CBundle()
     e2.bundles = b
     e3.bundles = None
     self.mcl.bundles = b
     eq_(set(self.b1.elements), {mcl, e1})
     eq_(set(self.b1.get_elements(type=CEnum)), {e1})
     eq_(set(b.elements), {e2, self.mcl})
     eq_(set(b.get_elements(type=CEnum)), {e2})
     eq_(e1.bundles, [self.b1])
     eq_(e2.bundles, [b])
     eq_(e3.bundles, [])
示例#28
0
 def test_define_enum_type_attribute(self):
     enum_values = ["A", "B", "C"]
     enum_obj = CEnum("ABCEnum", values=enum_values)
     CAttribute(type=enum_obj, default="A")
     CAttribute(default="A", type=enum_obj)
     try:
         CAttribute(type=enum_obj, default="X")
         exception_expected_()
     except CException as e:
         eq_(
             "default value 'X' incompatible with attribute's type 'ABCEnum'",
             e.value)
     try:
         CAttribute(default="X", type=enum_obj)
         exception_expected_()
     except CException as e:
         eq_(
             "default value 'X' incompatible with attribute's type 'ABCEnum'",
             e.value)
示例#29
0
    def test_remove_enum_from_bundle(self):
        b1 = CBundle("B1")
        b2 = CBundle("B2")
        e1 = CEnum("E1", bundles=b1)
        try:
            # noinspection PyTypeChecker
            b1.remove(None)
            exception_expected_()
        except CException as e:
            eq_("'None' is not an element of the bundle", e.value)
        try:
            b1.remove(CEnum("A"))
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        try:
            b2.remove(e1)
            exception_expected_()
        except CException as e:
            eq_("'E1' is not an element of the bundle", e.value)
        b1.remove(e1)
        eq_(set(b1.get_elements(type=CEnum)), set())

        e1 = CEnum("E1", bundles=b1)
        e2 = CEnum("E2", bundles=b1)
        e3 = CEnum("E3", values=["1", "2"], bundles=b1)

        b1.remove(e1)
        try:
            b1.remove(CEnum("E2", bundles=b2))
            exception_expected_()
        except CException as e:
            eq_("'E2' is not an element of the bundle", e.value)
        try:
            b1.remove(e1)
            exception_expected_()
        except CException as e:
            eq_("'E1' is not an element of the bundle", e.value)

        eq_(set(b1.get_elements(type=CEnum)), {e2, e3})
        b1.remove(e3)
        eq_(set(b1.get_elements(type=CEnum)), {e2})

        eq_(e3.name, "E3")
        eq_(e3.bundles, [])
        eq_(e3.values, ["1", "2"])
示例#30
0
    def test_remove_stereotype_from_bundle(self):
        b1 = CBundle("B1")
        b2 = CBundle("B2")
        s1 = CStereotype("s1", bundles=b1)
        try:
            # noinspection PyTypeChecker
            b1.remove(None)
            exception_expected_()
        except CException as e:
            eq_("'None' is not an element of the bundle", e.value)
        try:
            b1.remove(CEnum("A"))
            exception_expected_()
        except CException as e:
            eq_("'A' is not an element of the bundle", e.value)
        try:
            b2.remove(s1)
            exception_expected_()
        except CException as e:
            eq_("'s1' is not an element of the bundle", e.value)
        b1.remove(s1)
        eq_(set(b1.get_elements(type=CStereotype)), set())

        s1 = CStereotype("s1", bundles=b1)
        s2 = CStereotype("s1", bundles=b1)
        s3 = CStereotype("s1",
                         superclasses=s2,
                         attributes={"i": 1},
                         bundles=b1,
                         extended=self.mcl)
        s4 = CStereotype("s1",
                         superclasses=s2,
                         attributes={"i": 1},
                         bundles=b1,
                         extended=self.a)

        b1.remove(s1)
        try:
            b1.remove(CStereotype("s2", bundles=b2))
            exception_expected_()
        except CException as e:
            eq_("'s2' is not an element of the bundle", e.value)
        try:
            b1.remove(s1)
            exception_expected_()
        except CException as e:
            eq_("'s1' is not an element of the bundle", e.value)

        eq_(set(b1.get_elements(type=CStereotype)), {s2, s3, s4})
        b1.remove(s3)
        b1.remove(s4)
        eq_(set(b1.get_elements(type=CStereotype)), {s2})

        eq_(s3.superclasses, [s2])
        eq_(s2.subclasses, [s3, s4])
        eq_(s3.attribute_names, ["i"])
        eq_(s3.extended, [self.mcl])
        eq_(s3.name, "s1")
        eq_(s3.bundles, [])
        eq_(s4.superclasses, [s2])
        eq_(s4.attribute_names, ["i"])
        eq_(s4.extended, [self.a])
        eq_(s4.name, "s1")
        eq_(s4.bundles, [])