def test_parent_lookup_from_parent_tree(): """ Based on real case. """ value = PrimitiveStrObject("value") o1 = Object() o2 = Object() o3 = o2.clone() o4 = Object() o5 = Object() o1.scope_parent = o2 o2.scope_parent = o3 o2.meta_add_parent("*", o5) o3.scope_parent = o4 o3.meta_add_parent("*", o5) o4.scope_parent = o5 o4.meta_add_slot("value", value) assert o1.get_slot("value") is None assert o1.parent_lookup("value") is value
def test_meta_add_parent_cloned_objects_use_same_map(): o = Object() o.meta_add_parent("a", PrimitiveStrObject("value")) x = o.clone() assert "a" in o.parent_slot_keys assert o.map == x.map
def test_meta_add_parent_structural_change_creates_new_map_add(): o = Object() o.meta_add_parent("a", PrimitiveStrObject("value")) x = o.clone() assert o.map == x.map x.meta_add_parent("*", PrimitiveStrObject("another")) assert o.map != x.map assert o != x
def test_meta_add_parent_cloned_objects_dont_change_when_parent_is_changed(): o = Object() o.meta_add_parent("a", PrimitiveStrObject("value")) x = o.clone() assert o.map == x.map x.meta_add_parent("a", PrimitiveStrObject("another")) assert o.map == x.map assert o != x
def test_meta_add_parent_structural_change_creates_new_map_remove(): o = Object() o.meta_add_parent("a", PrimitiveStrObject("value")) x = o.clone() assert o.map == x.map x.meta_remove_parent("a") assert o.map != x.map assert o != x assert "a" in o.parent_slot_keys
def test_clone(): o = Object() o.meta_add_slot("test", Object()) # clones share same map clone = o.clone() assert clone.map is o.map assert clone._slot_values == o._slot_values # clones with updated slot value share same map clone.set_slot("test", Object()) assert clone.map is o.map assert clone._slot_values != o._slot_values # clones with different structure don't share maps clone.meta_add_slot("another", Object()) assert clone.map is not o.map assert clone._slot_values != o._slot_values