diff options
author | Pauli Virtanen <pav@iki.fi> | 2017-08-16 18:00:18 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2017-08-16 18:16:14 +0200 |
commit | b5f472d450522a701fa526f8c85f7eb467d65c1a (patch) | |
tree | 8f825384891abfb3c2459aa19ff9460b765b9345 /numpy/testing/nose_tools/noseclasses.py | |
parent | 441c082c881455a1149fa14ab7de2b91286da554 (diff) | |
download | numpy-b5f472d450522a701fa526f8c85f7eb467d65c1a.tar.gz |
ENH: check for FPU mode changes in the test suite
Emit a test failure if the FPU mode changes when running a test case,
allowing to pinpoint what test caused the mode change.
Diffstat (limited to 'numpy/testing/nose_tools/noseclasses.py')
-rw-r--r-- | numpy/testing/nose_tools/noseclasses.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/testing/nose_tools/noseclasses.py b/numpy/testing/nose_tools/noseclasses.py index 2f5d05004..9756b9b45 100644 --- a/numpy/testing/nose_tools/noseclasses.py +++ b/numpy/testing/nose_tools/noseclasses.py @@ -7,6 +7,7 @@ from __future__ import division, absolute_import, print_function import os +import sys import doctest import inspect @@ -317,6 +318,31 @@ class KnownFailurePlugin(ErrorClassPlugin): KnownFailure = KnownFailurePlugin # backwards compat +class FPUModeCheckPlugin(Plugin): + """ + Plugin that checks the FPU mode before and after each test, + raising failures if the test changed the mode. + """ + + def prepareTestCase(self, test): + from numpy.core.multiarray_tests import get_fpu_mode + + def run(result): + old_mode = get_fpu_mode() + test.test(result) + new_mode = get_fpu_mode() + + if old_mode != new_mode: + try: + raise AssertionError( + "FPU mode changed from {0:#x} to {1:#x} during the " + "test".format(old_mode, new_mode)) + except AssertionError: + result.addFailure(test, sys.exc_info()) + + return run + + # Class allows us to save the results of the tests in runTests - see runTests # method docstring for details class NumpyTestProgram(nose.core.TestProgram): |