test_scripts.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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
  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.7 the scripts would be named
  23. # 'f2py', 'f2py3', and 'f2py3.7'.
  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. def test_pep338():
  36. stdout = subprocess.check_output([sys.executable, '-mnumpy.f2py', '-v'])
  37. assert_equal(stdout.strip(), np.__version__.encode('ascii'))