summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/random/_examples/cython/setup.py6
-rw-r--r--numpy/random/tests/test_extending.py39
2 files changed, 28 insertions, 17 deletions
diff --git a/numpy/random/_examples/cython/setup.py b/numpy/random/_examples/cython/setup.py
index 19f045fc0..7ed0a3a18 100644
--- a/numpy/random/_examples/cython/setup.py
+++ b/numpy/random/_examples/cython/setup.py
@@ -12,6 +12,7 @@ from setuptools.extension import Extension
from os.path import join, abspath, dirname
path = abspath(dirname(__file__))
+defs = [('NPY_NO_DEPRECATED_API', 0)]
extending = Extension("extending",
sources=[join(path, 'extending.pyx')],
@@ -19,10 +20,13 @@ extending = Extension("extending",
np.get_include(),
join(path, '..', '..')
],
+ define_macros=defs,
)
distributions = Extension("extending_distributions",
sources=[join(path, 'extending_distributions.pyx')],
- include_dirs=[np.get_include()])
+ include_dirs=[np.get_include()],
+ define_macros=defs,
+ )
extensions = [extending, distributions]
diff --git a/numpy/random/tests/test_extending.py b/numpy/random/tests/test_extending.py
index 807de1a25..0cad76ed1 100644
--- a/numpy/random/tests/test_extending.py
+++ b/numpy/random/tests/test_extending.py
@@ -1,6 +1,8 @@
import os, sys
import pytest
import warnings
+import shutil
+import subprocess
try:
import cffi
@@ -22,30 +24,35 @@ except ImportError:
try:
import cython
+ from Cython.Compiler.Version import version as cython_version
except ImportError:
cython = None
+else:
+ from distutils.version import LooseVersion
+ # Cython 0.29.14 is required for Python 3.8 and there are
+ # other fixes in the 0.29 series that are needed even for earlier
+ # Python versions.
+ # Note: keep in sync with the one in pyproject.toml
+ required_version = LooseVersion('0.29.14')
+ if LooseVersion(cython_version) < required_version:
+ # too old or wrong cython, skip the test
+ cython = None
@pytest.mark.skipif(cython is None, reason="requires cython")
-def test_cython():
- curdir = os.getcwd()
- argv = sys.argv
- examples = (os.path.dirname(__file__), '..', '_examples')
- try:
- os.chdir(os.path.join(*examples))
- sys.argv = argv[:1] + ['build']
- with warnings.catch_warnings(record=True) as w:
- # setuptools issue gh-1885
- warnings.filterwarnings('always', '', DeprecationWarning)
- from numpy.random._examples.cython import setup
- finally:
- sys.argv = argv
- os.chdir(curdir)
+@pytest.mark.slow
+@pytest.mark.skipif(sys.platform == 'win32', reason="cmd too long on CI")
+def test_cython(tmp_path):
+ examples = os.path.join(os.path.dirname(__file__), '..', '_examples')
+ base = os.path.dirname(examples)
+ shutil.copytree(examples, tmp_path / '_examples')
+ subprocess.check_call([sys.executable, 'setup.py', 'build'],
+ cwd=str(tmp_path / '_examples' / 'cython'))
@pytest.mark.skipif(numba is None or cffi is None,
reason="requires numba and cffi")
def test_numba():
- from numpy.random._examples.numba import extending
+ from numpy.random._examples.numba import extending
@pytest.mark.skipif(cffi is None, reason="requires cffi")
def test_cffi():
- from numpy.random._examples.cffi import extending
+ from numpy.random._examples.cffi import extending