codekingpro/portable-devtools
115k
1import importlib.metadata
2import os
3import pathlib
4import subprocess
5
6import pytest
7
8import numpy as np
9import numpy._core.include
10import numpy._core.lib.pkgconfig
11from numpy.testing import IS_EDITABLE, IS_INSTALLED, IS_WASM, NUMPY_ROOT
12
13INCLUDE_DIR = NUMPY_ROOT / '_core' / 'include'
14PKG_CONFIG_DIR = NUMPY_ROOT / '_core' / 'lib' / 'pkgconfig'
15
16
17@pytest.mark.skipif(not IS_INSTALLED,
18 reason="`numpy-config` not expected to be installed")
19@pytest.mark.skipif(IS_WASM,
20 reason="wasm interpreter cannot start subprocess")
21class TestNumpyConfig:
22 def check_numpyconfig(self, arg):
23 p = subprocess.run(['numpy-config', arg], capture_output=True, text=True)
24 p.check_returncode()
25 return p.stdout.strip()
26
27 def test_configtool_version(self):
28 stdout = self.check_numpyconfig('--version')
29 assert stdout == np.__version__
30
31 def test_configtool_cflags(self):
32 stdout = self.check_numpyconfig('--cflags')
33 assert f'-I{os.fspath(INCLUDE_DIR)}' in stdout
34
35 def test_configtool_pkgconfigdir(self):
36 stdout = self.check_numpyconfig('--pkgconfigdir')
37 assert pathlib.Path(stdout) == PKG_CONFIG_DIR.resolve()
38
39
40@pytest.mark.skipif(not IS_INSTALLED,
41 reason="numpy must be installed to check its entrypoints")
42def test_pkg_config_entrypoint():
43 (entrypoint,) = importlib.metadata.entry_points(group='pkg_config', name='numpy')
44 assert entrypoint.value == numpy._core.lib.pkgconfig.__name__
45
46
47@pytest.mark.skipif(not IS_INSTALLED,
48 reason="numpy.pc is only available when numpy is installed")
49@pytest.mark.skipif(IS_EDITABLE, reason="editable installs don't have a numpy.pc")
50def test_pkg_config_config_exists():
51 assert PKG_CONFIG_DIR.joinpath('numpy.pc').is_file()
52 