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