[pypy-commit] pypy simple-range-strategy: fix tests and add more
squeaky
noreply at buildbot.pypy.org
Tue Mar 4 18:52:19 CET 2014
Author: Squeaky <squeaky_pl at gmx.com>
Branch: simple-range-strategy
Changeset: r69672:dd78cd5b33b4
Date: 2014-03-03 22:11 +0100
http://bitbucket.org/pypy/pypy/changeset/dd78cd5b33b4/
Log: fix tests and add more
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
@@ -1616,7 +1616,7 @@
_base_extend_from_list = _extend_from_list
def _extend_from_list(self, w_list, w_other):
- if w_other.strategy is self.space.fromcache(RangeListStrategy):
+ if isinstance(w_other.strategy, BaseRangeListStrategy):
l = self.unerase(w_list.lstorage)
other = w_other.getitems_int()
assert other is not None
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
@@ -1,5 +1,8 @@
import sys
-from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy, FloatListStrategy, BytesListStrategy, RangeListStrategy, make_range_list, UnicodeListStrategy
+from pypy.objspace.std.listobject import (
+ W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy,
+ FloatListStrategy, BytesListStrategy, RangeListStrategy,
+ SimpleRangeListStrategy, make_range_list, UnicodeListStrategy)
from pypy.objspace.std import listobject
from pypy.objspace.std.test.test_listobject import TestW_ListObject
@@ -18,7 +21,7 @@
UnicodeListStrategy)
assert isinstance(W_ListObject(space, [w(u'a'), w('b')]).strategy,
ObjectListStrategy) # mixed unicode and bytes
-
+
def test_empty_to_any(self):
space = self.space
w = space.wrap
@@ -183,7 +186,7 @@
def test_setslice(self):
space = self.space
w = space.wrap
-
+
l = W_ListObject(space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.setslice(0, 1, 2, W_ListObject(space, [w(1), w(2), w(3)]))
@@ -286,7 +289,7 @@
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)
@@ -347,6 +350,13 @@
empty = W_ListObject(space, [])
assert isinstance(empty.strategy, EmptyListStrategy)
+ r = make_range_list(space, 0, 1, 10)
+ empty.extend(r)
+ assert isinstance(empty.strategy, SimpleRangeListStrategy)
+ assert space.is_true(space.eq(empty.getitem(1), w(1)))
+
+ empty = W_ListObject(space, [])
+ assert isinstance(empty.strategy, EmptyListStrategy)
empty.extend(W_ListObject(space, [w(1), w(2), w(3)]))
assert isinstance(empty.strategy, IntegerListStrategy)
@@ -397,6 +407,40 @@
l.append(self.space.wrap(19))
assert isinstance(l.strategy, IntegerListStrategy)
+ def test_simplerangelist(self):
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop(5)
+ assert self.space.eq_w(v, self.space.wrap(5))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop(0)
+ assert self.space.eq_w(v, self.space.wrap(0))
+ # XXX promote to RangeListStrategy
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop_end()
+ assert self.space.eq_w(v, self.space.wrap(9))
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop_end()
+ assert self.space.eq_w(v, self.space.wrap(8))
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 5)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ l.append(self.space.wrap("string"))
+ assert isinstance(l.strategy, ObjectListStrategy)
+
+ l = make_range_list(self.space, 0,1,5)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ l.append(self.space.wrap(19))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+
def test_keep_range(self):
# simple list
l = make_range_list(self.space, 1,1,5)
More information about the pypy-commit
mailing list