def test_merge_gets(self): first = GetterMicroOpType("foo", IntegerType()) second = GetterMicroOpType("foo", UnitType(5)) combined = first.merge(second) self.assertTrue(isinstance(combined.value_type, UnitType)) self.assertEqual(combined.value_type.value, 5)
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))
def test_add_micro_op_object(self): class Foo(PythonObject): pass obj = Foo({ "foo": "hello" }) get_manager(obj).add_composite_type(CompositeType({ ("get", "foo"): GetterMicroOpType("foo", StringType()) }, name="test"))
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))
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"))
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))
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")
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)
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"
def test_const_property(self): obj = PythonObject({ "foo": "hello" }) get_manager(obj).add_composite_type(CompositeType({ ("get", "foo"): GetterMicroOpType("foo", StringType()) }, name="test")) self.assertEquals(obj.foo, "hello") with self.assertRaises(Exception): obj.foo = "what"
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
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")
return UniversalLupleType(property_types, wildcard_type) elif property_types: 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":
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"))
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"))
def test_add_micro_op_dictionary(self): obj = PythonDict({ "foo": "hello" }) get_manager(obj).add_composite_type(CompositeType({ ("get", "foo"): GetterMicroOpType("foo", StringType()) }, name="test"))