From 7de9f6c72d26121376a2bba1f7b38da0cebbdd93 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 8 Jul 2016 17:44:12 -0400 Subject: [PATCH] Tests can skip by exiting with 99; fix eigen test failure This allows (and changes the current examples) to exit with status 99 to skip a test instead of outputting a special string ("NumPy missing"). This also fixes the eigen test, which currently fails when eigen headers are available but NumPy is not, to skip instead of failing when NumPy isn't available. --- example/eigen.py | 6 +++++- example/example10.py | 4 ++-- example/example7.py | 4 ++-- example/run_test.py | 16 ++++++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/example/eigen.py b/example/eigen.py index 7ff9aed5..8ab35efc 100644 --- a/example/eigen.py +++ b/example/eigen.py @@ -11,7 +11,11 @@ from example import sparse_r, sparse_c from example import sparse_passthrough_r, sparse_passthrough_c from example import double_row, double_col from example import double_mat_cm, double_mat_rm -import numpy as np +try: + import numpy as np +except ImportError: + # NumPy missing: skip test + exit(99) ref = np.array( [[0, 3, 0, 0, 0, 11], diff --git a/example/example10.py b/example/example10.py index b18e729a..e21c1a5f 100755 --- a/example/example10.py +++ b/example/example10.py @@ -7,8 +7,8 @@ import example try: import numpy as np except ImportError: - print('NumPy missing') - exit(0) + # NumPy missing: skip test + exit(99) from example import vectorized_func from example import vectorized_func2 diff --git a/example/example7.py b/example/example7.py index 62d33017..48eda27b 100755 --- a/example/example7.py +++ b/example/example7.py @@ -8,8 +8,8 @@ from example import Matrix try: import numpy as np except ImportError: - print('NumPy missing') - exit(0) + # NumPy missing: skip test + exit(99) m = Matrix(5, 5) diff --git a/example/run_test.py b/example/run_test.py index c31ea098..90fec067 100755 --- a/example/run_test.py +++ b/example/run_test.py @@ -52,16 +52,20 @@ if len(sys.argv) == 3 and sys.argv[1] == '--relaxed': relaxed = True name = sys.argv[1] -output_bytes = subprocess.check_output([sys.executable, name + ".py"], - stderr=subprocess.STDOUT) +try: + output_bytes = subprocess.check_output([sys.executable, name + ".py"], + stderr=subprocess.STDOUT) +except subprocess.CalledProcessError as e: + if e.returncode == 99: + print('Test "%s" could not be run.' % name) + exit(0) + else: + raise output = sanitize(output_bytes.decode('utf-8')) reference = sanitize(open(name + '.ref', 'r').read()) -if 'NumPy missing' in output: - print('Test "%s" could not be run.' % name) - exit(0) -elif output == reference: +if output == reference: print('Test "%s" succeeded.' % name) exit(0) else: