mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Merged revisions 78815 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78815 | florent.xicluna | 2010-03-09 21:57:01 +0200 (Tue, 09 Mar 2010) | 2 lines #7772: Fix test_py3kwarn. Now the test suite could pass with "-3" flag. ........
This commit is contained in:
parent
51449f5346
commit
f9c2f4f399
2 changed files with 30 additions and 13 deletions
|
|
@ -9,6 +9,23 @@ from contextlib import nested
|
||||||
if not sys.py3kwarning:
|
if not sys.py3kwarning:
|
||||||
raise TestSkipped('%s must be run with the -3 flag' % __name__)
|
raise TestSkipped('%s must be run with the -3 flag' % __name__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from test.test_support import __warningregistry__ as _registry
|
||||||
|
except ImportError:
|
||||||
|
def check_deprecated_module(module_name):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
past_warnings = _registry.keys()
|
||||||
|
del _registry
|
||||||
|
def check_deprecated_module(module_name):
|
||||||
|
"""Lookup the past warnings for module already loaded using
|
||||||
|
test_support.import_module(..., deprecated=True)
|
||||||
|
"""
|
||||||
|
return any(module_name in msg and ' removed' in msg
|
||||||
|
and issubclass(cls, DeprecationWarning)
|
||||||
|
and (' module' in msg or ' package' in msg)
|
||||||
|
for (msg, cls, line) in past_warnings)
|
||||||
|
|
||||||
def reset_module_registry(module):
|
def reset_module_registry(module):
|
||||||
try:
|
try:
|
||||||
registry = module.__warningregistry__
|
registry = module.__warningregistry__
|
||||||
|
|
@ -331,10 +348,9 @@ class TestStdlibRemovals(unittest.TestCase):
|
||||||
"""Make sure the specified module, when imported, raises a
|
"""Make sure the specified module, when imported, raises a
|
||||||
DeprecationWarning and specifies itself in the message."""
|
DeprecationWarning and specifies itself in the message."""
|
||||||
with nested(CleanImport(module_name), warnings.catch_warnings()):
|
with nested(CleanImport(module_name), warnings.catch_warnings()):
|
||||||
# XXX: This is not quite enough for extension modules - those
|
warnings.filterwarnings("error", ".+ (module|package) .+ removed",
|
||||||
# won't rerun their init code even with CleanImport.
|
DeprecationWarning, __name__)
|
||||||
# You can see this easily by running the whole test suite with -3
|
warnings.filterwarnings("error", ".+ removed .+ (module|package)",
|
||||||
warnings.filterwarnings("error", ".+ removed",
|
|
||||||
DeprecationWarning, __name__)
|
DeprecationWarning, __name__)
|
||||||
try:
|
try:
|
||||||
__import__(module_name, level=0)
|
__import__(module_name, level=0)
|
||||||
|
|
@ -347,7 +363,10 @@ class TestStdlibRemovals(unittest.TestCase):
|
||||||
self.fail("Non-optional module {0} raised an "
|
self.fail("Non-optional module {0} raised an "
|
||||||
"ImportError.".format(module_name))
|
"ImportError.".format(module_name))
|
||||||
else:
|
else:
|
||||||
self.fail("DeprecationWarning not raised for {0}"
|
# For extension modules, check the __warningregistry__.
|
||||||
|
# They won't rerun their init code even with CleanImport.
|
||||||
|
if not check_deprecated_module(module_name):
|
||||||
|
self.fail("DeprecationWarning not raised for {0}"
|
||||||
.format(module_name))
|
.format(module_name))
|
||||||
|
|
||||||
def test_platform_independent_removals(self):
|
def test_platform_independent_removals(self):
|
||||||
|
|
@ -407,10 +426,8 @@ class TestStdlibRemovals(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with check_warnings():
|
run_unittest(TestPy3KWarnings,
|
||||||
warnings.simplefilter("always")
|
TestStdlibRemovals)
|
||||||
run_unittest(TestPy3KWarnings,
|
|
||||||
TestStdlibRemovals)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
||||||
|
|
@ -437,10 +437,10 @@ def _filterwarnings(filters, quiet=False):
|
||||||
if registry:
|
if registry:
|
||||||
registry.clear()
|
registry.clear()
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
# Disable filters, to record all warnings. Because
|
# Set filter "always" to record all warnings. Because
|
||||||
# test_warnings swap the module, we need to look up
|
# test_warnings swap the module, we need to look up in
|
||||||
# in the sys.modules dictionary.
|
# the sys.modules dictionary.
|
||||||
sys.modules['warnings'].resetwarnings()
|
sys.modules['warnings'].simplefilter("always")
|
||||||
yield WarningsRecorder(w)
|
yield WarningsRecorder(w)
|
||||||
# Filter the recorded warnings
|
# Filter the recorded warnings
|
||||||
reraise = [warning.message for warning in w]
|
reraise = [warning.message for warning in w]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue