Commits

mattip committed 45a97e4

add a passing test: getitem is returning a dtype instance that can be used as an int

Comments (0)

Files changed (1)

pypy/module/cpyext/test/test_typeobject.py

         obj = foo.new()
         assert module.hack_tp_dict(obj) == 2
 
+    def test_getitem(self):
+        import numpypy as np
+        module = self.import_extension('foo', [
+            ("test_getitem", "METH_O",
+             '''
+                PyObject *j, *retval;
+                j = PyInt_FromLong(2);
+                retval = PyObject_GetItem(args, j);
+                Py_DECREF(j);
+                return retval;
+            '''),
+            ],
+            )
+        val = module.test_getitem([10, 11, 12, 13, 14])
+        assert val == 12
+        val = module.test_getitem(np.array([20, 21, 22, 23, 24, 25]))
+        assert val == 22
+
 
 class TestTypes(BaseApiTest):
     def test_type_attributes(self, space, api):
         ref = make_ref(space, w_obj)
         api.Py_DecRef(ref)
 
+
 class AppTestSlots(AppTestCpythonExtensionBase):
     def test_some_slots(self):
         module = self.import_extension('foo', [