예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 def test_compare(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t = W_SetObject(self.space)
     _initialize_set(self.space, t, self.word)
     assert self.space.eq_w(s,t)
     u = self.space.wrap(set('simsalabim'))
     assert self.space.eq_w(s,u)
예제 #4
0
 def test_compare(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t = W_SetObject(self.space)
     _initialize_set(self.space, t, self.word)
     assert self.space.eq_w(s, t)
     u = self.space.wrap(set('simsalabim'))
     assert self.space.eq_w(s, u)
예제 #5
0
    def test_create_set_from_list(self):
        from pypy.interpreter.baseobjspace import W_Root
        from pypy.objspace.std.setobject import BytesSetStrategy, ObjectSetStrategy, UnicodeSetStrategy
        from pypy.objspace.std.floatobject import W_FloatObject

        w = self.space.wrap
        wb = self.space.wrapbytes
        intstr = self.space.fromcache(IntegerSetStrategy)
        tmp_func = intstr.get_storage_from_list
        # test if get_storage_from_list is no longer used
        intstr.get_storage_from_list = None

        w_list = W_ListObject(self.space, [w(1), w(2), w(3)])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is intstr
        assert intstr.unerase(w_set.sstorage) == {1: None, 2: None, 3: None}

        w_list = W_ListObject(self.space, [wb("1"), wb("2"), wb("3")])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(BytesSetStrategy)
        assert w_set.strategy.unerase(w_set.sstorage) == {
            "1": None,
            "2": None,
            "3": None
        }

        w_list = self.space.iter(
            W_ListObject(self.space,
                         [w(u"1"), w(u"2"), w(u"3")]))
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(UnicodeSetStrategy)
        assert w_set.strategy.unerase(w_set.sstorage) == {
            u"1": None,
            u"2": None,
            u"3": None
        }

        w_list = W_ListObject(self.space, [w("1"), w(2), w("3")])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(ObjectSetStrategy)
        for item in w_set.strategy.unerase(w_set.sstorage):
            assert isinstance(item, W_Root)

        w_list = W_ListObject(self.space, [w(1.0), w(2.0), w(3.0)])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(ObjectSetStrategy)
        for item in w_set.strategy.unerase(w_set.sstorage):
            assert isinstance(item, W_FloatObject)

        # changed cached object, need to change it back for other tests to pass
        intstr.get_storage_from_list = tmp_func
예제 #6
0
 def test_and(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t0 = W_SetObject(self.space)
     _initialize_set(self.space, t0, self.otherword)
     t1 = W_FrozensetObject(self.space, self.otherword)
     r0 = and__Set_Set(self.space, s, t0)
     r1 = and__Set_Set(self.space, s, t1)
     assert eq__Set_Set(self.space, r0, r1) == self.true
     sr = set_intersection__Set(self.space, s, [self.otherword])
     assert eq__Set_Set(self.space, r0, sr) == self.true
예제 #7
0
 def test_and(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t0 = W_SetObject(self.space)
     _initialize_set(self.space, t0, self.otherword)
     t1 = W_FrozensetObject(self.space, self.otherword)
     r0 = s.descr_and(self.space, t0)
     r1 = s.descr_and(self.space, t1)
     assert r0.descr_eq(self.space, r1) == self.true
     sr = s.descr_intersection(self.space, [self.otherword])
     assert r0.descr_eq(self.space, sr) == self.true
예제 #8
0
 def test_and(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t0 = W_SetObject(self.space)
     _initialize_set(self.space, t0, self.otherword)
     t1 = W_FrozensetObject(self.space, self.otherword)
     r0 = and__Set_Set(self.space, s, t0)
     r1 = and__Set_Set(self.space, s, t1)
     assert eq__Set_Set(self.space, r0, r1) == self.true
     sr = set_intersection__Set(self.space, s, [self.otherword])
     assert eq__Set_Set(self.space, r0, sr) == self.true
예제 #9
0
 def test_and(self):
     s = W_SetObject(self.space)
     _initialize_set(self.space, s, self.word)
     t0 = W_SetObject(self.space)
     _initialize_set(self.space, t0, self.otherword)
     t1 = W_FrozensetObject(self.space, self.otherword)
     r0 = s.descr_and(self.space, t0)
     r1 = s.descr_and(self.space, t1)
     assert r0.descr_eq(self.space, r1) == self.true
     sr = s.descr_intersection(self.space, [self.otherword])
     assert r0.descr_eq(self.space, sr) == self.true
예제 #10
0
    def test_listview_str_int_on_set(self):
        w = self.space.wrap

        w_a = W_SetObject(self.space)
        _initialize_set(self.space, w_a, w("abcdefg"))
        assert sorted(self.space.listview_str(w_a)) == list("abcdefg")
        assert self.space.listview_int(w_a) is None

        w_b = W_SetObject(self.space)
        _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)]))
        assert sorted(self.space.listview_int(w_b)) == [1,2,3,4,5]
        assert self.space.listview_str(w_b) is None
예제 #11
0
    def test_listview_str_int_on_set(self):
        w = self.space.wrap

        w_a = W_SetObject(self.space)
        _initialize_set(self.space, w_a, w("abcdefg"))
        assert sorted(self.space.listview_str(w_a)) == list("abcdefg")
        assert self.space.listview_int(w_a) is None

        w_b = W_SetObject(self.space)
        _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)]))
        assert sorted(self.space.listview_int(w_b)) == [1,2,3,4,5]
        assert self.space.listview_str(w_b) is None
예제 #12
0
    def test_listview_bytes_int_on_set(self):
        w = self.space.wrap
        wb = self.space.newbytes

        w_a = W_SetObject(self.space)
        _initialize_set(self.space, w_a, wb("abcdefg"))
        assert sorted(self.space.listview_int(w_a)) == [97, 98, 99, 100, 101, 102, 103]
        assert self.space.listview_bytes(w_a) is None

        w_b = W_SetObject(self.space)
        _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)]))
        assert sorted(self.space.listview_int(w_b)) == [1,2,3,4,5]
        assert self.space.listview_bytes(w_b) is None
예제 #13
0
    def test_listview_bytes_int_on_set(self):
        w = self.space.wrap
        wb = self.space.wrapbytes

        w_a = W_SetObject(self.space)
        _initialize_set(self.space, w_a, wb("abcdefg"))
        assert sorted(self.space.listview_int(w_a)) == [97, 98, 99, 100, 101, 102, 103]
        assert self.space.listview_bytes(w_a) is None

        w_b = W_SetObject(self.space)
        _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)]))
        assert sorted(self.space.listview_int(w_b)) == [1,2,3,4,5]
        assert self.space.listview_bytes(w_b) is None
예제 #14
0
    def test_intersection_order(self):
        # theses tests make sure that intersection is done in the correct order
        # (smallest first)
        space = self.space
        a = W_SetObject(self.space)
        _initialize_set(self.space, a, self.space.wrap("abcdefg"))
        a.intersect = None

        b = W_SetObject(self.space)
        _initialize_set(self.space, b, self.space.wrap("abc"))

        result = a.descr_intersection(space, [b])
        assert space.is_true(
            self.space.eq(result, W_SetObject(space, self.space.wrap("abc"))))

        c = W_SetObject(self.space)
        _initialize_set(self.space, c, self.space.wrap("e"))

        d = W_SetObject(self.space)
        _initialize_set(self.space, d, self.space.wrap("ab"))

        # if ordering works correct we should start with set e
        a.get_storage_copy = None
        b.get_storage_copy = None
        d.get_storage_copy = None

        result = a.descr_intersection(space, [d, c, b])
        assert space.is_true(
            self.space.eq(result, W_SetObject(space, self.space.wrap(""))))
예제 #15
0
    def test_intersection_order(self):
        # theses tests make sure that intersection is done in the correct order
        # (smallest first)
        space = self.space
        a = W_SetObject(self.space)
        _initialize_set(self.space, a, self.space.wrap("abcdefg"))
        a.intersect = None

        b = W_SetObject(self.space)
        _initialize_set(self.space, b, self.space.wrap("abc"))

        result = set_intersection__Set(space, a, [b])
        assert space.is_true(self.space.eq(result, W_SetObject(space, self.space.wrap("abc"))))

        c = W_SetObject(self.space)
        _initialize_set(self.space, c, self.space.wrap("e"))

        d = W_SetObject(self.space)
        _initialize_set(self.space, d, self.space.wrap("ab"))

        # if ordering works correct we should start with set e
        a.get_storage_copy = None
        b.get_storage_copy = None
        d.get_storage_copy = None

        result = set_intersection__Set(space, a, [d,c,b])
        assert space.is_true(self.space.eq(result, W_SetObject(space, self.space.wrap(""))))
예제 #16
0
    def test_create_set_from_list(self):
        from pypy.interpreter.baseobjspace import W_Root
        from pypy.objspace.std.setobject import BytesSetStrategy, ObjectSetStrategy, UnicodeSetStrategy
        from pypy.objspace.std.floatobject import W_FloatObject

        w = self.space.wrap
        wb = self.space.wrapbytes
        intstr = self.space.fromcache(IntegerSetStrategy)
        tmp_func = intstr.get_storage_from_list
        # test if get_storage_from_list is no longer used
        intstr.get_storage_from_list = None

        w_list = W_ListObject(self.space, [w(1), w(2), w(3)])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is intstr
        assert intstr.unerase(w_set.sstorage) == {1:None, 2:None, 3:None}

        w_list = W_ListObject(self.space, [wb("1"), wb("2"), wb("3")])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(BytesSetStrategy)
        assert w_set.strategy.unerase(w_set.sstorage) == {"1":None, "2":None, "3":None}

        w_list = self.space.iter(W_ListObject(self.space, [w(u"1"), w(u"2"), w(u"3")]))
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(UnicodeSetStrategy)
        assert w_set.strategy.unerase(w_set.sstorage) == {u"1":None, u"2":None, u"3":None}

        w_list = W_ListObject(self.space, [w("1"), w(2), w("3")])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(ObjectSetStrategy)
        for item in w_set.strategy.unerase(w_set.sstorage):
            assert isinstance(item, W_Root)

        w_list = W_ListObject(self.space, [w(1.0), w(2.0), w(3.0)])
        w_set = W_SetObject(self.space)
        _initialize_set(self.space, w_set, w_list)
        assert w_set.strategy is self.space.fromcache(ObjectSetStrategy)
        for item in w_set.strategy.unerase(w_set.sstorage):
            assert isinstance(item, W_FloatObject)

        # changed cached object, need to change it back for other tests to pass
        intstr.get_storage_from_list = tmp_func
예제 #17
0
 def test_compare(self):
     s = W_SetObject(self.space, None)
     _initialize_set(self.space, s, self.word)
     t = W_SetObject(self.space, None)
     _initialize_set(self.space, t, self.word)
     assert self.space.eq_w(s, t)
예제 #18
0
 def test_compare(self):
     s = W_SetObject(self.space, None)
     _initialize_set(self.space, s, self.word)
     t = W_SetObject(self.space, None)
     _initialize_set(self.space, t, self.word)
     assert self.space.eq_w(s,t)