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
7cb672c2
Commit
7cb672c2
authored
Mar 18, 2015
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23353: improve exceptions tests for generators
parent
c48c4748
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+46
-0
No files found.
Lib/test/test_exceptions.py
View file @
7cb672c2
...
@@ -661,6 +661,52 @@ class ExceptionTests(unittest.TestCase):
...
@@ -661,6 +661,52 @@ class ExceptionTests(unittest.TestCase):
pass
pass
self
.
assertEqual
(
sys
.
exc_info
(),
(
None
,
None
,
None
))
self
.
assertEqual
(
sys
.
exc_info
(),
(
None
,
None
,
None
))
def
test_generator_leaking3
(
self
):
# See issue #23353. When gen.throw() is called, the caller's
# exception state should be save and restored.
def
g
():
try
:
yield
except
ZeroDivisionError
:
yield
sys
.
exc_info
()[
1
]
it
=
g
()
next
(
it
)
try
:
1
/
0
except
ZeroDivisionError
as
e
:
self
.
assertIs
(
sys
.
exc_info
()[
1
],
e
)
gen_exc
=
it
.
throw
(
e
)
self
.
assertIs
(
sys
.
exc_info
()[
1
],
e
)
self
.
assertIs
(
gen_exc
,
e
)
self
.
assertEqual
(
sys
.
exc_info
(),
(
None
,
None
,
None
))
def
test_generator_leaking4
(
self
):
# See issue #23353. When an exception is raised by a generator,
# the caller's exception state should still be restored.
def
g
():
try
:
1
/
0
except
ZeroDivisionError
:
yield
sys
.
exc_info
()[
0
]
raise
it
=
g
()
try
:
raise
TypeError
except
TypeError
:
# The caller's exception state (TypeError) is temporarily
# saved in the generator.
tp
=
next
(
it
)
self
.
assertIs
(
tp
,
ZeroDivisionError
)
try
:
next
(
it
)
# We can't check it immediately, but while next() returns
# with an exception, it shouldn't have restored the old
# exception state (TypeError).
except
ZeroDivisionError
as
e
:
self
.
assertIs
(
sys
.
exc_info
()[
1
],
e
)
# We used to find TypeError here.
self
.
assertEqual
(
sys
.
exc_info
(),
(
None
,
None
,
None
))
def
test_generator_doesnt_retain_old_exc
(
self
):
def
test_generator_doesnt_retain_old_exc
(
self
):
def
g
():
def
g
():
self
.
assertIsInstance
(
sys
.
exc_info
()[
1
],
RuntimeError
)
self
.
assertIsInstance
(
sys
.
exc_info
()[
1
],
RuntimeError
)
...
...
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