def test_delete_class_that_is_an_attribute_type(self):
        b1 = CBundle("B1")
        mcl = CMetaclass("MCL")
        cl1 = CClass(mcl, "CL1", bundles=b1)
        cl2 = CClass(mcl, "CL2", bundles=b1)
        cl3 = CClass(mcl, "CL3", bundles=b1)
        o3 = CObject(cl3, "O3")

        ea1 = CAttribute(type=cl3, default=o3)
        m = CMetaclass("M", bundles=b1, attributes={"o": ea1})
        c = CClass(m)
        cl1.delete()
        cl3.delete()
        try:
            # we just use list here, in order to not get a warning that ea1.default has no effect
            list([ea1.default])
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
        try:
            # we just use list here, in order to not get a warning that ea1.type has no effect
            list([ea1.type])
            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 = cl1
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
        try:
            ea1.type = cl2
            exception_expected_()
        except CException as e:
            eq_("default value '' incompatible with attribute's type 'CL2'",
                e.value)
        try:
            c.set_value("o", CObject(cl2))
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
        try:
            c.get_value("o")
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
Esempio n. 2
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)
Esempio n. 3
0
 def test_set_cattribute_method_to_none(self):
     # setting the type/default to their default value (None) should work
     a = CAttribute()
     a.type = None
     a.default = None
     eq_(a.type, None)
     eq_(a.default, None)
Esempio n. 4
0
 def test_type_object_attribute_class_is_deleted_in_type_method(self):
     attr_cl = CClass(self.mcl, "AC")
     attr_cl.delete()
     try:
         a = CAttribute()
         a.type = attr_cl
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
Esempio n. 5
0
    def test_delete_enum_from_bundle(self):
        b1 = CBundle("B1")
        e1 = CEnum("E1", bundles=b1)
        e1.delete()
        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)
        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()
        eq_(set(b1.get_elements(type=CEnum)), {e2, e3})
        e3.delete()
        eq_(set(b1.get_elements(type=CEnum)), {e2})

        eq_(e3.name, None)
        eq_(e3.bundles, [])
        eq_(e3.values, [])
        eq_(set(cl.attributes), {ea1, ea2})
        try:
            # we just use list here, in order to not get a warning that ea1.default has no effect
            list([ea1.default])
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
        try:
            # we just use list here, in order to not get a warning that ea1.type has no effect
            list([ea1.type])
            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)