[pypy-commit] pypy default: test/fix xrange rejecting floats
bdkearns
noreply at buildbot.pypy.org
Sat Apr 26 08:18:09 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r70999:171d134c9340
Date: 2014-04-26 02:14 -0400
http://bitbucket.org/pypy/pypy/changeset/171d134c9340/
Log: test/fix xrange rejecting floats
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -351,17 +351,17 @@
self.promote_step = promote_step
def descr_new(space, w_subtype, w_start, w_stop=None, w_step=None):
- start = _toint(space, w_start)
+ start = space.int_w(w_start)
if space.is_none(w_step): # no step argument provided
step = 1
promote_step = True
else:
- step = _toint(space, w_step)
+ step = space.int_w(w_step)
promote_step = False
if space.is_none(w_stop): # only 1 argument provided
start, stop = 0, start
else:
- stop = _toint(space, w_stop)
+ stop = space.int_w(w_stop)
howmany = get_len_of_range(space, start, stop, step)
obj = space.allocate_instance(W_XRange, w_subtype)
W_XRange.__init__(obj, space, start, howmany, step, promote_step)
@@ -425,11 +425,6 @@
minint = -sys.maxint - 1
return minint if last < minint - step else last + step
-def _toint(space, w_obj):
- # this also supports float arguments. CPython still does, too.
- # needs a bit more thinking in general...
- return space.int_w(space.int(w_obj))
-
W_XRange.typedef = TypeDef("xrange",
__new__ = interp2app(W_XRange.descr_new.im_func),
__repr__ = interp2app(W_XRange.descr_repr),
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -311,14 +311,14 @@
def test_xrange_len(self):
x = xrange(33)
assert len(x) == 33
- x = xrange(33.2)
- assert len(x) == 33
+ exc = raises(TypeError, xrange, 33.2)
+ assert "integer" in str(exc.value)
x = xrange(33,0,-1)
assert len(x) == 33
x = xrange(33,0)
assert len(x) == 0
- x = xrange(33,0.2)
- assert len(x) == 0
+ exc = raises(TypeError, xrange, 33, 0.2)
+ assert "integer" in str(exc.value)
x = xrange(0,33)
assert len(x) == 33
x = xrange(0,33,-1)
diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -1,5 +1,4 @@
class AppTestMap:
-
def test_trivial_map_one_seq(self):
assert map(lambda x: x+2, [1, 2, 3, 4]) == [3, 4, 5, 6]
@@ -77,6 +76,7 @@
assert result == [(2, 7), (1, 6), (None, 5), (None, 4),
(None, 3), (None, 2), (None, 1)]
+
class AppTestZip:
def test_one_list(self):
assert zip([1,2,3]) == [(1,), (2,), (3,)]
@@ -93,6 +93,7 @@
yield None
assert zip(Foo()) == []
+
class AppTestReduce:
def test_None(self):
raises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None)
@@ -105,6 +106,7 @@
assert reduce(lambda x, y: x-y, [10, 2, 8]) == 0
assert reduce(lambda x, y: x-y, [2, 8], 10) == 0
+
class AppTestFilter:
def test_None(self):
assert filter(None, ['a', 'b', 1, 0, None]) == ['a', 'b', 1]
@@ -125,6 +127,7 @@
return i * 10
assert filter(lambda x: x != 20, T("abcd")) == (0, 10, 30)
+
class AppTestXRange:
def test_xrange(self):
x = xrange(2, 9, 3)
@@ -155,7 +158,8 @@
assert list(xrange(0, 10, A())) == [0, 5]
def test_xrange_float(self):
- assert list(xrange(0.1, 2.0, 1.1)) == [0, 1]
+ exc = raises(TypeError, xrange, 0.1, 2.0, 1.1)
+ assert "integer" in str(exc.value)
def test_xrange_long(self):
import sys
@@ -218,6 +222,7 @@
assert list(reversed(list(reversed("hello")))) == ['h','e','l','l','o']
raises(TypeError, reversed, reversed("hello"))
+
class AppTestApply:
def test_apply(self):
def f(*args, **kw):
@@ -228,6 +233,7 @@
assert apply(f, args) == (args, {})
assert apply(f, args, kw) == (args, kw)
+
class AppTestAllAny:
"""
These are copied directly and replicated from the Python 2.5 source code.
@@ -277,6 +283,7 @@
S = [10, 20, 30]
assert any([x > 42 for x in S]) == False
+
class AppTestMinMax:
def test_min(self):
assert min(1, 2) == 1
More information about the pypy-commit
mailing list