Author: Devin Jeanpierre <[email protected]>
Branch: 
Changeset: r84087:ae51d22a2c25
Date: 2016-05-01 00:04 -0700
http://bitbucket.org/pypy/pypy/changeset/ae51d22a2c25/

Log:    merge branch cpyext-test-A. This gets all cpyext tests passing under
        -A.

        All the fixes are either by changing behavior to do the CPython-
        compatible thing, "#ifdef PYPY_VERSION" to have PyPy-specific test
        behavior, or else a @pytest.mark.skipif for tests that shouldn't be
        run in CPython at all.

diff --git a/pypy/module/cpyext/test/test_datetime.py 
b/pypy/module/cpyext/test/test_datetime.py
--- a/pypy/module/cpyext/test/test_datetime.py
+++ b/pypy/module/cpyext/test/test_datetime.py
@@ -109,7 +109,7 @@
                  Py_RETURN_NONE;
              """
              )
-            ])
+            ], prologue='#include "datetime.h"\n')
         import datetime
         assert module.get_types() == (datetime.date,
                                       datetime.datetime,
diff --git a/pypy/module/cpyext/test/test_dictobject.py 
b/pypy/module/cpyext/test/test_dictobject.py
--- a/pypy/module/cpyext/test/test_dictobject.py
+++ b/pypy/module/cpyext/test/test_dictobject.py
@@ -181,6 +181,7 @@
                  if (!PyArg_ParseTuple(args, "O", &dict))
                      return NULL;
                  proxydict = PyDictProxy_New(dict);
+#ifdef PYPY_VERSION  // PyDictProxy_Check[Exact] are PyPy-specific.
                  if (!PyDictProxy_Check(proxydict)) {
                     Py_DECREF(proxydict);
                     PyErr_SetNone(PyExc_ValueError);
@@ -191,6 +192,7 @@
                     PyErr_SetNone(PyExc_ValueError);
                     return NULL;
                  }
+#endif  // PYPY_VERSION
                  i = PyObject_Size(proxydict);
                  Py_DECREF(proxydict);
                  return PyLong_FromLong(i);
diff --git a/pypy/module/cpyext/test/test_thread.py 
b/pypy/module/cpyext/test/test_thread.py
--- a/pypy/module/cpyext/test/test_thread.py
+++ b/pypy/module/cpyext/test/test_thread.py
@@ -1,9 +1,12 @@
-import py
+import sys
+
+import py, pytest
 
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 
 
 class AppTestThread(AppTestCpythonExtensionBase):
+    @pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, 
reason='pypy only test')
     def test_get_thread_ident(self):
         module = self.import_extension('foo', [
             ("get_thread_ident", "METH_NOARGS",
@@ -30,6 +33,7 @@
 
         assert results[0][0] != results[1][0]
 
+    @pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, 
reason='pypy only test')
     def test_acquire_lock(self):
         module = self.import_extension('foo', [
             ("test_acquire_lock", "METH_NOARGS",
@@ -53,13 +57,14 @@
             ])
         module.test_acquire_lock()
 
+    @pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, 
reason='pypy only test')
     def test_release_lock(self):
         module = self.import_extension('foo', [
             ("test_release_lock", "METH_NOARGS",
              """
 #ifndef PyThread_release_lock
 #error "seems we are not accessing PyPy's functions"
-#endif           
+#endif
                  PyThread_type_lock lock = PyThread_allocate_lock();
                  PyThread_acquire_lock(lock, 1);
                  PyThread_release_lock(lock);
@@ -74,6 +79,7 @@
             ])
         module.test_release_lock()
 
+    @pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, 
reason='pypy only test')
     def test_tls(self):
         module = self.import_extension('foo', [
             ("create_key", "METH_NOARGS",
diff --git a/pypy/module/cpyext/test/test_tupleobject.py 
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -84,7 +84,14 @@
              """
                 PyObject *item = PyTuple_New(0);
                 PyObject *t = PyTuple_New(1);
-                if (t->ob_refcnt != 1 || item->ob_refcnt != 1) {
+#ifdef PYPY_VERSION
+                // PyPy starts even empty tuples with a refcount of 1.
+                const int initial_item_refcount = 1;
+#else
+                // CPython can cache ().
+                const int initial_item_refcount = item->ob_refcnt;
+#endif  // PYPY_VERSION
+                if (t->ob_refcnt != 1 || item->ob_refcnt != 
initial_item_refcount) {
                     PyErr_SetString(PyExc_SystemError, "bad initial refcnt");
                     return NULL;
                 }
@@ -94,8 +101,8 @@
                     PyErr_SetString(PyExc_SystemError, "SetItem: t refcnt != 
1");
                     return NULL;
                 }
-                if (item->ob_refcnt != 1) {
-                    PyErr_SetString(PyExc_SystemError, "SetItem: item refcnt 
!= 1");
+                if (item->ob_refcnt != initial_item_refcount) {
+                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt 
!= initial_item_refcount");
                     return NULL;
                 }
 
@@ -109,8 +116,8 @@
                     PyErr_SetString(PyExc_SystemError, "GetItem: t refcnt != 
1");
                     return NULL;
                 }
-                if (item->ob_refcnt != 1) {
-                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt 
!= 1");
+                if (item->ob_refcnt != initial_item_refcount) {
+                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt 
!= initial_item_refcount");
                     return NULL;
                 }
                 return t;
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py 
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -24,8 +24,11 @@
                  if(PyUnicode_GetSize(s) != 11) {
                      result = -PyUnicode_GetSize(s);
                  }
+#ifdef PYPY_VERSION
+                 // Slightly silly test that tp_basicsize is reasonable.
                  if(s->ob_type->tp_basicsize != sizeof(void*)*7)
                      result = s->ob_type->tp_basicsize;
+#endif  // PYPY_VERSION
                  Py_DECREF(s);
                  return PyLong_FromLong(result);
              """),
@@ -85,8 +88,11 @@
              '''
              ),
             ])
-        res = module.test_hash(u"xyz")
-        assert res == hash(u'xyz')
+        obj = u'xyz'
+        # CPython in particular does not precompute ->hash, so we need to call
+        # hash() first.
+        expected_hash = hash(obj)
+        assert module.test_hash(obj) == expected_hash
 
     def test_default_encoded_string(self):
         module = self.import_extension('foo', [
diff --git a/pypy/module/cpyext/test/test_version.py 
b/pypy/module/cpyext/test/test_version.py
--- a/pypy/module/cpyext/test/test_version.py
+++ b/pypy/module/cpyext/test/test_version.py
@@ -1,4 +1,6 @@
-import py
+import sys
+
+import py, pytest
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 
 
@@ -22,8 +24,6 @@
             PyModule_AddIntConstant(m, "py_major_version", PY_MAJOR_VERSION);
             PyModule_AddIntConstant(m, "py_minor_version", PY_MINOR_VERSION);
             PyModule_AddIntConstant(m, "py_micro_version", PY_MICRO_VERSION);
-            PyModule_AddStringConstant(m, "pypy_version", PYPY_VERSION);
-            PyModule_AddIntConstant(m, "pypy_version_num", PYPY_VERSION_NUM);
         }
         """
         module = self.import_module(name='foo', init=init)
@@ -31,6 +31,18 @@
         assert module.py_major_version == sys.version_info.major
         assert module.py_minor_version == sys.version_info.minor
         assert module.py_micro_version == sys.version_info.micro
+
+    @pytest.mark.skipif('__pypy__' not in sys.builtin_module_names, 
reason='pypy only test')
+    def test_pypy_versions(self):
+        import sys
+        init = """
+        if (Py_IsInitialized()) {
+            PyObject *m = Py_InitModule("foo", NULL);
+            PyModule_AddStringConstant(m, "pypy_version", PYPY_VERSION);
+            PyModule_AddIntConstant(m, "pypy_version_num", PYPY_VERSION_NUM);
+        }
+        """
+        module = self.import_module(name='foo', init=init)
         v = sys.pypy_version_info
         s = '%d.%d.%d' % (v[0], v[1], v[2])
         if v.releaselevel != 'final':
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to