Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d86576c

Browse files
committed
TST: fix linting, add dependency on meson for tests
1 parent 14fd4e4 commit d86576c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

numpy/random/tests/test_extending.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import importlib
1+
from importlib.util import spec_from_file_location, module_from_spec
22
import os
33
import pathlib
44
import pytest
@@ -60,7 +60,9 @@ def test_cython(tmp_path):
6060
# We don't want a wheel build, so do the steps in a controlled way
6161
# The meson.build file is not copied as part of the build, so generate it
6262
with open(build_dir / "meson.build", "wt", encoding="utf-8") as fid:
63-
fid.write(textwrap.dedent("""\
63+
get_inc = ('import os; os.chdir(".."); import numpy; '
64+
'print(os.path.abspath(numpy.get_include() + "../../.."))')
65+
fid.write(textwrap.dedent(f"""\
6466
project('random-build-examples', 'c', 'cpp', 'cython')
6567
6668
# https://mesonbuild.com/Python-module.html
@@ -77,10 +79,8 @@ def test_cython(tmp_path):
7779
error('tests requires Cython >= 0.29.35')
7880
endif
7981
80-
_numpy_abs = run_command(py3,
81-
['-c', 'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
82-
check: true
83-
).stdout().strip()
82+
_numpy_abs = run_command(py3, ['-c', '{get_inc}'],
83+
check: true).stdout().strip()
8484
8585
npymath_path = _numpy_abs / 'core' / 'lib'
8686
npy_include_path = _numpy_abs / 'core' / 'include'
@@ -123,11 +123,11 @@ def test_cython(tmp_path):
123123
# import without adding the directory to sys.path
124124
so1 = sorted(glob.glob(str(target_dir / "extending.*")))[0]
125125
so2 = sorted(glob.glob(str(target_dir / "extending_distributions.*")))[0]
126-
spec1 = importlib.util.spec_from_file_location("extending", so1)
127-
spec2 = importlib.util.spec_from_file_location("extending_distributions", so2)
128-
extending = importlib.util.module_from_spec(spec1)
126+
spec1 = spec_from_file_location("extending", so1)
127+
spec2 = spec_from_file_location("extending_distributions", so2)
128+
extending = module_from_spec(spec1)
129129
spec1.loader.exec_module(extending)
130-
extending_distributions = importlib.util.module_from_spec(spec2)
130+
extending_distributions = module_from_spec(spec2)
131131
spec2.loader.exec_module(extending_distributions)
132132
# actually test the cython c-extension
133133
from numpy.random import PCG64

test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cython>=0.29.34,<3.0
22
wheel==0.38.1
33
setuptools==59.2.0 ; python_version < '3.12'
44
setuptools ; python_version >= '3.12'
5+
meson
56
hypothesis==6.24.1
67
pytest==6.2.5
78
pytz==2021.3

0 commit comments

Comments
 (0)