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_get_slot_from_several_parents(): """ o.parents | |-- p <-- cycle, yay --, | |-- x -> Object() | | |-- y -> Object() | | `-- z -> p --------' | `-- p3 `-- x -> p2 | `-- xex """ val = PrimitiveStrObject("it is xex!") p = Object() p.meta_add_slot("x", Object()) p.meta_add_slot("y", Object()) p.meta_add_slot("z", p) # cycle, yay! p2 = Object() p.meta_add_slot("xex", val) p3 = Object() p.meta_add_slot("x", p2) o = Object() o.meta_add_parent("p", p) o.meta_add_parent("p3", p3) assert o.get_slot("xex") is None assert o.parent_lookup("xex") is val
def test_slot_lookup_from_scope_parent(): p = Object() val = PrimitiveStrObject("it is xex!") p.meta_add_slot("xex", val) o = Object() o.scope_parent = p assert o.get_slot("xex") is None assert o.slot_lookup("xex") is val
def test_get_slot_from_one_parent(): val = PrimitiveStrObject("it is xex!") p = Object() p.meta_add_slot("xex", val) o = Object() o.meta_add_parent("p", p) assert o.get_slot("xex") is None assert o.parent_lookup("xex") is val
def test_meta_insert_slot(): first = PrimitiveStrObject("first") second = PrimitiveStrObject("second") third = PrimitiveStrObject("third") o = Object() assert not o._slot_values o.meta_add_slot("first", first) o.meta_add_slot("third", third) assert o.get_slot("first") is first assert o.get_slot("third") is third o.meta_insert_slot(1, "second", second) assert o.map._slots.keys() == ["first", "second", "third"] # make sure that objects didn't shifted assert o.get_slot("first") is first assert o.get_slot("second") is second assert o.get_slot("third") is third
def test_meta_remove_slot_shift_map_pointers(): first = PrimitiveStrObject("first") second = PrimitiveStrObject("second") third = PrimitiveStrObject("third") o = Object() assert not o._slot_values o.meta_add_slot("first", first) o.meta_add_slot("second", second) o.meta_add_slot("third", third) assert o.get_slot("first") is first assert o.get_slot("second") is second assert o.get_slot("third") is third o.meta_remove_slot("first") assert len(o._slot_values) == 2 assert len(o.map._slots) == 2 assert o.map._slots["second"] == 0 assert o.map._slots["third"] == 1 assert o.get_slot("first") is None assert o.get_slot("second") == second assert o.get_slot("third") == third
def _add_reflection_to_universe(self): self.universe.meta_add_slot("universe", self.universe) primitives = self.universe.get_slot("primitives") if primitives is None: primitives = Object() self.universe.meta_add_slot("primitives", primitives) # transport values from primitives to global level for slot in primitives.slot_keys: self.universe.meta_add_slot(slot, primitives.get_slot(slot)) primitives.meta_add_slot("interpreter", gen_interpreter_primitives(self))
def slot_lookup(): val = PrimitiveStrObject("it is xex!") flat = PrimitiveStrObject("it is flat") p = Object() p.meta_add_slot("xex", val) o = Object() o.meta_add_parent("p", p) o.meta_add_parent("p", flat) assert o.get_slot("xex") is None assert o.slot_lookup("xex") is val assert o.slot_lookup("flat") is flat
def test_get_slot(): o = Object() val = PrimitiveStrObject("xe") o.meta_add_slot("test", val) assert o.get_slot("test") is val