summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-04-30 20:15:59 -0400
committerCharles Harris <charlesr.harris@gmail.com>2015-04-30 20:15:59 -0400
commitad99656c5d13200b51404e06b2bd3a2ad9ef7439 (patch)
tree9dc92ffb5949ff8e81b6d85b4441921d4571b0b7
parent38cb7aa3815748c1d719e918718b7726a18ed1fc (diff)
parent83e0d1762ed96c5fa142c14546b1f188f8d68ec6 (diff)
downloadnumpy-ad99656c5d13200b51404e06b2bd3a2ad9ef7439.tar.gz
Merge pull request #5817 from matthew-brett/master
MRG: add module to test installed scripts
-rw-r--r--.travis.yml4
-rw-r--r--numpy/tests/test_scripts.py65
-rwxr-xr-xtools/travis-test.sh13
3 files changed, 79 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml
index 0bf2ab447..dbfe426b8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,6 +28,10 @@ before_install:
- ulimit -a
- mkdir builds
- pushd builds
+ # Build into own virtualenv
+ # We therefore control our own environment, avoid travis' numpy
+ - virtualenv --python=python venv
+ - source venv/bin/activate
- pip install nose
# pip install coverage
- python -V
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'))
diff --git a/tools/travis-test.sh b/tools/travis-test.sh
index 3981c3b58..f31f1dc56 100755
--- a/tools/travis-test.sh
+++ b/tools/travis-test.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
set -ex
# travis boxes give you 1.5 cpus
@@ -120,10 +120,17 @@ fi
export PYTHON
export PIP
if [ -n "$USE_WHEEL" ] && [ $# -eq 0 ]; then
- $PIP install --upgrade pip
+ # Build wheel
$PIP install wheel
$PYTHON setup.py bdist_wheel
- $PIP install --pre --upgrade --find-links dist numpy
+ # Make another virtualenv to install into
+ virtualenv --python=python venv-for-wheel
+ . venv-for-wheel/bin/activate
+ # Move out of source directory to avoid finding local numpy
+ pushd dist
+ $PIP install --pre --upgrade --find-links . numpy
+ $PIP install nose
+ popd
run_test
elif [ "$USE_CHROOT" != "1" ] && [ "$USE_BENTO" != "1" ]; then
setup_base