test_configtool.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import subprocess
  3. import sysconfig
  4. import pytest
  5. import numpy as np
  6. from numpy.testing import IS_WASM
  7. is_editable = not bool(np.__path__)
  8. numpy_in_sitepackages = sysconfig.get_path('platlib') in np.__file__
  9. # We only expect to have a `numpy-config` available if NumPy was installed via
  10. # a build frontend (and not `spin` for example)
  11. if not (numpy_in_sitepackages or is_editable):
  12. pytest.skip("`numpy-config` not expected to be installed",
  13. allow_module_level=True)
  14. def check_numpyconfig(arg):
  15. p = subprocess.run(['numpy-config', arg], capture_output=True, text=True)
  16. p.check_returncode()
  17. return p.stdout.strip()
  18. @pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocess")
  19. def test_configtool_version():
  20. stdout = check_numpyconfig('--version')
  21. assert stdout == np.__version__
  22. @pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocess")
  23. def test_configtool_cflags():
  24. stdout = check_numpyconfig('--cflags')
  25. assert stdout.endswith(os.path.join('numpy', '_core', 'include'))
  26. @pytest.mark.skipif(IS_WASM, reason="wasm interpreter cannot start subprocess")
  27. def test_configtool_pkgconfigdir():
  28. stdout = check_numpyconfig('--pkgconfigdir')
  29. assert stdout.endswith(os.path.join('numpy', '_core', 'lib', 'pkgconfig'))
  30. if not is_editable:
  31. # Also check that the .pc file actually exists (unless we're using an
  32. # editable install, then it'll be hiding in the build dir)
  33. assert os.path.exists(os.path.join(stdout, 'numpy.pc'))