mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Remove test.test_support.guard_warnings_filter.
test.test_support.catch_warning is more full-featured and provides the same functionality. Since guard_warnings_filter was added in 2.6 there is no backwards-compatibility issues.
This commit is contained in:
parent
be7abbb9d9
commit
2ee4128e9b
10 changed files with 18 additions and 32 deletions
|
@ -265,12 +265,6 @@ If no match is found \var{filename} is returned.
|
||||||
This does not equal a failure since it could be the path to the file.
|
This does not equal a failure since it could be the path to the file.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{guard_warnings_filter}{}
|
|
||||||
Returns a context manager that guards the \module{warnings} module's
|
|
||||||
filter settings.
|
|
||||||
\versionadded{2.6}
|
|
||||||
\end{funcdesc}
|
|
||||||
|
|
||||||
\begin{funcdesc}{run_unittest}{*classes}
|
\begin{funcdesc}{run_unittest}{*classes}
|
||||||
Execute \class{unittest.TestCase} subclasses passed to the function.
|
Execute \class{unittest.TestCase} subclasses passed to the function.
|
||||||
The function scans the classes for methods starting with the prefix
|
The function scans the classes for methods starting with the prefix
|
||||||
|
|
|
@ -6,7 +6,7 @@ import unittest
|
||||||
import pickle, cPickle
|
import pickle, cPickle
|
||||||
|
|
||||||
from test.test_support import (TESTFN, unlink, run_unittest,
|
from test.test_support import (TESTFN, unlink, run_unittest,
|
||||||
guard_warnings_filter)
|
catch_warning)
|
||||||
from test.test_pep352 import ignore_message_warning
|
from test.test_pep352 import ignore_message_warning
|
||||||
|
|
||||||
# XXX This is not really enough, each *operation* should be tested!
|
# XXX This is not really enough, each *operation* should be tested!
|
||||||
|
@ -274,7 +274,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
ignore_message_warning()
|
ignore_message_warning()
|
||||||
for exc, args, expected in exceptionList:
|
for exc, args, expected in exceptionList:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.test_support import TESTFN, run_unittest, guard_warnings_filter
|
from test.test_support import TESTFN, run_unittest, catch_warning
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
@ -215,7 +215,7 @@ class ImportTest(unittest.TestCase):
|
||||||
self.assert_(y is test.test_support, y.__name__)
|
self.assert_(y is test.test_support, y.__name__)
|
||||||
|
|
||||||
def test_import_initless_directory_warning(self):
|
def test_import_initless_directory_warning(self):
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
# Just a random non-package directory we always expect to be
|
# Just a random non-package directory we always expect to be
|
||||||
# somewhere in sys.path...
|
# somewhere in sys.path...
|
||||||
warnings.simplefilter('error', ImportWarning)
|
warnings.simplefilter('error', ImportWarning)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
import __builtin__
|
import __builtin__
|
||||||
import exceptions
|
import exceptions
|
||||||
import warnings
|
import warnings
|
||||||
from test.test_support import run_unittest, guard_warnings_filter
|
from test.test_support import run_unittest, catch_warning
|
||||||
import os
|
import os
|
||||||
from platform import system as platform_system
|
from platform import system as platform_system
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
self.failUnless(issubclass(Exception, object))
|
self.failUnless(issubclass(Exception, object))
|
||||||
|
|
||||||
def verify_instance_interface(self, ins):
|
def verify_instance_interface(self, ins):
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
ignore_message_warning()
|
ignore_message_warning()
|
||||||
for attr in ("args", "message", "__str__", "__repr__",
|
for attr in ("args", "message", "__str__", "__repr__",
|
||||||
"__getitem__"):
|
"__getitem__"):
|
||||||
|
@ -95,7 +95,7 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
# Make sure interface works properly when given a single argument
|
# Make sure interface works properly when given a single argument
|
||||||
arg = "spam"
|
arg = "spam"
|
||||||
exc = Exception(arg)
|
exc = Exception(arg)
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
ignore_message_warning()
|
ignore_message_warning()
|
||||||
results = ([len(exc.args), 1], [exc.args[0], arg],
|
results = ([len(exc.args), 1], [exc.args[0], arg],
|
||||||
[exc.message, arg],
|
[exc.message, arg],
|
||||||
|
@ -109,7 +109,7 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
arg_count = 3
|
arg_count = 3
|
||||||
args = tuple(range(arg_count))
|
args = tuple(range(arg_count))
|
||||||
exc = Exception(*args)
|
exc = Exception(*args)
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
ignore_message_warning()
|
ignore_message_warning()
|
||||||
results = ([len(exc.args), arg_count], [exc.args, args],
|
results = ([len(exc.args), arg_count], [exc.args, args],
|
||||||
[exc.message, ''], [str(exc), str(args)],
|
[exc.message, ''], [str(exc), str(args)],
|
||||||
|
@ -121,7 +121,7 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
def test_interface_no_arg(self):
|
def test_interface_no_arg(self):
|
||||||
# Make sure that with no args that interface is correct
|
# Make sure that with no args that interface is correct
|
||||||
exc = Exception()
|
exc = Exception()
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
ignore_message_warning()
|
ignore_message_warning()
|
||||||
results = ([len(exc.args), 0], [exc.args, tuple()],
|
results = ([len(exc.args), 0], [exc.args, tuple()],
|
||||||
[exc.message, ''],
|
[exc.message, ''],
|
||||||
|
@ -132,7 +132,7 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_message_deprecation(self):
|
def test_message_deprecation(self):
|
||||||
# As of Python 2.6, BaseException.message is deprecated.
|
# As of Python 2.6, BaseException.message is deprecated.
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
warnings.resetwarnings()
|
warnings.resetwarnings()
|
||||||
warnings.filterwarnings('error')
|
warnings.filterwarnings('error')
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ class UsageTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_catch_string(self):
|
def test_catch_string(self):
|
||||||
# Catching a string should trigger a DeprecationWarning.
|
# Catching a string should trigger a DeprecationWarning.
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
warnings.resetwarnings()
|
warnings.resetwarnings()
|
||||||
warnings.filterwarnings("error")
|
warnings.filterwarnings("error")
|
||||||
str_exc = "spam"
|
str_exc = "spam"
|
||||||
|
|
|
@ -178,7 +178,7 @@ class WichmannHill_TestBasicOps(TestBasicOps):
|
||||||
|
|
||||||
def test_bigrand(self):
|
def test_bigrand(self):
|
||||||
# Verify warnings are raised when randrange is too large for random()
|
# Verify warnings are raised when randrange is too large for random()
|
||||||
with test_support.guard_warnings_filter():
|
with test_support.catch_warning():
|
||||||
warnings.filterwarnings("error", "Underlying random")
|
warnings.filterwarnings("error", "Underlying random")
|
||||||
self.assertRaises(UserWarning, self.gen.randrange, 2**60)
|
self.assertRaises(UserWarning, self.gen.randrange, 2**60)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
sys.path = ['.'] + sys.path
|
sys.path = ['.'] + sys.path
|
||||||
|
|
||||||
from test.test_support import verbose, run_unittest, guard_warnings_filter
|
from test.test_support import verbose, run_unittest, catch_warning
|
||||||
import re
|
import re
|
||||||
from re import Scanner
|
from re import Scanner
|
||||||
import sys, os, traceback
|
import sys, os, traceback
|
||||||
|
@ -416,7 +416,7 @@ class ReTests(unittest.TestCase):
|
||||||
self.pickle_test(cPickle)
|
self.pickle_test(cPickle)
|
||||||
# old pickles expect the _compile() reconstructor in sre module
|
# old pickles expect the _compile() reconstructor in sre module
|
||||||
import warnings
|
import warnings
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
warnings.filterwarnings("ignore", "The sre module is deprecated",
|
warnings.filterwarnings("ignore", "The sre module is deprecated",
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
from sre import _compile
|
from sre import _compile
|
||||||
|
|
|
@ -50,7 +50,7 @@ def any_err(func, *args):
|
||||||
|
|
||||||
def with_warning_restore(func):
|
def with_warning_restore(func):
|
||||||
def _with_warning_restore(*args, **kw):
|
def _with_warning_restore(*args, **kw):
|
||||||
with test.test_support.guard_warnings_filter():
|
with test.test_support.catch_warning():
|
||||||
# Grrr, we need this function to warn every time. Without removing
|
# Grrr, we need this function to warn every time. Without removing
|
||||||
# the warningregistry, running test_tarfile then test_struct would fail
|
# the warningregistry, running test_tarfile then test_struct would fail
|
||||||
# on 64-bit platforms.
|
# on 64-bit platforms.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""Do a minimal test of all the modules that aren't otherwise tested."""
|
"""Do a minimal test of all the modules that aren't otherwise tested."""
|
||||||
|
|
||||||
from test.test_support import guard_warnings_filter
|
from test.test_support import catch_warning
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
with guard_warnings_filter():
|
with catch_warning():
|
||||||
warnings.filterwarnings('ignore', r".*posixfile",
|
warnings.filterwarnings('ignore', r".*posixfile",
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
warnings.filterwarnings('ignore', r".*mimify", DeprecationWarning)
|
warnings.filterwarnings('ignore', r".*mimify", DeprecationWarning)
|
||||||
|
|
|
@ -271,14 +271,6 @@ def open_urlresource(url):
|
||||||
fn, _ = urllib.urlretrieve(url, filename)
|
fn, _ = urllib.urlretrieve(url, filename)
|
||||||
return open(fn)
|
return open(fn)
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def guard_warnings_filter():
|
|
||||||
"""Guard the warnings filter from being permanently changed."""
|
|
||||||
original_filters = warnings.filters[:]
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
warnings.filters = original_filters
|
|
||||||
|
|
||||||
class WarningMessage(object):
|
class WarningMessage(object):
|
||||||
"Holds the result of the latest showwarning() call"
|
"Holds the result of the latest showwarning() call"
|
||||||
|
|
|
@ -61,7 +61,7 @@ class TestModule(unittest.TestCase):
|
||||||
def test_options(self):
|
def test_options(self):
|
||||||
# Uses the private _setoption() function to test the parsing
|
# Uses the private _setoption() function to test the parsing
|
||||||
# of command-line warning arguments
|
# of command-line warning arguments
|
||||||
with test_support.guard_warnings_filter():
|
with test_support.catch_warning():
|
||||||
self.assertRaises(warnings._OptionError,
|
self.assertRaises(warnings._OptionError,
|
||||||
warnings._setoption, '1:2:3:4:5:6')
|
warnings._setoption, '1:2:3:4:5:6')
|
||||||
self.assertRaises(warnings._OptionError,
|
self.assertRaises(warnings._OptionError,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue