Exemple #1
0
 def test_add_stereotype_instance_metaclass_correct_by_inheritance_of_stereotype(
         self):
     s1 = CStereotype("S1", extended=self.mcl)
     s2 = CStereotype("S2", superclasses=s1)
     c = CClass(self.mcl, "CL", stereotype_instances=s2)
     eq_(s2.extended_instances, [c])
     eq_(c.stereotype_instances, [s2])
    def test_stereotype_instances_on_association_link(self):
        s1 = CStereotype("S1", extended=self.a)
        s2 = CStereotype("S2", extended=self.a)
        s3 = CStereotype("S3", extended=self.a)

        c1 = CClass(self.m1, "C1")
        c2 = CClass(self.m2, "C2")
        c3 = CClass(self.m2, "C3")
        links = set_links({c1: [c2, c3]})
        l1 = links[0]

        eq_(l1.stereotype_instances, [])
        eq_(s1.extended_instances, [])
        l1.stereotype_instances = [s1]
        eq_(s1.extended_instances, [l1])
        eq_(l1.stereotype_instances, [s1])
        l1.stereotype_instances = [s1, s2, s3]
        eq_(s1.extended_instances, [l1])
        eq_(s2.extended_instances, [l1])
        eq_(s3.extended_instances, [l1])
        eq_(set(l1.stereotype_instances), {s1, s2, s3})
        l1.stereotype_instances = s2
        eq_(l1.stereotype_instances, [s2])
        eq_(s1.extended_instances, [])
        eq_(s2.extended_instances, [l1])
        eq_(s3.extended_instances, [])

        eq_(c1.get_links_for_association(self.a), links)
        eq_(c2.get_links_for_association(self.a), [l1])
        eq_(c3.get_links_for_association(self.a), [links[1]])
    def test_stereotype_instances_on_derived_association(self):
        s1 = CStereotype("S1", extended=self.a)
        s2 = CStereotype("S2", extended=self.a)
        s3 = CStereotype("S3", extended=self.a)

        c1 = CClass(self.m1, "C1")
        c2 = CClass(self.m2, "C2")

        a1 = c1.association(c2, name="a", multiplicity="*", role_name="c2",
                            source_multiplicity="1", source_role_name="c1", derived_from=self.a)

        eq_(a1.stereotype_instances, [])
        eq_(s1.extended_instances, [])
        a1.stereotype_instances = [s1]
        eq_(s1.extended_instances, [a1])
        eq_(a1.stereotype_instances, [s1])
        a1.stereotype_instances = [s1, s2, s3]
        eq_(s1.extended_instances, [a1])
        eq_(s2.extended_instances, [a1])
        eq_(s3.extended_instances, [a1])
        eq_(set(a1.stereotype_instances), {s1, s2, s3})
        a1.stereotype_instances = s2
        eq_(a1.stereotype_instances, [s2])
        eq_(s1.extended_instances, [])
        eq_(s2.extended_instances, [a1])
        eq_(s3.extended_instances, [])

        eq_(c1.associations, [a1])
        eq_(c2.associations, [a1])
Exemple #4
0
 def test_stereotype_extension_add_remove(self):
     s1 = CStereotype("S1")
     eq_(set(s1.extended), set())
     a1 = self.m1.association(self.m2,
                              multiplicity="1",
                              role_name="m1",
                              source_multiplicity="*",
                              source_role_name="m2",
                              stereotypes=[s1])
     eq_(set(s1.extended), {a1})
     eq_(set(a1.stereotypes), {s1})
     a2 = self.m1.association(self.m2,
                              multiplicity="1",
                              role_name="m1",
                              source_multiplicity="*",
                              source_role_name="m2",
                              stereotypes=s1)
     eq_(set(s1.extended), {a1, a2})
     eq_(set(a1.stereotypes), {s1})
     eq_(set(a2.stereotypes), {s1})
     s1.extended = [a2]
     eq_(set(s1.extended), {a2})
     eq_(set(a1.stereotypes), set())
     eq_(set(a2.stereotypes), {s1})
     s2 = CStereotype("S2", extended=[a2])
     eq_(set(a2.stereotypes), {s2, s1})
     eq_(set(s1.extended), {a2})
     eq_(set(s2.extended), {a2})
     a2.stereotypes = []
     eq_(set(a2.stereotypes), set())
     eq_(set(s1.extended), set())
     eq_(set(s2.extended), set())
Exemple #5
0
    def test_delete_tagged_values_with_superclass(self):
        sst = CStereotype("SST", attributes={"intVal": 20, "intVal2": 30})
        st = CStereotype("ST",
                         superclasses=sst,
                         attributes={
                             "isBoolean": True,
                             "intVal": 1
                         })
        self.mcl.stereotypes = st

        cl = CClass(self.mcl,
                    "C",
                    stereotype_instances=st,
                    tagged_values={"isBoolean": False})
        cl.delete_tagged_value("isBoolean")
        cl.delete_tagged_value("intVal2")
        eq_(cl.tagged_values, {"intVal": 1})

        cl.set_tagged_value("intVal", 2, sst)
        cl.set_tagged_value("intVal", 3, st)
        eq_(cl.tagged_values, {"intVal": 3})
        cl.delete_tagged_value("intVal")
        eq_(cl.tagged_values, {"intVal": 2})

        cl.set_tagged_value("intVal", 2, sst)
        cl.set_tagged_value("intVal", 3, st)
        cl.delete_tagged_value("intVal", st)
        eq_(cl.tagged_values, {"intVal": 2})

        cl.set_tagged_value("intVal", 2, sst)
        cl.set_tagged_value("intVal", 3, st)
        cl.delete_tagged_value("intVal", sst)
        eq_(cl.tagged_values, {"intVal": 3})
Exemple #6
0
    def test_default_values_on_stereotype_inheritance2(self):
        mcl = CMetaclass("MCL",
                         attributes={
                             "aStr2": "def",
                             "aList2": ["d1", "d2"],
                             "b": bool
                         })
        mcl2 = CMetaclass("MCL2",
                          superclasses=mcl,
                          attributes={
                              "aStr1": str,
                              "aList1": list
                          })
        try:
            CStereotype("S1",
                        extended=mcl,
                        default_values={
                            "aStr1": "a",
                            "aList2": []
                        })
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "attribute 'aStr1' unknown for metaclasses extended by stereotype 'S1'"
            )

        s2 = CStereotype("S2",
                         extended=mcl2,
                         default_values={
                             "aList1": ["a"],
                             "aStr2": "def2"
                         })
        eq_(s2.default_values, {"aList1": ["a"], "aStr2": "def2"})
Exemple #7
0
    def test_apply_stereotype_instances_wrong_metaclass_inheritance(self):
        mcl1 = CMetaclass("MCL1", superclasses=self.mcl)
        mcl2 = CMetaclass("MCL2", superclasses=self.mcl)
        s1 = CStereotype("S1", extended=mcl1)
        s2 = CStereotype("S2", extended=mcl2)
        super_stereotype = CStereotype("SuperST", extended=self.mcl)

        c = CClass(self.mcl, "CL")

        try:
            c.stereotype_instances = s1
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "stereotype 'S1' cannot be added to 'CL': no extension by this stereotype found"
            )

        c.stereotype_instances = super_stereotype

        mcl1_class = CClass(mcl1, "Mcl1Class", stereotype_instances=s1)
        try:
            mcl1_class.stereotype_instances = [s1, s2]
            exception_expected_()
        except CException as e:
            eq_(
                e.value,
                "stereotype 'S2' cannot be added to 'Mcl1Class': no extension by this stereotype found"
            )
        mcl1_class.stereotype_instances = [s1, super_stereotype]
        eq_(set(mcl1_class.stereotype_instances), {s1, super_stereotype})
        eq_(c.stereotype_instances, [super_stereotype])
 def test_extended_classes_of_inheriting_stereotypes__superclass_has_the_same(
         self):
     m1 = CMetaclass()
     s1 = CStereotype(extended=[m1])
     s2 = CStereotype(superclasses=[s1], extended=[m1])
     eq_(set(s1.extended), {m1})
     eq_(set(s2.extended), {m1})
     eq_(set(m1.stereotypes), {s2, s1})
 def test_stereotypes_that_are_deleted(self):
     s1 = CStereotype("S1")
     s1.delete()
     try:
         CMetaclass(stereotypes=[s1])
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
Exemple #10
0
 def test_attribute_get_name_and_classifier(self):
     cl = CStereotype("S", attributes={"isBoolean": True})
     a = cl.get_attribute("isBoolean")
     eq_(a.name, "isBoolean")
     eq_(a.classifier, cl)
     cl.delete()
     eq_(a.name, None)
     eq_(a.classifier, None)
Exemple #11
0
 def test_delete_stereotype_of_extended_instances(self):
     s1 = CStereotype("S1", extended=self.mcl)
     s1.delete()
     try:
         CClass(self.mcl, "C1", stereotype_instances=[s1])
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
Exemple #12
0
 def test_metaclass_stereotypes_append(self):
     s1 = CStereotype()
     s2 = CStereotype()
     m = CMetaclass(stereotypes=[s1])
     # should have no effect, as setter must be used
     m.stereotypes.append(s2)
     eq_(m.stereotypes, [s1])
     eq_(s1.extended, [m])
     eq_(s2.extended, [])
 def test_add_stereotype_instance_correct_by_inheritance_of_stereotype(
         self):
     s1 = CStereotype("S1", extended=self.a)
     s2 = CStereotype("S2", superclasses=s1)
     c1 = CClass(self.m1, "C1")
     c2 = CClass(self.m2, "C2")
     links = c1.add_links(c2, stereotype_instances=[s2])[0]
     eq_(s2.extended_instances, [links])
     eq_(links.stereotype_instances, [s2])
 def test_extended_classes_of_inheriting_stereotypes__superclass_is_set_to_the_same(
         self):
     m1 = CMetaclass("M1")
     s1 = CStereotype("S1")
     s2 = CStereotype("S2", extended=[m1], superclasses=[s1])
     m1.stereotypes = [s2, s1]
     eq_(set(s1.extended), {m1})
     eq_(set(s2.extended), {m1})
     eq_(set(m1.stereotypes), {s2, s1})
 def test_extended_classes_of_inheriting_stereotypes__remove_superclass_stereotype(
         self):
     m1 = CMetaclass()
     s1 = CStereotype(extended=[m1])
     s2 = CStereotype(superclasses=[s1], extended=[m1])
     m1.stereotypes = s2
     eq_(set(s1.extended), set())
     eq_(set(s2.extended), {m1})
     eq_(set(m1.stereotypes), {s2})
Exemple #16
0
 def test_creation_of_3_stereotypes(self):
     s1 = CStereotype("S1")
     s2 = CStereotype("S2")
     s3 = CStereotype("S3")
     self.mcl.stereotypes = [s1, s2, s3]
     eq_(s1.extended, [self.mcl])
     eq_(s2.extended, [self.mcl])
     eq_(s3.extended, [self.mcl])
     eq_(set(self.mcl.stereotypes), {s1, s2, s3})
 def test_extended_classes_of_inheriting_stereotypes__superclass_has_none(
         self):
     m1 = CMetaclass()
     m2 = CMetaclass(superclasses=[m1])
     s1 = CStereotype()
     s2 = CStereotype(superclasses=[s1])
     m2.stereotypes = s2
     eq_(len(s1.extended), 0)
     eq_(set(m2.stereotypes), {s2})
Exemple #18
0
 def test_all_extended_instances(self):
     s1 = CStereotype("S1", extended=self.mcl)
     s2 = CStereotype("S2", superclasses=s1)
     c1 = CClass(self.mcl, "C1", stereotype_instances=s1)
     c2 = CClass(self.mcl, "C2", stereotype_instances=s2)
     eq_(s1.extended_instances, [c1])
     eq_(s2.extended_instances, [c2])
     eq_(s1.all_extended_instances, [c1, c2])
     eq_(s2.all_extended_instances, [c2])
Exemple #19
0
 def test_delete_stereotype_having_two_bundles(self):
     b1 = CBundle("B1")
     b2 = CBundle("B2")
     s1 = CStereotype("s1", bundles=[b1, b2])
     s2 = CStereotype("s2", bundles=[b2])
     s1.delete()
     eq_(set(b1.get_elements(type=CStereotype)), set())
     eq_(set(b2.get_elements(type=CStereotype)), {s2})
     eq_(set(s1.bundles), set())
     eq_(set(s2.bundles), {b2})
Exemple #20
0
 def test_delete_default_value_from_stereotype_on_no_extension_fails(self):
     try:
         s1 = CStereotype("S1")
         s1.delete_default_value("a")
         exception_expected_()
     except CException as e:
         eq_(
             e.value,
             "default values can only be used on a stereotype that extends metaclasses"
         )
Exemple #21
0
 def test_get_default_value_from_stereotype_on_association_fails(self):
     try:
         s1 = CStereotype("S1", extended=self.a)
         s1.get_default_value("a")
         exception_expected_()
     except CException as e:
         eq_(
             e.value,
             "default values can only be used on a stereotype that extends metaclasses"
         )
 def test_stereotype_unknown_non_positional_argument(self):
     t = CStereotype("T")
     try:
         CStereotype("ST", superclass=t)
         exception_expected_()
     except CException as e:
         eq_(
             "unknown keyword argument 'superclass', should be one of: " +
             "['extended', 'default_values', 'attributes', 'superclasses', 'bundles']",
             e.value)
Exemple #23
0
 def test_multiple_extended_instances(self):
     s1 = CStereotype("S1", extended=self.mcl)
     s2 = CStereotype("S2", extended=self.mcl)
     c1 = CClass(self.mcl, "C1", stereotype_instances=[s1])
     eq_(s1.extended_instances, [c1])
     c2 = CClass(self.mcl, "C2", stereotype_instances=s1)
     eq_(set(s1.extended_instances), {c1, c2})
     c3 = CClass(self.mcl, "C3", stereotype_instances=[s1, s2])
     eq_(set(s1.extended_instances), {c1, c2, c3})
     eq_(set(s2.extended_instances), {c3})
 def test_add_stereotype_instance_correct_by_inheritance_of_stereotype(self):
     s1 = CStereotype("S1", extended=self.a)
     s2 = CStereotype("S2", superclasses=s1)
     c1 = CClass(self.m1, "C1")
     c2 = CClass(self.m2, "C2")
     a1 = c1.association(c2, name="a", multiplicity="*", role_name="c2",
                         source_multiplicity="1", source_role_name="c1", derived_from=self.a,
                         stereotype_instances=s2)
     eq_(s2.extended_instances, [a1])
     eq_(a1.stereotype_instances, [s2])
Exemple #25
0
 def test_stereotype_defined_bundles(self):
     eq_(set(self.b1.get_elements(type=CStereotype)), set())
     s1 = CStereotype("s1", bundles=self.b1)
     eq_(set(self.b1.get_elements(type=CStereotype)), {s1})
     s2 = CStereotype("s2", bundles=[self.b1])
     s3 = CStereotype("s3", bundles=[self.b1, self.b2])
     cl = CClass(self.mcl, "C", bundles=self.b1)
     eq_(set(self.b1.get_elements(type=CStereotype)), {s1, s2, s3})
     eq_(set(self.b1.elements), {s1, s2, s3, cl})
     eq_(set(self.b2.get_elements(type=CStereotype)), {s3})
     eq_(set(self.b2.elements), {s3})
Exemple #26
0
 def test_creation_of_unnamed_stereotype_in_bundle(self):
     cl = CClass(self.mcl)
     s1 = CStereotype()
     s2 = CStereotype()
     s3 = CStereotype("x")
     self.b1.elements = [s1, s2, s3, cl]
     eq_(set(self.b1.get_elements(type=CStereotype)), {s1, s2, s3})
     eq_(self.b1.get_element(name=None), s1)
     eq_(set(self.b1.get_elements(type=CStereotype, name=None)), {s1, s2})
     eq_(self.b1.get_element(name=None), s1)
     eq_(set(self.b1.get_elements(name=None)), {s1, s2, cl})
Exemple #27
0
 def test_bundle_delete_stereotype_association(self):
     s1 = CStereotype("s1", bundles=self.b1, extended=self.a)
     eq_(s1.extended, [self.a])
     s2 = CStereotype("s2", bundles=self.b1)
     s3 = CStereotype("s3", bundles=self.b1)
     self.b1.delete()
     eq_(set(self.b1.elements), set())
     eq_(s1.bundles, [])
     eq_(s1.extended, [self.a])
     eq_(s2.bundles, [])
     eq_(s3.bundles, [])
Exemple #28
0
 def test_bundle_delete_stereotype_metaclass(self):
     s1 = CStereotype("s1", bundles=self.b1, extended=self.mcl)
     eq_(s1.extended, [self.mcl])
     s2 = CStereotype("s2", bundles=self.b1)
     s3 = CStereotype("s3", bundles=self.b1)
     self.b1.delete()
     eq_(set(self.b1.elements), set())
     eq_(s1.bundles, [])
     eq_(s1.extended, [self.mcl])
     eq_(s2.bundles, [])
     eq_(s3.bundles, [])
 def test_delete_stereotype_of_extended_instances(self):
     s1 = CStereotype("S1", extended=self.a)
     s1.delete()
     c1 = CClass(self.m1, "C1")
     c2 = CClass(self.m2, "C2")
     links = set_links({c1: c2})[0]
     try:
         links.stereotype_instances = [s1]
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
Exemple #30
0
    def test_default_values_from_stereotype__metaclass_delete(self):
        mcl = CMetaclass("MCL",
                         attributes={
                             "aStr2": "def",
                             "aList2": ["d1", "d2"],
                             "b": bool
                         })
        mcl2 = CMetaclass("MCL2",
                          superclasses=mcl,
                          attributes={
                              "aStr1": str,
                              "aList1": list
                          })
        s1 = CStereotype("S1",
                         extended=mcl2,
                         default_values={
                             "aStr1": "a",
                             "aList2": []
                         })
        s2 = CStereotype("S2",
                         superclasses=s1,
                         extended=mcl2,
                         default_values={
                             "aList1": ["a"],
                             "aStr2": "def2"
                         })
        c1 = CClass(mcl2, "C1", stereotype_instances=s2)
        mcl.delete()
        c2 = CClass(mcl2, "C2", stereotype_instances=s1)
        c3 = CClass(mcl2, "C3", stereotype_instances=s2)

        eq_(c1.get_value("aStr1"), "a")
        eq_(c1.get_value("aList1"), ["a"])
        try:
            eq_(c1.get_value("aStr2"), "def2")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'aStr2' unknown for 'C1'")

        eq_(c2.get_value("aStr1"), "a")
        eq_(c2.get_value("aList1"), None)
        try:
            eq_(c2.get_value("aStr2"), "def2")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'aStr2' unknown for 'C2'")

        eq_(c3.get_value("aStr1"), "a")
        eq_(c3.get_value("aList1"), ["a"])
        try:
            eq_(c3.get_value("aStr2"), "def2")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'aStr2' unknown for 'C3'")