Exemplo n.º 1
0
 def test_link_delete_object(self):
     self.c1.association(self.c2,
                         name="l",
                         source_multiplicity="*",
                         multiplicity="*")
     o1 = CObject(self.c1, "o2")
     o2 = CObject(self.c2, "o2")
     o3 = CObject(self.c2, "o3")
     o4 = CObject(self.c1, "o4")
     add_links({o1: [o2, o3]})
     add_links({o4: [o3, o2]})
     o2.delete()
     eq_(o1.linked, [o3])
     eq_(o3.linked, [o1, o4])
     eq_(o4.linked, [o3])
     try:
         add_links({o1: [o2]})
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot link to deleted target")
     try:
         add_links({o2: [o1]})
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot link to deleted source")
Exemplo n.º 2
0
 def test_default_object_attribute_is_deleted_in_constructor(self):
     attribute_class = CClass(self.mcl, "AC")
     default_object = CObject(attribute_class)
     default_object.delete()
     try:
         CMetaclass("M", attributes={"ac": default_object})
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
Exemplo n.º 3
0
 def test_default_object_attribute_is_deleted_in_default_method(self):
     attr_cl = CClass(self.mcl, "AC")
     default_obj = CObject(attr_cl)
     default_obj.delete()
     try:
         a = CAttribute()
         a.default = default_obj
         exception_expected_()
     except CException as e:
         eq_(e.value, "cannot access named element that has been deleted")
    def test_class_instance_of(self):
        a = CClass(self.mcl)
        b = CClass(self.mcl, superclasses=[a])
        c = CClass(self.mcl)
        o = CObject(b, "o")

        eq_(o.instance_of(a), True)
        eq_(o.instance_of(b), True)
        eq_(o.instance_of(c), False)

        try:
            o.instance_of(o)
            exception_expected_()
        except CException as e:
            eq_("'o' is not a class", e.value)

        o.delete()
        eq_(o.instance_of(a), False)
    def test_attribute_values_exceptional_cases(self):
        cl = CClass(self.mcl, "C", attributes={"b": True})
        o1 = CObject(cl, "o")
        o1.delete()

        try:
            o1.get_value("b")
            exception_expected_()
        except CException as e:
            eq_(e.value, "can't get value 'b' on deleted object")

        try:
            o1.set_value("b", 1)
            exception_expected_()
        except CException as e:
            eq_(e.value, "can't set value 'b' on deleted object")

        try:
            o1.delete_value("b")
            exception_expected_()
        except CException as e:
            eq_(e.value, "can't delete value 'b' on deleted object")

        try:
            o1.values = {"b": 1}
            exception_expected_()
        except CException as e:
            eq_(e.value, "can't set values on deleted object")

        try:
            # we just use list here, in order to not get a warning that o1.values has no effect
            list(o1.values)
            exception_expected_()
        except CException as e:
            eq_(e.value, "can't get values on deleted object")

        o = CObject(cl, "o")
        try:
            o.delete_value("x")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'x' unknown for 'o'")
Exemplo n.º 6
0
    def test_class_instance_relation_deletion_from_object(self):
        cl1 = CClass(self.mcl, "CL1")
        o1 = CObject(cl1, "O1")
        o1.delete()
        eq_(set(cl1.objects), set())

        o1 = CObject(cl1, "O1")
        o2 = CObject(cl1, "O2")
        o3 = CObject(cl1, "O3")

        eq_(set(cl1.objects), {o1, o2, o3})
        o1.delete()
        eq_(set(cl1.objects), {o2, o3})
        o3.delete()
        eq_(set(cl1.objects), {o2})
        eq_(o1.classifier, None)
        eq_(o2.classifier, cl1)
        eq_(o3.classifier, None)
        o2.delete()
        eq_(set(cl1.objects), set())
        eq_(o1.classifier, None)
        eq_(o2.classifier, None)
        eq_(o3.classifier, None)
Exemplo n.º 7
0
    def test_delete_object(self):
        o = CObject(self.cl, "o")
        o.delete()
        eq_(set(self.cl.objects), set())

        o1 = CObject(self.cl, "o1")
        o2 = CObject(self.cl, "o2")
        o3 = CObject(self.cl, "o3")
        o3.set_value("i", 7)

        o1.delete()
        eq_(set(self.cl.objects), {o2, o3})
        o3.delete()
        eq_(set(self.cl.objects), {o2})

        eq_(o3.classifier, None)
        eq_(set(self.cl.objects), {o2})
        eq_(o3.name, None)
        eq_(o3.bundles, [])
        try:
            o3.get_value("i")
            exception_expected_()
        except CException as e:
            eq_("can't get value 'i' on deleted object", e.value)