[pypy-svn] pypy default: Add an obscure test.
arigo
commits-noreply at bitbucket.org
Wed Jan 26 13:56:02 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41345:fe4079a2be07
Date: 2011-01-26 13:55 +0100
http://bitbucket.org/pypy/pypy/changeset/fe4079a2be07/
Log: Add an obscure test.
diff --git a/pypy/module/itertools/test/test_itertools.py b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -30,6 +30,12 @@
it = itertools.count(12.1, 1.0)
assert repr(it) == 'count(12.1, 1.0)'
+ def test_count_invalid(self):
+ import itertools
+
+ raises(TypeError, itertools.count, None)
+ raises(TypeError, itertools.count, 'a')
+
def test_repeat(self):
import itertools
diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -32,8 +32,17 @@
return self.space.wrap(s)
+def check_number(space, w_obj):
+ if (space.lookup(w_obj, '__add__') is None or
+ space.is_true(space.isinstance(w_obj, space.w_str)) or
+ space.is_true(space.isinstance(w_obj, space.w_unicode))):
+ raise OperationError(space.w_TypeError,
+ space.wrap("expected a number"))
+
@unwrap_spec(ObjSpace, W_Root, W_Root, W_Root)
def W_Count___new__(space, w_subtype, w_start=0, w_step=1):
+ check_number(space, w_start)
+ check_number(space, w_step)
r = space.allocate_instance(W_Count, w_subtype)
r.__init__(space, w_start, w_step)
return space.wrap(r)
More information about the Pypy-commit
mailing list