def test_attribute_values_inheritance(self):
        t1 = CClass(self.mcl, "T1")
        t2 = CClass(self.mcl, "T2")
        c = CClass(self.mcl, "C", superclasses=[t1, t2])
        sc = CClass(self.mcl, "C", superclasses=c)

        t1.attributes = {"i0": 0}
        t2.attributes = {"i1": 1}
        c.attributes = {"i2": 2}
        sc.attributes = {"i3": 3}

        o = CObject(sc, "o")

        for name, value in {"i0": 0, "i1": 1, "i2": 2, "i3": 3}.items():
            eq_(o.get_value(name), value)

        eq_(o.get_value("i0", t1), 0)
        eq_(o.get_value("i1", t2), 1)
        eq_(o.get_value("i2", c), 2)
        eq_(o.get_value("i3", sc), 3)

        for name, value in {"i0": 10, "i1": 11, "i2": 12, "i3": 13}.items():
            o.set_value(name, value)

        for name, value in {"i0": 10, "i1": 11, "i2": 12, "i3": 13}.items():
            eq_(o.get_value(name), value)

        eq_(o.get_value("i0", t1), 10)
        eq_(o.get_value("i1", t2), 11)
        eq_(o.get_value("i2", c), 12)
        eq_(o.get_value("i3", sc), 13)
 def test_attribute_value_type_check_list(self):
     self.cl.attributes = {"t": list}
     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)
 def test_attribute_value_type_check_bool1(self):
     self.cl.attributes = {"t": bool}
     o = CObject(self.cl, "o")
     try:
         o.set_value("t", self.mcl)
         exception_expected_()
     except CException as e:
         eq_(f"value for attribute 't' is not a known attribute type", e.value)
 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)
 def test_attribute_value_type_check_object(self):
     attribute_type = CClass(self.mcl, "AttrType")
     self.cl.attributes = {"t": attribute_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)
    def test_attribute_values_inheritance_after_delete_superclass(self):
        t1 = CClass(self.mcl, "T1")
        t2 = CClass(self.mcl, "T2")
        c = CClass(self.mcl, "C", superclasses=[t1, t2])
        sc = CClass(self.mcl, "C", superclasses=c)

        t1.attributes = {"i0": 0}
        t2.attributes = {"i1": 1}
        c.attributes = {"i2": 2}
        sc.attributes = {"i3": 3}

        o = CObject(sc, "o")

        t2.delete()

        for name, value in {"i0": 0, "i2": 2, "i3": 3}.items():
            eq_(o.get_value(name), value)
        try:
            o.get_value("i1")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'i1' unknown for 'o'")

        eq_(o.get_value("i0", t1), 0)
        try:
            o.get_value("i1", t2)
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'i1' unknown for ''")
        eq_(o.get_value("i2", c), 2)
        eq_(o.get_value("i3", sc), 3)

        for name, value in {"i0": 10, "i2": 12, "i3": 13}.items():
            o.set_value(name, value)
        try:
            o.set_value("i1", 11)
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'i1' unknown for 'o'")

        for name, value in {"i0": 10, "i2": 12, "i3": 13}.items():
            eq_(o.get_value(name), value)
        try:
            o.get_value("i1")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'i1' unknown for 'o'")

        eq_(o.get_value("i0", t1), 10)
        try:
            o.get_value("i1", t2)
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'i1' unknown for ''")
        eq_(o.get_value("i2", c), 12)
        eq_(o.get_value("i3", sc), 13)
 def test_object_attribute_of_superclass_type(self):
     attribute_super_type = CClass(self.mcl, "AttrSuperType")
     attribute_type = CClass(self.mcl, "AttrType", superclasses=attribute_super_type)
     attribute_value = CObject(attribute_type, "attribute_value")
     o = CObject(self.cl, "o1")
     self.cl.attributes = {
         "attrTypeObj1": attribute_super_type, "attrTypeObj2": attribute_value
     }
     o.set_value("attrTypeObj1", attribute_value)
     o.set_value("attrTypeObj2", attribute_value)
     eq_(o.get_value("attrTypeObj1"), attribute_value)
     eq_(o.get_value("attrTypeObj2"), attribute_value)
    def test_delete_class_that_is_an_attribute_type(self):
        b1 = CBundle("B1")
        cl1 = CClass(self.mcl, "CL1", bundles=b1)
        cl2 = CClass(self.mcl, "CL2", bundles=b1)
        cl3 = CClass(self.mcl, "CL3", bundles=b1)
        o3 = CObject(cl3, "O3")

        ea1 = CAttribute(type=cl3, default=o3)
        c = CClass(self.mcl, "C", bundles=b1, attributes={"o": ea1})
        o = CObject(c)
        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:
            o.set_value("o", CObject(cl2))
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
        try:
            o.get_value("o")
            exception_expected_()
        except CException as e:
            eq_("cannot access named element that has been deleted", e.value)
    def test_attribute_of_value_unknown(self):
        o = CObject(self.cl, "o")
        try:
            o.get_value("x")
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'x' unknown for 'o'")

        self.cl.attributes = {"isBoolean": True, "intVal": 1}
        try:
            o.set_value("x", 1)
            exception_expected_()
        except CException as e:
            eq_(e.value, "attribute 'x' unknown for 'o'")
    def test_object_type_attribute_values(self):
        attribute_type = CClass(self.mcl, "AttrType")
        attribute_value = CObject(attribute_type, "attribute_value")
        self.cl.attributes = {"attrTypeObj": attribute_value}
        object_attribute = self.cl.get_attribute("attrTypeObj")
        eq_(object_attribute.type, attribute_type)
        o = CObject(self.cl, "o")
        eq_(o.get_value("attrTypeObj"), attribute_value)

        non_attribute_value = CObject(self.cl, "non_attribute_value")
        try:
            o.set_value("attrTypeObj", non_attribute_value)
            exception_expected_()
        except CException as e:
            eq_(e.value, "type of 'non_attribute_value' is not matching type of attribute 'attrTypeObj'")
예제 #11
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_class_type_attribute_values(self):
        attribute_type = CMetaclass("AttrType")
        attribute_value = CClass(attribute_type, "attribute_value")
        self.cl.attributes = {"attrTypeCl": attribute_type}
        class_attribute = self.cl.get_attribute("attrTypeCl")
        class_attribute.default = attribute_value
        eq_(class_attribute.type, attribute_type)
        o = CObject(self.cl, "o")
        eq_(o.get_value("attrTypeCl"), attribute_value)

        non_attribute_value = CClass(CMetaclass("MX"), "non_attribute_value")
        try:
            o.set_value("attrTypeCl", non_attribute_value)
            exception_expected_()
        except CException as e:
            eq_(e.value, "type of 'non_attribute_value' is not matching type of attribute 'attrTypeCl'")
 def test_attributes_overwrite_no_defaults(self):
     cl = CClass(self.mcl, "C", attributes={
         "isBoolean": bool,
         "intVal": int})
     o = CObject(cl, "o")
     eq_(o.get_value("isBoolean"), None)
     o.set_value("isBoolean", False)
     cl.attributes = {
         "isBoolean": bool,
         "intVal": int,
         "floatVal": float}
     eq_(o.get_value("isBoolean"), False)
     eq_(o.get_value("floatVal"), None)
     eq_(o.get_value("intVal"), None)
     o.set_value("floatVal", 1.2)
     eq_(o.get_value("floatVal"), 1.2)
    def test_values_multiple_inheritance(self):
        t1 = CClass(self.mcl, "T1")
        t2 = CClass(self.mcl, "T2")
        st_a = CClass(self.mcl, "STA", superclasses=[t1, t2])
        sub_a = CClass(self.mcl, "SubA", superclasses=[st_a])
        st_b = CClass(self.mcl, "STB", superclasses=[t1, t2])
        sub_b = CClass(self.mcl, "SubB", superclasses=[st_b])
        st_c = CClass(self.mcl, "STC")
        sub_c = CClass(self.mcl, "SubC", superclasses=[st_c])

        cl = CClass(self.mcl, "M", superclasses=[sub_a, sub_b, sub_c])
        o = CObject(cl)

        t1.attributes = {"i0": 0}
        t2.attributes = {"i1": 1}
        st_a.attributes = {"i2": 2}
        sub_a.attributes = {"i3": 3}
        st_b.attributes = {"i4": 4}
        sub_b.attributes = {"i5": 5}
        st_c.attributes = {"i6": 6}
        sub_c.attributes = {"i7": 7}

        eq_(o.get_value("i0"), 0)
        eq_(o.get_value("i1"), 1)
        eq_(o.get_value("i2"), 2)
        eq_(o.get_value("i3"), 3)
        eq_(o.get_value("i4"), 4)
        eq_(o.get_value("i5"), 5)
        eq_(o.get_value("i6"), 6)
        eq_(o.get_value("i7"), 7)

        eq_(o.get_value("i0", t1), 0)
        eq_(o.get_value("i1", t2), 1)
        eq_(o.get_value("i2", st_a), 2)
        eq_(o.get_value("i3", sub_a), 3)
        eq_(o.get_value("i4", st_b), 4)
        eq_(o.get_value("i5", sub_b), 5)
        eq_(o.get_value("i6", st_c), 6)
        eq_(o.get_value("i7", sub_c), 7)

        o.set_value("i0", 10)
        o.set_value("i1", 11)
        o.set_value("i2", 12)
        o.set_value("i3", 13)
        o.set_value("i4", 14)
        o.set_value("i5", 15)
        o.set_value("i6", 16)
        o.set_value("i7", 17)

        eq_(o.get_value("i0"), 10)
        eq_(o.get_value("i1"), 11)
        eq_(o.get_value("i2"), 12)
        eq_(o.get_value("i3"), 13)
        eq_(o.get_value("i4"), 14)
        eq_(o.get_value("i5"), 15)
        eq_(o.get_value("i6"), 16)
        eq_(o.get_value("i7"), 17)
 def test_attribute_deleted_no_default(self):
     cl = CClass(self.mcl, "C", attributes={
         "isBoolean": bool,
         "intVal": int})
     cl.attributes = {"isBoolean": bool}
     o = CObject(cl, "o")
     eq_(o.get_value("isBoolean"), None)
     try:
         o.get_value("intVal")
         exception_expected_()
     except CException as e:
         eq_(e.value, "attribute 'intVal' unknown for 'o'")
     try:
         o.set_value("intVal", 1)
         exception_expected_()
     except CException as e:
         eq_(e.value, "attribute 'intVal' unknown for 'o'")
 def test_enum_type_attribute_values(self):
     enum_type = CEnum("EnumT", values=["A", "B", "C"])
     cl = CClass(self.mcl, "C", attributes={
         "e1": enum_type,
         "e2": enum_type})
     e2 = cl.get_attribute("e2")
     e2.default = "A"
     o = CObject(cl, "o")
     eq_(o.get_value("e1"), None)
     eq_(o.get_value("e2"), "A")
     o.set_value("e1", "B")
     o.set_value("e2", "C")
     eq_(o.get_value("e1"), "B")
     eq_(o.get_value("e2"), "C")
     try:
         o.set_value("e1", "X")
         exception_expected_()
     except CException as e:
         eq_(e.value, "value 'X' is not element of enumeration")
 def test_attribute_deleted(self):
     cl = CClass(self.mcl, "C", attributes={
         "isBoolean": True,
         "intVal": 15})
     o = CObject(cl, "o")
     eq_(o.get_value("intVal"), 15)
     cl.attributes = {
         "isBoolean": False}
     eq_(o.get_value("isBoolean"), True)
     try:
         o.get_value("intVal")
         exception_expected_()
     except CException as e:
         eq_(e.value, "attribute 'intVal' unknown for 'o'")
     try:
         o.set_value("intVal", 1)
         exception_expected_()
     except CException as e:
         eq_(e.value, "attribute 'intVal' unknown for 'o'")
    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'")
 def test_attributes_overwrite(self):
     cl = CClass(self.mcl, "C", attributes={
         "isBoolean": True,
         "intVal": 15})
     o = CObject(cl, "o")
     eq_(o.get_value("intVal"), 15)
     try:
         o.get_value("floatVal")
         exception_expected_()
     except CException as e:
         eq_(e.value, "attribute 'floatVal' unknown for 'o'")
     o.set_value("intVal", 18)
     cl.attributes = {
         "isBoolean": False,
         "intVal": 19,
         "floatVal": 25.1}
     eq_(o.get_value("isBoolean"), True)
     eq_(o.get_value("floatVal"), 25.1)
     eq_(o.get_value("intVal"), 18)
     o.set_value("floatVal", 1.2)
     eq_(o.get_value("floatVal"), 1.2)
예제 #20
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)
 def test_values_setter_with_superclass(self):
     scl = CClass(self.mcl, "SCL", attributes={
         "intVal": 20, "intVal2": 30})
     cl = CClass(self.mcl, "C", superclasses=scl, attributes={
         "isBoolean": True,
         "intVal": 1})
     o = CObject(cl, "o", values={
         "isBoolean": False})
     eq_(o.values, {"isBoolean": False, "intVal": 1, "intVal2": 30})
     o.set_value("intVal", 12, scl)
     o.set_value("intVal", 15, cl)
     o.set_value("intVal2", 16, scl)
     eq_(o.values, {"isBoolean": False, "intVal": 15, "intVal2": 16})
     eq_(o.get_value("intVal", scl), 12)
     eq_(o.get_value("intVal", cl), 15)
 def test_integers_as_floats(self):
     cl = CClass(self.mcl, "C", attributes={
         "floatVal": float})
     o = CObject(cl, "o")
     o.set_value("floatVal", 15)
     eq_(o.get_value("floatVal"), 15)
예제 #23
0
def new_customer(name=None, **kwargs):
    a_customer = CObject(customer, name, **kwargs)
    a_customer.set_value("id", get_customer_id())
    return a_customer
예제 #24
0
def new_product(name=None, **kwargs):
    a_product = CObject(product, name, **kwargs)
    a_product.set_value("id", get_product_id())
    return a_product
# get rid of the objects, we don't need from the imported shopping model
cart1.delete()
order1.delete()
for item_object in item.objects:
    item_object.delete()

# define a new cart and order, as they would be created in the shopping session
cart1 = CObject(cart)
cart1_items = add_items_to_cart(cart1, [[premium_pen, 3]])
set_links({cart1: thomas_customer}, association=customer_cart_relation)
order1 = place_order(cart1)

# create and link the objects which have attributes or links
search_obj = CObject(search_item)
search_obj.set_value("search string", "pens")
view_shopping_cart_obj = CObject(view_shopping_cart)
view_shopping_cart_obj.add_links(cart1, role_name="cart")
add_to_shopping_cart_obj = CObject(add_to_shopping_cart)
add_to_shopping_cart_obj.add_links(cart1_items, role_name="item")
checkout_obj = CObject(checkout)
checkout_obj.add_links(order1, role_name="order")
view_item_obj = CObject(view_item)
view_item_obj.add_links(premium_pen, role_name="product")

# pass the full trace to create_trace to filter out the meaningful objects in the trace and link them
a_trace = create_trace([
    CObject(initial_node_shopping_cart),
    CObject(decision_node_search_browse),
    CObject(merge_node_search), search_obj,
    CObject(decision_node_found),
예제 #26
0
    def test_links_as_attribute_values(self):
        code = CClass(self.mcl, "Code")
        source = CClass(self.mcl, "Source")
        code.association(source, "[contained_code] * -> [source] *")
        code_a = CClass(self.mcl, "Code A", superclasses=code)
        code_b = CClass(self.mcl, "Code B", superclasses=code)
        a_b_association = code_a.association(code_b,
                                             "a_b: [code_a] * -> [code_b] *",
                                             superclasses=code)
        code_a1 = CObject(code_a, "code_a1")
        code_b1 = CObject(code_b, "code_b1")
        code_b2 = CObject(code_b, "code_b2")
        a_b_links = add_links({code_a1: [code_b1, code_b2]},
                              association=a_b_association)

        links_list = [code_a1, code_b2, code_b1, a_b_links[0], a_b_links[1]]

        collection_type = CClass(self.mcl,
                                 "Collection Type",
                                 attributes={
                                     "primary_code": code,
                                     "default_value_code": a_b_links[0],
                                     "codes": list,
                                     "default_values_list": links_list
                                 })
        collection = CObject(collection_type)

        eq_(collection.get_value("primary_code"), None)
        eq_(collection.get_value("default_value_code"), a_b_links[0])
        eq_(collection.get_value("codes"), None)
        eq_(collection.get_value("default_values_list"), links_list)

        collection.set_value("primary_code", a_b_links[1])
        collection.set_value("default_value_code", a_b_links[1])
        collection.set_value("codes", [code_a1, a_b_links[0]])
        collection.set_value("default_values_list",
                             [a_b_links[0], a_b_links[1]])

        eq_(collection.get_value("primary_code"), a_b_links[1])
        eq_(collection.get_value("default_value_code"), a_b_links[1])
        eq_(collection.get_value("codes"), [code_a1, a_b_links[0]])
        eq_(collection.get_value("default_values_list"),
            [a_b_links[0], a_b_links[1]])

        collection.values = {
            'default_values_list': [a_b_links[0]],
            "codes": []
        }

        eq_(
            collection.values, {
                'default_value_code': a_b_links[1],
                'default_values_list': [a_b_links[0]],
                'codes': [],
                'primary_code': a_b_links[1]
            })

        collection.delete_value("primary_code")
        collection.delete_value("default_value_code")
        collection.delete_value("codes")
        collection.delete_value("default_values_list")

        eq_(collection.get_value("primary_code"), None)
        eq_(collection.get_value("default_value_code"), None)
        eq_(collection.get_value("codes"), None)
        eq_(collection.get_value("default_values_list"), None)
    def test_attribute_values_same_name_inheritance(self):
        t1 = CClass(self.mcl, "T1")
        t2 = CClass(self.mcl, "T2")
        c = CClass(self.mcl, "C", superclasses=[t1, t2])
        sc = CClass(self.mcl, "C", superclasses=c)

        t1.attributes = {"i": 0}
        t2.attributes = {"i": 1}
        c.attributes = {"i": 2}
        sc.attributes = {"i": 3}

        o1 = CObject(sc)
        o2 = CObject(c)
        o3 = CObject(t1)

        eq_(o1.get_value("i"), 3)
        eq_(o2.get_value("i"), 2)
        eq_(o3.get_value("i"), 0)

        eq_(o1.get_value("i", sc), 3)
        eq_(o1.get_value("i", c), 2)
        eq_(o1.get_value("i", t2), 1)
        eq_(o1.get_value("i", t1), 0)
        eq_(o2.get_value("i", c), 2)
        eq_(o2.get_value("i", t2), 1)
        eq_(o2.get_value("i", t1), 0)
        eq_(o3.get_value("i", t1), 0)

        o1.set_value("i", 10)
        o2.set_value("i", 11)
        o3.set_value("i", 12)

        eq_(o1.get_value("i"), 10)
        eq_(o2.get_value("i"), 11)
        eq_(o3.get_value("i"), 12)

        eq_(o1.get_value("i", sc), 10)
        eq_(o1.get_value("i", c), 2)
        eq_(o1.get_value("i", t2), 1)
        eq_(o1.get_value("i", t1), 0)
        eq_(o2.get_value("i", c), 11)
        eq_(o2.get_value("i", t2), 1)
        eq_(o2.get_value("i", t1), 0)
        eq_(o3.get_value("i", t1), 12)

        o1.set_value("i", 130, sc)
        o1.set_value("i", 100, t1)
        o1.set_value("i", 110, t2)
        o1.set_value("i", 120, c)

        eq_(o1.get_value("i"), 130)

        eq_(o1.get_value("i", sc), 130)
        eq_(o1.get_value("i", c), 120)
        eq_(o1.get_value("i", t2), 110)
        eq_(o1.get_value("i", t1), 100)
예제 #28
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)
 def test_attribute_defined_after_instance(self):
     cl = CClass(self.mcl, "C")
     o = CObject(cl, "o")
     cl.attributes = {"floatVal": float}
     o.set_value("floatVal", 15)
     eq_(o.get_value("floatVal"), 15)
    def test_delete_attribute_values_with_superclass(self):
        scl = CClass(self.mcl, "SCL", attributes={
            "intVal": 20, "intVal2": 30})
        cl = CClass(self.mcl, "C", superclasses=scl, attributes={
            "isBoolean": True,
            "intVal": 1})
        o = CObject(cl, "o", values={
            "isBoolean": False})
        o.delete_value("isBoolean")
        o.delete_value("intVal2")
        eq_(o.values, {"intVal": 1})

        o.set_value("intVal", 2, scl)
        o.set_value("intVal", 3, cl)
        eq_(o.values, {"intVal": 3})
        o.delete_value("intVal")
        eq_(o.values, {"intVal": 2})

        o.set_value("intVal", 2, scl)
        o.set_value("intVal", 3, cl)
        o.delete_value("intVal", cl)
        eq_(o.values, {"intVal": 2})

        o.set_value("intVal", 2, scl)
        o.set_value("intVal", 3, cl)
        o.delete_value("intVal", scl)
        eq_(o.values, {"intVal": 3})