test_configtool.py 1.8 KB

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