def test_iter(self): space = self.space s = W_SetObject(space, self.wrapped([1, 2])) it = s.iter() assert isinstance(it, IntegerIteratorImplementation) assert space.unwrap(it.next()) == 1 assert space.unwrap(it.next()) == 2 # s = W_SetObject(space, self.wrapped(["a", "b"], bytes=True)) it = s.iter() assert isinstance(it, BytesIteratorImplementation) assert space.unwrap(it.next()) == "a" assert space.unwrap(it.next()) == "b"
def test_create_list_from_set(self): from pypy.objspace.std.setobject import W_SetObject from pypy.objspace.std.setobject import _initialize_set space = self.space w = space.wrap w_l = W_ListObject( space, [space.wrap(1), space.wrap(2), space.wrap(3)]) w_set = W_SetObject(self.space) _initialize_set(self.space, w_set, w_l) w_set.iter = None # make sure fast path is used w_l2 = W_ListObject(space, []) space.call_method(w_l2, "__init__", w_set) w_l2.sort(False) assert space.eq_w(w_l, w_l2) w_l = W_ListObject(space, [space.wrap("a"), space.wrap("b"), space.wrap("c")]) _initialize_set(self.space, w_set, w_l) space.call_method(w_l2, "__init__", w_set) w_l2.sort(False) assert space.eq_w(w_l, w_l2)
def test_create_list_from_set(self): from pypy.objspace.std.setobject import W_SetObject from pypy.objspace.std.setobject import _initialize_set space = self.space w = space.wrap w_l = W_ListObject(space, [space.wrap(1), space.wrap(2), space.wrap(3)]) w_set = W_SetObject(self.space) _initialize_set(self.space, w_set, w_l) w_set.iter = None # make sure fast path is used w_l2 = W_ListObject(space, []) space.call_method(w_l2, "__init__", w_set) w_l2.sort(False) assert space.eq_w(w_l, w_l2) w_l = W_ListObject(space, [space.wrap("a"), space.wrap("b"), space.wrap("c")]) _initialize_set(self.space, w_set, w_l) space.call_method(w_l2, "__init__", w_set) w_l2.sort(False) assert space.eq_w(w_l, w_l2)
def test_iter(self): space = self.space s = W_SetObject(space, self.wrapped([1, 2])) it = s.iter() assert isinstance(it, IntegerIteratorImplementation) assert space.unwrap(it.next()) == 1 assert space.unwrap(it.next()) == 2 # s = W_SetObject(space, self.wrapped(["a", "b"])) it = s.iter() assert isinstance(it, BytesIteratorImplementation) assert space.unwrap(it.next()) == "a" assert space.unwrap(it.next()) == "b" # s = W_SetObject(space, self.wrapped([u"a", u"b"])) it = s.iter() assert isinstance(it, UnicodeIteratorImplementation) assert space.unwrap(it.next()) == u"a" assert space.unwrap(it.next()) == u"b"