diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2015-12-10 16:24:08 -0800 |
---|---|---|
committer | Matthew Brett <matthew.brett@gmail.com> | 2015-12-10 16:24:08 -0800 |
commit | c2b6ab9924271b96d3c783f7818723a1bb8f511a (patch) | |
tree | f88b40237cb6954960f906aa9358c74334839c21 /numpy/tests/test_scripts.py | |
parent | edb902cdc6573553afcf11047ecdfb447e444322 (diff) | |
parent | b064e4b4cb3f8d571605ee8a7f53c9ce2d5df879 (diff) | |
download | numpy-maintenance/1.9.x.tar.gz |
Merge pull request #6350 from matthew-brett/prepare-1.9.4maintenance/1.9.x
MRG: preparing for potential 1.9.4 release
Fix f2py shebang line error for wheel installs.
Diffstat (limited to 'numpy/tests/test_scripts.py')
-rw-r--r-- | numpy/tests/test_scripts.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/numpy/tests/test_scripts.py b/numpy/tests/test_scripts.py new file mode 100644 index 000000000..b48e3f3f7 --- /dev/null +++ b/numpy/tests/test_scripts.py @@ -0,0 +1,65 @@ +""" Test scripts + +Test that we can run executable scripts that have been installed with numpy. +""" +from __future__ import division, print_function, absolute_import + +import os +from os.path import join as pathjoin, isfile, dirname, basename +import sys +from subprocess import Popen, PIPE +import numpy as np +from numpy.compat.py3k import basestring, asbytes +from nose.tools import assert_equal +from numpy.testing.decorators import skipif + +skipif_inplace = skipif(isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))) + +def run_command(cmd, check_code=True): + """ Run command sequence `cmd` returning exit code, stdout, stderr + + Parameters + ---------- + cmd : str or sequence + string with command name or sequence of strings defining command + check_code : {True, False}, optional + If True, raise error for non-zero return code + + Returns + ------- + returncode : int + return code from execution of `cmd` + stdout : bytes (python 3) or str (python 2) + stdout from `cmd` + stderr : bytes (python 3) or str (python 2) + stderr from `cmd` + + Raises + ------ + RuntimeError + If `check_code` is True, and return code !=0 + """ + cmd = [cmd] if isinstance(cmd, basestring) else list(cmd) + if os.name == 'nt': + # Quote any arguments with spaces. The quotes delimit the arguments + # on Windows, and the arguments might be file paths with spaces. + # On Unix the list elements are each separate arguments. + cmd = ['"{0}"'.format(c) if ' ' in c else c for c in cmd] + proc = Popen(cmd, stdout=PIPE, stderr=PIPE) + stdout, stderr = proc.communicate() + if proc.poll() == None: + proc.terminate() + if check_code and proc.returncode != 0: + raise RuntimeError('\n'.join( + ['Command "{0}" failed with', + 'stdout', '------', '{1}', '', + 'stderr', '------', '{2}']).format(cmd, stdout, stderr)) + return proc.returncode, stdout, stderr + + +@skipif_inplace +def test_f2py(): + # test that we can run f2py script + f2py_cmd = 'f2py' + basename(sys.executable)[6:] + code, stdout, stderr = run_command([f2py_cmd, '-v']) + assert_equal(stdout.strip(), asbytes('2')) |