[pypy-commit] pypy cpyext-fast-typecheck: add a passing test
antocuni
pypy.commits at gmail.com
Thu Mar 22 08:04:46 EDT 2018
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-fast-typecheck
Changeset: r94064:b8745d3e1669
Date: 2018-03-22 12:23 +0100
http://bitbucket.org/pypy/pypy/changeset/b8745d3e1669/
Log: add a passing test
diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -796,6 +796,34 @@
assert module.tp_init(list, x, ("hi",)) is None
assert x == ["h", "i"]
+ def test_mp_subscript(self):
+ module = self.import_extension('foo', [
+ ("new_obj", "METH_NOARGS",
+ '''
+ PyObject *obj;
+ obj = PyObject_New(PyObject, &Foo_Type);
+ return obj;
+ '''
+ )], prologue='''
+ static PyObject*
+ mp_subscript(PyObject *self, PyObject *key)
+ {
+ return Py_BuildValue("i", 42);
+ }
+ PyMappingMethods tp_as_mapping;
+ static PyTypeObject Foo_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "foo.foo",
+ };
+ ''', more_init = '''
+ Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ Foo_Type.tp_as_mapping = &tp_as_mapping;
+ tp_as_mapping.mp_subscript = (binaryfunc)mp_subscript;
+ if (PyType_Ready(&Foo_Type) < 0) INITERROR;
+ ''')
+ obj = module.new_obj()
+ assert obj[100] == 42
+
def test_mp_ass_subscript(self):
module = self.import_extension('foo', [
("new_obj", "METH_NOARGS",
More information about the pypy-commit
mailing list