def test_cleanup_fringe(self): w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_c = self.space.newutf8("c", 1) w_d = self.space.newutf8("d", 1) base = Terminator(self.space) base.instantiation_count = 6 m1 = base.get_next(w_a, 'a"', 0, 2, base) m2 = base.get_next(w_b, 'b"', 0, 2, base) m3 = base.get_next(w_c, 'c"', 0, 2, base) m4 = base.get_next(w_d, 'd"', 0, 2, base) m5 = m4.get_next(w_a, 'a"', 0, 2, base) base.instantiation_count = 7 m1.instantiation_count = 2 m2.instantiation_count = 2 m3.instantiation_count = 2 m4.instantiation_count = 1 m5.instantiation_count = 1 assert base.current_fringe == dict.fromkeys([m1, m2, m3, m4]) base.cleanup_fringe() assert base.current_fringe == dict.fromkeys([m1, m2, m3]) assert m4.state == MapBase.BLOCKED assert m4.nextmap_first is None assert m4.nextmap_all is None assert m5.state == MapBase.BLOCKED assert m5.nextmap_first is None assert m5.nextmap_all is None
def test_json_map(self): m = Terminator(self.space) w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_c = self.space.newutf8("c", 1) m1 = m.get_next(w_a, '"a"', 0, 3, m) assert m1.w_key == w_a assert m1.nextmap_first is None assert m1.key_repr == '"a"' assert m1.key_repr_cmp('"a": 123', 0) assert not m1.key_repr_cmp('b": 123', 0) assert m.nextmap_first.w_key == w_a m2 = m.get_next(w_a, '"a"', 0, 3, m) assert m2 is m1 m3 = m.get_next(w_b, '"b"', 0, 3, m) assert m3.w_key == w_b assert m3.nextmap_first is None assert m3.key_repr == '"b"' assert m.nextmap_first is m1 m4 = m3.get_next(w_c, '"c"', 0, 3, m) assert m4.w_key == w_c assert m4.nextmap_first is None assert m4.key_repr == '"c"' assert m3.nextmap_first is m4
def test_json_map_get_index(self): m = Terminator(self.space) w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_c = self.space.newutf8("c", 1) m1 = m.get_next(w_a, 'a"', 0, 2, m) assert m1.get_index(w_a) == 0 assert m1.get_index(w_b) == -1 m2 = m.get_next(w_b, 'b"', 0, 2, m) assert m2.get_index(w_b) == 0 assert m2.get_index(w_a) == -1 m3 = m2.get_next(w_c, 'c"', 0, 2, m) assert m3.get_index(w_b) == 0 assert m3.get_index(w_c) == 1 assert m3.get_index(w_a) == -1
def test_repeated_key_get_next(self): m = Terminator(self.space) w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_c = self.space.newutf8("c", 1) m1 = m.get_next(w_a, '"a"', 0, 3, m) m1 = m1.get_next(w_b, '"b"', 0, 3, m) m1 = m1.get_next(w_c, '"c"', 0, 3, m) m2 = m1.get_next(w_a, '"a"', 0, 3, m) assert m2 is None
def test_jsonmap_fill_dict(self): from collections import OrderedDict m = Terminator(self.space) space = self.space w_a = space.newutf8("a", 1) w_b = space.newutf8("b", 1) w_c = space.newutf8("c", 1) m1 = m.get_next(w_a, 'a"', 0, 2, m) m2 = m1.get_next(w_b, 'b"', 0, 2, m) m3 = m2.get_next(w_c, 'c"', 0, 2, m) d = OrderedDict() m3.fill_dict(d, [space.w_None, space.w_None, space.w_None]) assert list(d) == [w_a, w_b, w_c]
def test_deal_with_blocked_number_of_leaves(self): w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_x = self.space.newutf8("x", 1) w_u = self.space.newutf8("u", 1) space = self.space base = Terminator(space) m1 = base.get_next(w_a, 'a"', 0, 2, base) m2 = m1.get_next(w_b, 'b"', 0, 2, base) m2.get_next(w_x, 'x"', 0, 2, base) m2.get_next(w_u, 'u"', 0, 2, base) assert base.number_of_leaves == 2 m2.mark_blocked(base) assert base.number_of_leaves == 1
def _make_some_maps(self): # base -> m1 -> m2 -> m3 # \-> m4 w_a = self.space.newutf8("a", 1) w_b = self.space.newutf8("b", 1) w_c = self.space.newutf8("c", 1) w_d = self.space.newutf8("d", 1) base = Terminator(self.space) base.instantiation_count = 6 m1 = base.get_next(w_a, 'a"', 0, 2, base) m2 = m1.get_next(w_b, 'b"', 0, 2, base) m3 = m2.get_next(w_c, 'c"', 0, 2, base) m4 = m2.get_next(w_d, 'd"', 0, 2, base) return base, m1, m2, m3, m4