Beispiel #1
0
    def test_rev_const_assigned_to_narrow_type(self):
        rev_const_type = CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", AnyType())
        }, name="test")

        normal_broad_type = CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", StringType())
        }, name="test")

        self.assertTrue(normal_broad_type.is_copyable_from(rev_const_type, DUMMY_REASONER))
Beispiel #2
0
    def test_rev_const_flatten_tuple(self):
        rev_const_type = CompositeType({
            ("get", 0): GetterMicroOpType(0, StringType()),
            ("set", 0): SetterMicroOpType(0, AnyType())
        }, name="test")

        normal_broad_type = CompositeType({
            ("get", 0): GetterMicroOpType(0, StringType()),
            ("set", 0): SetterMicroOpType(0, StringType())
        }, name="test")

        rev_const_type = prepare_lhs_type(rev_const_type, None)

        self.assertTrue(isinstance(rev_const_type.get_micro_op_type(("set", 0)).value_type, StringType))

        self.assertTrue(normal_broad_type.is_copyable_from(rev_const_type, DUMMY_REASONER))
Beispiel #3
0
    def test_failed_setup_broad_writing_property(self):
        with self.assertRaises(CompositeTypeIsInconsistent):
            obj = PythonObject({ "foo": "hello" })

            get_manager(obj).add_composite_type(CompositeType({
                ("get", "foo"): GetterMicroOpType("foo", StringType()),
                ("set", "foo"): SetterMicroOpType("foo", AnyType())
            }, name="test"))
Beispiel #4
0
    def test_rev_const_flatten_list(self):
        rev_const_type = CompositeType({
            ("get", 0): GetterMicroOpType(0, StringType()),
            ("set", 0): SetterMicroOpType(0, AnyType()),
            ("insert-start",): InsertStartMicroOpType(IntegerType(), False)
        }, name="test")

        normal_broad_type = CompositeType({
            ("get", 0): GetterMicroOpType(0, StringType()),
            ("set", 0): SetterMicroOpType(0, StringType()),
        }, name="test")

        rev_const_type = prepare_lhs_type(rev_const_type, None)

        self.assertTrue(rev_const_type.is_self_consistent(DUMMY_REASONER))

        self.assertTrue(normal_broad_type.is_copyable_from(rev_const_type, DUMMY_REASONER))
Beispiel #5
0
    def test_composite_object_dereference(self):
        obj = PythonObject({ "foo": "hello" })

        get_manager(obj).add_composite_type(CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", StringType())
        }, name="test"))

        self.assertEquals(obj.foo, "hello")
Beispiel #6
0
    def test_rev_const_can_not_be_added_to_object(self):
        rev_const_type = CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", AnyType())
        }, name="test")

        obj = PythonObject({ "foo": "hello" })
        with self.assertRaises(Exception):
            get_manager(obj).add_composite_type(rev_const_type)
Beispiel #7
0
    def test_composite_object_assignment(self):
        obj = PythonObject({ "foo": "hello" })

        get_manager(obj).add_composite_type(CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", StringType())
        }, name="test"))

        obj.foo = "what"
Beispiel #8
0
    def test_composite_object_invalid_assignment(self):
        obj = PythonObject({ "foo": "hello" })

        get_manager(obj).add_composite_type(CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", StringType())
        }, name="test"))

        with self.assertRaises(TypeError):
            obj.foo = 5
Beispiel #9
0
    def test_python_like_object(self):
        obj = PythonObject({ "foo": "hello" })

        get_manager(obj).add_composite_type(CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", AnyType()),
            ("set", "foo"): SetterMicroOpType("foo", AnyType())
        }, name="test"))

        self.assertEquals(obj.foo, "hello")
        obj.foo = "what"
        self.assertEquals(obj.foo, "what")
Beispiel #10
0
    def test_java_like_object(self):
        obj = PythonObject({ "foo": "hello" })

        get_manager(obj).add_composite_type(CompositeType({
            ("get", "foo"): GetterMicroOpType("foo", StringType()),
            ("set", "foo"): SetterMicroOpType("foo", StringType())
        }, name="test"))

        self.assertEquals(obj.foo, "hello")
        obj.foo = "what"
        self.assertEquals(obj.foo, "what")

        with self.assertRaises(Exception):
            obj.bar = "hello"
Beispiel #11
0
        return UniversalTupleType(property_types)
    elif wildcard_type:
        return UniversalListType(wildcard_type)
    else:
        return EMPTY_COMPOSITE_TYPE


def inferred_opcode_factory(*args, **kwargs):
    return None


MICRO_OP_FACTORIES = {
    "get":
    lambda k, v: GetterMicroOpType(k, enrich_type(v)),
    "set":
    lambda k, v: SetterMicroOpType(k, enrich_type(v)),
    "insert-start":
    lambda v, t: InsertStartMicroOpType(enrich_type(v), t),
    "insert-end":
    lambda v, t: InsertEndMicroOpType(enrich_type(v), t),
    "get-wildcard":
    lambda k, v, e: GetterWildcardMicroOpType(enrich_type(k), enrich_type(v), e
                                              ),
    "set-wildcard":
    lambda k, v, ke, te: SetterWildcardMicroOpType(enrich_type(k),
                                                   enrich_type(v), ke, te),
    "delete-wildcard":
    lambda kt, ke: DeletterWildcardMicroOpType(enrich_type(kt), ke),
    "remove-wildcard":
    lambda ke, te: RemoverWildcardMicroOpType(ke, te),
    "insert-wildcard":
Beispiel #12
0
 def test_setup_broad_reading_property(self):
     obj = PythonObject({ "foo": "hello" })
     get_manager(obj).add_composite_type(CompositeType({
         ("get", "foo"): GetterMicroOpType("foo", AnyType()),
         ("set", "foo"): SetterMicroOpType("foo", StringType())
     }, name="test"))
Beispiel #13
0
 def test_setup_narrow_write_property(self):
     obj = PythonObject({ "foo": "hello" })
     get_manager(obj).add_composite_type(CompositeType({
         ("get", "foo"): GetterMicroOpType("foo", UnitType("hello")),
         ("set", "foo"): SetterMicroOpType("foo", UnitType("hello"))
     }, name="test"))
Beispiel #14
0
    def test_merge_sets(self):
        first = SetterMicroOpType("foo", IntegerType())
        second = SetterMicroOpType("foo", UnitType(5))

        combined = first.merge(second)
        self.assertTrue(isinstance(combined.value_type, IntegerType))