[pypy-svn] r74090 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Mon Apr 26 19:25:13 CEST 2010
Author: afa
Date: Mon Apr 26 19:25:12 2010
New Revision: 74090
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/number.py
pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
Log:
PySeqIter_New
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/number.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/number.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/number.py Mon Apr 26 19:25:12 2010
@@ -46,7 +46,7 @@
@cpython_api([PyObject], PyObject)
def PyNumber_Long(space, w_obj):
- """ Returns the o converted to a long integer object on success, or NULL on
+ """Returns the o converted to a long integer object on success, or NULL on
failure. This is the equivalent of the Python expression long(o)."""
return space.long(w_obj)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py Mon Apr 26 19:25:12 2010
@@ -93,3 +93,12 @@
"""Return the concatenation of o1 and o2 on success, and NULL on failure.
This is the equivalent of the Python expression o1 + o2."""
return space.add(w_o1, w_o2)
+
+ at cpython_api([PyObject], PyObject)
+def PySeqIter_New(space, w_seq):
+ """Return an iterator that works with a general sequence object, seq. The
+ iteration ends when the sequence raises IndexError for the subscripting
+ operation.
+ """
+ return space.iter(w_seq)
+
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Mon Apr 26 19:25:12 2010
@@ -2635,14 +2635,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PySeqIter_New(space, seq):
- """Return an iterator that works with a general sequence object, seq. The
- iteration ends when the sequence raises IndexError for the subscripting
- operation.
- """
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyCallIter_Check(space, iter):
"""Return true if the type of op is PyCallIter_Type.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py Mon Apr 26 19:25:12 2010
@@ -2,6 +2,7 @@
from pypy.interpreter.error import OperationError
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext import sequence
+import py.test
class TestSequence(BaseApiTest):
def test_sequence(self, space, api):
@@ -43,3 +44,11 @@
w_t = space.wrap((1, 2, 3, 4, 5))
assert space.unwrap(api.PySequence_GetSlice(w_t, 2, 4)) == (3, 4)
assert space.unwrap(api.PySequence_GetSlice(w_t, 1, -1)) == (2, 3, 4)
+
+ def test_iter(self, space, api):
+ w_t = space.wrap((1, 2))
+ w_iter = api.PySeqIter_New(w_t)
+ assert space.unwrap(space.next(w_iter)) == 1
+ assert space.unwrap(space.next(w_iter)) == 2
+ exc = raises(OperationError, space.next, w_iter)
+ assert exc.value.match(space, space.w_StopIteration)
More information about the Pypy-commit
mailing list