test_configtool.py 1.7 KB

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