[pypy-svn] r79910 - in pypy/branch/psycopg2compatibility/pypy/module/cpyext: . test
dan at codespeak.net
dan at codespeak.net
Wed Dec 8 20:14:55 CET 2010
Author: dan
Date: Wed Dec 8 20:14:53 2010
New Revision: 79910
Modified:
pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py
pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py
Log:
Now reject dictionaries, test for this.
Modified: pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py (original)
+++ pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py Wed Dec 8 20:14:53 2010
@@ -9,6 +9,8 @@
from pypy.module.cpyext.tupleobject import PyTuple_Check, PyTuple_SetItem
from pypy.module.cpyext.object import Py_IncRef, Py_DecRef
+from pypy.module.cpyext.dictobject import PyDict_Check
+
@cpython_api([PyObject, Py_ssize_t], PyObject)
def PySequence_Repeat(space, w_obj, count):
"""Return the result of repeating sequence object o count times, or NULL on
@@ -136,5 +138,7 @@
This function used an int type for i. This might require
changes in your code for properly supporting 64-bit systems."""
+ if PyDict_Check(space, w_o) or not PySequence_Check(space, w_o):
+ raise OperationError(space.w_TypeError, "object doesn't support sequence assignment") # FIXME: format like CPython
space.setitem(w_o, space.wrap(i), w_v)
return 0
Modified: pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py (original)
+++ pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py Wed Dec 8 20:14:53 2010
@@ -72,23 +72,22 @@
assert exc.value.match(space, space.w_StopIteration)
def test_setitem(self, space, api):
- value = api.PyInt_FromLong(42)
- tup = api.PyTuple_New(1)
-
- result = api.PySequence_SetItem(tup, 0, value)
- assert result == -1
- assert api.PyErr_Occurred()
- assert api.PyErr_ExceptionMatches(space.w_TypeError)
+ def expect_error(w_o, i=0, v=42, w_err=space.w_TypeError):
+ value = space.wrap(v)
+ result = api.PySequence_SetItem(w_o, i, value)
+ assert result == -1
+ assert api.PyErr_Occurred()
+ assert api.PyErr_ExceptionMatches(w_err)
+ api.PyErr_Clear()
l = api.PyList_New(1)
-
- result = api.PySequence_SetItem(l, 0, value)
+ w_value = space.wrap(42)
+ result = api.PySequence_SetItem(l, 0, w_value)
assert result != -1
+ assert space.eq_w(space.getitem(l, space.wrap(0)), w_value)
- assert space.eq_w(space.getitem(l, space.wrap(0)), value)
+ expect_error(l, 3,
+ w_err=space.w_IndexError)
- result = api.PySequence_SetItem(l, 3, value)
- assert result == -1
- assert api.PyErr_Occurred()
- assert api.PyErr_ExceptionMatches(space.w_IndexError)
- api.PyErr_Clear()
+ expect_error(api.PyTuple_New(1)) # TypeError
+ expect_error(space.newdict()) # TypeError
More information about the Pypy-commit
mailing list