test_scripts.py 1.6 KB

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