[pypy-commit] pypy list-strategies: Added tests for extend
l.diekmann
noreply at buildbot.pypy.org
Fri Sep 23 13:11:35 CEST 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47433:f34cf6b46a37
Date: 2011-02-23 16:58 +0100
http://bitbucket.org/pypy/pypy/changeset/f34cf6b46a37/
Log: Added tests for extend
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -201,10 +201,9 @@
assert index == 0
self.append(w_list, w_item)
- def extend(self, w_list, items_w):
- #XXX: would be faster if items_w was a W_List and we could get its strategy
- w_list.strategy = get_strategy_from_list_objects(items_w)
- w_list.strategy.init_from_list_w(w_list, items_w)
+ def extend(self, w_list, w_other):
+ w_list.strategy = w_other.strategy
+ w_list.strategy.init_from_list_w(w_list, w_other.getitems())
class AbstractUnwrappedStrategy(ListStrategy):
def unwrap(self, w_obj):
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -98,4 +98,19 @@
l.setslice(0, 1, 2, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
+ def test_extend(self):
+ l = W_ListObject([])
+ assert isinstance(l.strategy, EmptyListStrategy)
+ l.extend(W_ListObject([self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)]))
+ assert isinstance(l.strategy, IntegerListStrategy)
+ l = W_ListObject([self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
+ assert isinstance(l.strategy, IntegerListStrategy)
+ l.extend(W_ListObject([self.space.wrap('a'), self.space.wrap('b'), self.space.wrap('c')]))
+ assert isinstance(l.strategy, ObjectListStrategy)
+
+ l = W_ListObject([self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
+ assert isinstance(l.strategy, IntegerListStrategy)
+ l.extend(W_ListObject([self.space.wrap(4), self.space.wrap(5), self.space.wrap(6)]))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
More information about the pypy-commit
mailing list