Пример #1
0
 def test_empty_setslice_with_objectlist(self):
     l = W_ListObject(self.space, [])
     o = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap("2"), self.space.wrap(3)])
     l.setslice(0, 1, o.length(), o)
     assert l.getitems() == o.getitems()
     l.append(self.space.wrap(17))
     assert l.getitems() != o.getitems()
Пример #2
0
    def test_empty_setslice_with_objectlist(self):
        space = self.space
        w = space.wrap

        l = W_ListObject(space, [])
        o = W_ListObject(space, [space.wrap(1), space.wrap("2"), space.wrap(3)])
        l.setslice(0, 1, o.length(), o)
        assert l.getitems() == o.getitems()
        l.append(space.wrap(17))
        assert l.getitems() != o.getitems()
Пример #3
0
    def test_setslice_List(self):

        def wrapitems(items):
            items_w = []
            for i in items:
                items_w.append(self.space.wrap(i))
            return items_w

        def keep_other_strategy(w_list, start, step, length, w_other):
            other_strategy = w_other.strategy
            w_list.setslice(start, step, length, w_other)
            assert w_other.strategy is other_strategy

        l = W_ListObject(self.space, wrapitems([1,2,3,4,5]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)

        l = W_ListObject(self.space, wrapitems([1,2,3,4,5]))
        other = W_ListObject(self.space, wrapitems([6, 6, 6]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(IntegerListStrategy)

        l = W_ListObject(self.space, wrapitems(["a","b","c","d","e"]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(StringListStrategy)

        l = W_ListObject(self.space, wrapitems(["a",3,"c",4,"e"]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)

        l = W_ListObject(self.space, wrapitems(["a",3,"c",4,"e"]))
        other = W_ListObject(self.space, [])
        keep_other_strategy(l, 0, 1, l.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)
Пример #4
0
    def test_setslice_List(self):
        space = self.space

        def wrapitems(items, bytes=False):
            items_w = []
            for i in items:
                w_item = space.wrapbytes(i) if bytes else space.wrap(i)
                items_w.append(w_item)
            return items_w

        def keep_other_strategy(w_list, start, step, length, w_other):
            other_strategy = w_other.strategy
            w_list.setslice(start, step, length, w_other)
            assert w_other.strategy is other_strategy

        l = W_ListObject(space, wrapitems([1,2,3,4,5]))
        other = W_ListObject(space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is space.fromcache(ObjectListStrategy)

        l = W_ListObject(space, wrapitems([1,2,3,4,5]))
        other = W_ListObject(space, wrapitems([6, 6, 6]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is space.fromcache(IntegerListStrategy)

        l = W_ListObject(space, wrapitems(["a","b","c","d","e"], bytes=True))
        other = W_ListObject(space, wrapitems(["a", "b", "c"], bytes=True))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is space.fromcache(BytesListStrategy)

        l = W_ListObject(space, wrapitems([u"a",u"b",u"c",u"d",u"e"]))
        other = W_ListObject(space, wrapitems([u"a", u"b", u"c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is space.fromcache(UnicodeListStrategy)

        l = W_ListObject(space, wrapitems([1.1, 2.2, 3.3, 4.4, 5.5]))
        other = W_ListObject(space, [])
        keep_other_strategy(l, 0, 1, l.length(), other)
        assert l.strategy is space.fromcache(FloatListStrategy)

        l = W_ListObject(space, wrapitems(["a",3,"c",4,"e"]))
        other = W_ListObject(space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is space.fromcache(ObjectListStrategy)

        l = W_ListObject(space, wrapitems(["a",3,"c",4,"e"]))
        other = W_ListObject(space, [])
        keep_other_strategy(l, 0, 1, l.length(), other)
        assert l.strategy is space.fromcache(ObjectListStrategy)
Пример #5
0
    def test_setslice_List(self):
        def wrapitems(items):
            items_w = []
            for i in items:
                items_w.append(self.space.wrap(i))
            return items_w

        def keep_other_strategy(w_list, start, step, length, w_other):
            other_strategy = w_other.strategy
            w_list.setslice(start, step, length, w_other)
            assert w_other.strategy is other_strategy

        l = W_ListObject(self.space, wrapitems([1, 2, 3, 4, 5]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)

        l = W_ListObject(self.space, wrapitems([1, 2, 3, 4, 5]))
        other = W_ListObject(self.space, wrapitems([6, 6, 6]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(IntegerListStrategy)

        l = W_ListObject(self.space, wrapitems(["a", "b", "c", "d", "e"]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(StringListStrategy)

        l = W_ListObject(self.space, wrapitems([1.1, 2.2, 3.3, 4.4, 5.5]))
        other = W_ListObject(self.space, [])
        keep_other_strategy(l, 0, 1, l.length(), other)
        assert l.strategy is self.space.fromcache(FloatListStrategy)

        l = W_ListObject(self.space, wrapitems(["a", 3, "c", 4, "e"]))
        other = W_ListObject(self.space, wrapitems(["a", "b", "c"]))
        keep_other_strategy(l, 0, 2, other.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)

        l = W_ListObject(self.space, wrapitems(["a", 3, "c", 4, "e"]))
        other = W_ListObject(self.space, [])
        keep_other_strategy(l, 0, 1, l.length(), other)
        assert l.strategy is self.space.fromcache(ObjectListStrategy)