Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4d42f2b4
Commit
4d42f2b4
authored
Mar 09, 2010
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#7772: Fix test_py3kwarn. Now the test suite could pass with "-3" flag.
parent
e30bc38c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
18 deletions
+33
-18
Lib/test/test_py3kwarn.py
Lib/test/test_py3kwarn.py
+29
-14
Lib/test/test_support.py
Lib/test/test_support.py
+4
-4
No files found.
Lib/test/test_py3kwarn.py
View file @
4d42f2b4
...
...
@@ -3,11 +3,26 @@ import sys
from
test.test_support
import
check_warnings
,
CleanImport
,
run_unittest
import
warnings
from
contextlib
import
nested
if
not
sys
.
py3kwarning
:
raise
unittest
.
SkipTest
(
'%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
):
try
:
registry
=
module
.
__warningregistry__
...
...
@@ -341,11 +356,10 @@ class TestStdlibRemovals(unittest.TestCase):
def
check_removal
(
self
,
module_name
,
optional
=
False
):
"""Make sure the specified module, when imported, raises a
DeprecationWarning and specifies itself in the message."""
with
nested
(
CleanImport
(
module_name
),
warnings
.
catch_warnings
()):
# XXX: This is not quite enough for extension modules - those
# won't rerun their init code even with CleanImport.
# You can see this easily by running the whole test suite with -3
warnings
.
filterwarnings
(
"error"
,
".+ removed"
,
with
CleanImport
(
module_name
),
warnings
.
catch_warnings
():
warnings
.
filterwarnings
(
"error"
,
".+ (module|package) .+ removed"
,
DeprecationWarning
,
__name__
)
warnings
.
filterwarnings
(
"error"
,
".+ removed .+ (module|package)"
,
DeprecationWarning
,
__name__
)
try
:
__import__
(
module_name
,
level
=
0
)
...
...
@@ -358,8 +372,11 @@ class TestStdlibRemovals(unittest.TestCase):
self
.
fail
(
"Non-optional module {0} raised an "
"ImportError."
.
format
(
module_name
))
else
:
self
.
fail
(
"DeprecationWarning not raised for {0}"
.
format
(
module_name
))
# 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
))
def
test_platform_independent_removals
(
self
):
# Make sure that the modules that are available on all platforms raise
...
...
@@ -390,7 +407,7 @@ class TestStdlibRemovals(unittest.TestCase):
def
test_reduce_move
(
self
):
from
operator
import
add
# reduce tests may have already triggered this warning
reset_module_registry
(
unittest
)
reset_module_registry
(
unittest
.
case
)
with
warnings
.
catch_warnings
():
warnings
.
filterwarnings
(
"error"
,
"reduce"
)
self
.
assertRaises
(
DeprecationWarning
,
reduce
,
add
,
range
(
10
))
...
...
@@ -407,10 +424,8 @@ class TestStdlibRemovals(unittest.TestCase):
def
test_main
():
with
check_warnings
():
warnings
.
simplefilter
(
"always"
)
run_unittest
(
TestPy3KWarnings
,
TestStdlibRemovals
)
run_unittest
(
TestPy3KWarnings
,
TestStdlibRemovals
)
if
__name__
==
'__main__'
:
test_main
()
Lib/test/test_support.py
View file @
4d42f2b4
...
...
@@ -519,10 +519,10 @@ def _filterwarnings(filters, quiet=False):
if
registry
:
registry
.
clear
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
#
Disable filters,
to record all warnings. Because
# test_warnings swap the module, we need to look up
#
in
the sys.modules dictionary.
sys
.
modules
[
'warnings'
].
resetwarnings
(
)
#
Set filter "always"
to record all warnings. Because
# test_warnings swap the module, we need to look up
in
# the sys.modules dictionary.
sys
.
modules
[
'warnings'
].
simplefilter
(
"always"
)
yield
WarningsRecorder
(
w
)
# Filter the recorded warnings
reraise
=
[
warning
.
message
for
warning
in
w
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment