diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2012-03-04 14:09:48 +0100 |
---|---|---|
committer | Mark Wiebe <mwwiebe@gmail.com> | 2012-03-04 12:59:21 -0800 |
commit | 7961e1f56ec9754cafcb9a67445b01d47d1b1676 (patch) | |
tree | ab2bf9cae04603618061cc7a8fa6a924eaca7d8e /numpy | |
parent | e692a7579b89bf43e8456f418e6b625a4e4a4233 (diff) | |
download | numpy-7961e1f56ec9754cafcb9a67445b01d47d1b1676.tar.gz |
TST: add "raise on warning" behavior to NoseTester constructor.
Also document that behavior has to be switched for a release, and remove
comments on turning on deprecation warnings that don't apply anymore.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/testing/nosetester.py | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py index 2fb08603e..9041ff69d 100644 --- a/numpy/testing/nosetester.py +++ b/numpy/testing/nosetester.py @@ -104,10 +104,22 @@ class NoseTester(object): Parameters ---------- - package : module, str or None + package : module, str or None, optional The package to test. If a string, this should be the full path to the package. If None (default), `package` is set to the module from which `NoseTester` is initialized. + raise_warnings : sequence of warnings, optional + This specifies which warnings to configure as 'raise' instead + of 'warn' during the test execution. To disable this feature, + pass an empty tuple. See Notes for more details. + + Notes + ----- + The default for `raise_warnings` is ``(DeprecationWarning, RuntimeWarning)`` + for the master branch of NumPy, and ``()`` for released versions. The + purpose of this switching behavior is to catch as many warnings as possible + during development, but not give problems for packaging of released + versions. """ # Stuff to exclude from tests. These are from numpy.distutils @@ -117,16 +129,8 @@ class NoseTester(object): 'pyrex_ext', 'swig_ext'] - def __init__(self, package=None): - ''' Test class init - - Parameters - ---------- - package : string or module - If string, gives full path to package - If None, extract calling module path - Default is None - ''' + def __init__(self, package=None, + raise_warnings=(DeprecationWarning, RuntimeWarning)): package_name = None if package is None: f = sys._getframe(1) @@ -143,12 +147,15 @@ class NoseTester(object): self.package_path = package_path - # find the package name under test; this name is used to limit coverage - # reporting (if enabled) + # Find the package name under test; this name is used to limit coverage + # reporting (if enabled). if package_name is None: package_name = get_package_name(package_path) self.package_name = package_name + # Set to empty tuple in constructor in maintenance branches. + self.raise_warnings = raise_warnings + def _test_argv(self, label, verbose, extra_argv): ''' Generate argv for nosetest command @@ -254,7 +261,7 @@ class NoseTester(object): def test(self, label='fast', verbose=1, extra_argv=None, doctests=False, coverage=False, - raisewarnings=(DeprecationWarning, RuntimeWarning)): + raise_warnings=None): """ Run tests for module using nose. @@ -280,11 +287,13 @@ class NoseTester(object): If True, report coverage of NumPy code. Default is False. (This requires the `coverage module: <http://nedbatchelder.com/code/modules/coverage.html>`_). - raisewarnings : tuple of warnings, optional + raise_warnings : sequence of warnings, optional This specifies which warnings to configure as 'raise' instead of 'warn' during the test execution. To disable this feature, - pass an empty tuple. The default is (DeprecationWarning, - RuntimeWarning). + pass an empty sequence. + The default (None) is determined by the `NoseTester` constructor. + For NumPy it is set to ``(DeprecationWarning, RuntimeWarning)`` + during development, and to ``()`` for released versions. Returns ------- @@ -331,6 +340,9 @@ class NoseTester(object): import doctest doctest.master = None + if raise_warnings is None: + raise_warnings = self.raise_warnings + # Preserve the state of the warning filters warn_ctx = numpy.testing.utils.WarningManager() warn_ctx.__enter__() @@ -339,10 +351,10 @@ class NoseTester(object): # so that running the tests is more repeatable. warnings.resetwarnings() # If deprecation warnings are not set to 'error' below, - # at least set them to 'warn' + # at least set them to 'warn'. warnings.filterwarnings('always', category=DeprecationWarning) # Force the requested warnings to raise - for warningtype in raisewarnings: + for warningtype in raise_warnings: warnings.filterwarnings('error', category=warningtype) argv, plugins = self.prepare_test_args(label, verbose, extra_argv, |