test_scripts.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """ Test scripts
  2. Test that we can run executable scripts that have been installed with numpy.
  3. """
  4. import sys
  5. import os
  6. import pytest
  7. from os.path import join as pathjoin, isfile, dirname
  8. import subprocess
  9. import numpy as np
  10. from numpy.testing import assert_equal, IS_WASM
  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'))