summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-03-18 23:53:09 +0200
committerGitHub <noreply@github.com>2020-03-18 23:53:09 +0200
commit965b41d418e6100c1afae0b6f818a7ef152bc25d (patch)
tree0e31074466dd881a08c4a26de424362e035d9a53 /numpy/f2py
parentc2dd245047ff2eb80972600163ecac9048d74e1f (diff)
downloadnumpy-965b41d418e6100c1afae0b6f818a7ef152bc25d.tar.gz
BUG, TST: fix f2py for PyPy, skip one test for PyPy (#15750)
* BUG, TST: fix f2py for PyPy, skip one test for PyPy, xfail tests for s390x
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/cfuncs.py6
-rw-r--r--numpy/f2py/tests/test_block_docstring.py3
-rw-r--r--numpy/f2py/tests/test_callback.py6
-rw-r--r--numpy/f2py/tests/test_mixed.py6
-rw-r--r--numpy/f2py/tests/test_return_character.py13
-rw-r--r--numpy/f2py/tests/test_return_complex.py9
-rw-r--r--numpy/f2py/tests/test_return_integer.py10
-rw-r--r--numpy/f2py/tests/test_return_real.py15
8 files changed, 34 insertions, 34 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 1d6ada247..f1ac214d4 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -1033,6 +1033,8 @@ cfuncs[
'try_pyarr_from_complex_double'] = 'static int try_pyarr_from_complex_double(PyObject* obj,complex_double* v) {\n TRYCOMPLEXPYARRAYTEMPLATE(double,\'D\');\n}\n'
needs['create_cb_arglist'] = ['CFUNCSMESS', 'PRINTPYOBJERR', 'MINMAX']
+
+# create the list of arguments to be used when calling back to python
cfuncs['create_cb_arglist'] = """\
static int create_cb_arglist(PyObject* fun,PyTupleObject* xa,const int maxnofargs,const int nofoptargs,int *nofargs,PyTupleObject **args,const char *errmess) {
PyObject *tmp = NULL;
@@ -1058,6 +1060,10 @@ static int create_cb_arglist(PyObject* fun,PyTupleObject* xa,const int maxnofarg
tmp_fun = fun; /* built-in function */
Py_INCREF(tmp_fun);
tot = maxnofargs;
+ if (PyCFunction_Check(fun)) {
+ /* In case the function has a co_argcount (like on PyPy) */
+ di = 0;
+ }
if (xa != NULL)
tot += PyTuple_Size((PyObject *)xa);
}
diff --git a/numpy/f2py/tests/test_block_docstring.py b/numpy/f2py/tests/test_block_docstring.py
index 03660f021..e431f5ba6 100644
--- a/numpy/f2py/tests/test_block_docstring.py
+++ b/numpy/f2py/tests/test_block_docstring.py
@@ -16,7 +16,8 @@ class TestBlockDocString(util.F2PyTest):
@pytest.mark.skipif(sys.platform=='win32',
reason='Fails with MinGW64 Gfortran (Issue #9673)')
- @pytest.mark.xfail(IS_PYPY, reason="PyPy does not modify tp_doc")
+ @pytest.mark.xfail(IS_PYPY,
+ reason="PyPy cannot modify tp_doc after PyType_Ready")
def test_block_docstring(self):
expected = "'i'-array(2,3)\n"
assert_equal(self.module.block.__doc__, expected)
diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py
index 7629df605..4e29ab9fc 100644
--- a/numpy/f2py/tests/test_callback.py
+++ b/numpy/f2py/tests/test_callback.py
@@ -4,7 +4,7 @@ import sys
import pytest
import numpy as np
-from numpy.testing import assert_, assert_equal
+from numpy.testing import assert_, assert_equal, IS_PYPY
from . import util
@@ -59,12 +59,12 @@ cf2py intent(out) a
end
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't,t2'.split(','))
def test_all(self, name):
self.check_function(name)
- @pytest.mark.slow
+ @pytest.mark.xfail(IS_PYPY,
+ reason="PyPy cannot modify tp_doc after PyType_Ready")
def test_docstring(self):
expected = textwrap.dedent("""\
a = t(fun,[fun_extra_args])
diff --git a/numpy/f2py/tests/test_mixed.py b/numpy/f2py/tests/test_mixed.py
index fc00ccc43..04266ca5b 100644
--- a/numpy/f2py/tests/test_mixed.py
+++ b/numpy/f2py/tests/test_mixed.py
@@ -2,7 +2,7 @@ import os
import textwrap
import pytest
-from numpy.testing import assert_, assert_equal
+from numpy.testing import assert_, assert_equal, IS_PYPY
from . import util
@@ -15,13 +15,13 @@ class TestMixed(util.F2PyTest):
_path('src', 'mixed', 'foo_fixed.f90'),
_path('src', 'mixed', 'foo_free.f90')]
- @pytest.mark.slow
def test_all(self):
assert_(self.module.bar11() == 11)
assert_(self.module.foo_fixed.bar12() == 12)
assert_(self.module.foo_free.bar13() == 13)
- @pytest.mark.slow
+ @pytest.mark.xfail(IS_PYPY,
+ reason="PyPy cannot modify tp_doc after PyType_Ready")
def test_docstring(self):
expected = textwrap.dedent("""\
a = bar11()
diff --git a/numpy/f2py/tests/test_return_character.py b/numpy/f2py/tests/test_return_character.py
index 6cb95a8b6..429e69bb4 100644
--- a/numpy/f2py/tests/test_return_character.py
+++ b/numpy/f2py/tests/test_return_character.py
@@ -3,12 +3,13 @@ import pytest
from numpy import array
from numpy.testing import assert_
from . import util
+import platform
+IS_S390X = platform.machine() == 's390x'
class TestReturnCharacter(util.F2PyTest):
- def check_function(self, t):
- tname = t.__doc__.split()[0]
+ def check_function(self, t, tname):
if tname in ['t0', 't1', 's0', 's1']:
assert_(t(23) == b'2')
r = t('ab')
@@ -79,10 +80,10 @@ cf2py intent(out) ts
end
"""
- @pytest.mark.slow
+ @pytest.mark.xfail(IS_S390X, reason="calback returns ' '")
@pytest.mark.parametrize('name', 't0,t1,t5,s0,s1,s5,ss'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module, name))
+ self.check_function(getattr(self.module, name), name)
class TestF90ReturnCharacter(TestReturnCharacter):
@@ -138,7 +139,7 @@ module f90_return_char
end module f90_return_char
"""
- @pytest.mark.slow
+ @pytest.mark.xfail(IS_S390X, reason="calback returns ' '")
@pytest.mark.parametrize('name', 't0,t1,t5,ts,s0,s1,s5,ss'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module.f90_return_char, name))
+ self.check_function(getattr(self.module.f90_return_char, name), name)
diff --git a/numpy/f2py/tests/test_return_complex.py b/numpy/f2py/tests/test_return_complex.py
index 9063695bc..38b23e1f3 100644
--- a/numpy/f2py/tests/test_return_complex.py
+++ b/numpy/f2py/tests/test_return_complex.py
@@ -8,8 +8,7 @@ from . import util
class TestReturnComplex(util.F2PyTest):
- def check_function(self, t):
- tname = t.__doc__.split()[0]
+ def check_function(self, t, tname):
if tname in ['t0', 't8', 's0', 's8']:
err = 1e-5
else:
@@ -102,10 +101,9 @@ cf2py intent(out) td
end
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't0,t8,t16,td,s0,s8,s16,sd'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module, name))
+ self.check_function(getattr(self.module, name), name)
class TestF90ReturnComplex(TestReturnComplex):
@@ -161,7 +159,6 @@ module f90_return_complex
end module f90_return_complex
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't0,t8,t16,td,s0,s8,s16,sd'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module.f90_return_complex, name))
+ self.check_function(getattr(self.module.f90_return_complex, name), name)
diff --git a/numpy/f2py/tests/test_return_integer.py b/numpy/f2py/tests/test_return_integer.py
index 35f32e37d..c95835454 100644
--- a/numpy/f2py/tests/test_return_integer.py
+++ b/numpy/f2py/tests/test_return_integer.py
@@ -8,7 +8,7 @@ from . import util
class TestReturnInteger(util.F2PyTest):
- def check_function(self, t):
+ def check_function(self, t, tname):
assert_(t(123) == 123, repr(t(123)))
assert_(t(123.6) == 123)
assert_(t(long(123)) == 123)
@@ -36,7 +36,7 @@ class TestReturnInteger(util.F2PyTest):
assert_raises(Exception, t, t)
assert_raises(Exception, t, {})
- if t.__doc__.split()[0] in ['t8', 's8']:
+ if tname in ['t8', 's8']:
assert_raises(OverflowError, t, 100000000000000000000000)
assert_raises(OverflowError, t, 10000000011111111111111.23)
@@ -101,11 +101,10 @@ cf2py intent(out) t8
end
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name',
't0,t1,t2,t4,t8,s0,s1,s2,s4,s8'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module, name))
+ self.check_function(getattr(self.module, name), name)
class TestF90ReturnInteger(TestReturnInteger):
@@ -172,8 +171,7 @@ module f90_return_integer
end module f90_return_integer
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name',
't0,t1,t2,t4,t8,s0,s1,s2,s4,s8'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module.f90_return_integer, name))
+ self.check_function(getattr(self.module.f90_return_integer, name), name)
diff --git a/numpy/f2py/tests/test_return_real.py b/numpy/f2py/tests/test_return_real.py
index 1707aab45..258cf8d28 100644
--- a/numpy/f2py/tests/test_return_real.py
+++ b/numpy/f2py/tests/test_return_real.py
@@ -9,8 +9,8 @@ from . import util
class TestReturnReal(util.F2PyTest):
- def check_function(self, t):
- if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']:
+ def check_function(self, t, tname):
+ if tname in ['t0', 't4', 's0', 's4']:
err = 1e-5
else:
err = 0.0
@@ -32,7 +32,7 @@ class TestReturnReal(util.F2PyTest):
assert_(abs(t(array([234], 'B')) - 234.) <= err)
assert_(abs(t(array([234], 'f')) - 234.) <= err)
assert_(abs(t(array([234], 'd')) - 234.) <= err)
- if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']:
+ if tname in ['t0', 't4', 's0', 's4']:
assert_(t(1e200) == t(1e300)) # inf
#assert_raises(ValueError, t, array([234], 'S1'))
@@ -88,10 +88,9 @@ end interface
end python module c_ext_return_real
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't4,t8,s4,s8'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module, name))
+ self.check_function(getattr(self.module, name), name)
class TestF77ReturnReal(TestReturnReal):
@@ -143,10 +142,9 @@ cf2py intent(out) td
end
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't0,t4,t8,td,s0,s4,s8,sd'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module, name))
+ self.check_function(getattr(self.module, name), name)
class TestF90ReturnReal(TestReturnReal):
@@ -202,7 +200,6 @@ module f90_return_real
end module f90_return_real
"""
- @pytest.mark.slow
@pytest.mark.parametrize('name', 't0,t4,t8,td,s0,s4,s8,sd'.split(','))
def test_all(self, name):
- self.check_function(getattr(self.module.f90_return_real, name))
+ self.check_function(getattr(self.module.f90_return_real, name), name)