test_scripts.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """ Test scripts
  2. Test that we can run executable scripts that have been installed with numpy.
  3. """
  4. import os
  5. import subprocess
  6. import sys
  7. from os.path import dirname, isfile
  8. from os.path import join as pathjoin
  9. import pytest
  10. import numpy as np
  11. from numpy.testing import IS_WASM, assert_equal
  12. is_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))
  13. def find_f2py_commands():
  14. if sys.platform == 'win32':
  15. exe_dir = dirname(sys.executable)
  16. if exe_dir.endswith('Scripts'): # virtualenv
  17. return [os.path.join(exe_dir, 'f2py')]
  18. else:
  19. return [os.path.join(exe_dir, "Scripts", 'f2py')]
  20. else:
  21. # Three scripts are installed in Unix-like systems:
  22. # 'f2py', 'f2py{major}', and 'f2py{major.minor}'. For example,
  23. # if installed with python3.9 the scripts would be named
  24. # 'f2py', 'f2py3', and 'f2py3.9'.
  25. version = sys.version_info
  26. major = str(version.major)
  27. minor = str(version.minor)
  28. return ['f2py', 'f2py' + major, 'f2py' + major + '.' + minor]
  29. @pytest.mark.skipif(is_inplace, reason="Cannot test f2py command inplace")
  30. @pytest.mark.xfail(reason="Test is unreliable")
  31. @pytest.mark.parametrize('f2py_cmd', find_f2py_commands())
  32. def test_f2py(f2py_cmd):
  33. # test that we can run f2py script
  34. stdout = subprocess.check_output([f2py_cmd, '-v'])
  35. assert_equal(stdout.strip(), np.__version__.encode('ascii'))
  36. @pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess")
  37. def test_pep338():
  38. stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v'])
  39. assert_equal(stdout.strip(), np.__version__.encode('ascii'))