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
4a4286da
Commit
4a4286da
authored
May 28, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore tests until the code is actually removed.
parent
94c91544
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
Lib/test/test_contextlib.py
Lib/test/test_contextlib.py
+122
-0
No files found.
Lib/test/test_contextlib.py
View file @
4a4286da
...
...
@@ -100,6 +100,128 @@ class ContextManagerTestCase(unittest.TestCase):
self
.
assertEqual
(
baz
.
foo
,
'bar'
)
self
.
assertEqual
(
baz
.
__doc__
,
"Whee!"
)
class
NestedTestCase
(
unittest
.
TestCase
):
# XXX This needs more work
def
test_nested
(
self
):
@
contextmanager
def
a
():
yield
1
@
contextmanager
def
b
():
yield
2
@
contextmanager
def
c
():
yield
3
with
nested
(
a
(),
b
(),
c
())
as
(
x
,
y
,
z
):
self
.
assertEqual
(
x
,
1
)
self
.
assertEqual
(
y
,
2
)
self
.
assertEqual
(
z
,
3
)
def
test_nested_cleanup
(
self
):
state
=
[]
@
contextmanager
def
a
():
state
.
append
(
1
)
try
:
yield
2
finally
:
state
.
append
(
3
)
@
contextmanager
def
b
():
state
.
append
(
4
)
try
:
yield
5
finally
:
state
.
append
(
6
)
try
:
with
nested
(
a
(),
b
())
as
(
x
,
y
):
state
.
append
(
x
)
state
.
append
(
y
)
1
/
0
except
ZeroDivisionError
:
self
.
assertEqual
(
state
,
[
1
,
4
,
2
,
5
,
6
,
3
])
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_right_exception
(
self
):
state
=
[]
@
contextmanager
def
a
():
yield
1
class
b
(
object
):
def
__enter__
(
self
):
return
2
def
__exit__
(
self
,
*
exc_info
):
try
:
raise
Exception
()
except
:
pass
try
:
with
nested
(
a
(),
b
())
as
(
x
,
y
):
1
/
0
except
ZeroDivisionError
:
self
.
assertEqual
((
x
,
y
),
(
1
,
2
))
except
Exception
:
self
.
fail
(
"Reraised wrong exception"
)
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_b_swallows
(
self
):
@
contextmanager
def
a
():
yield
@
contextmanager
def
b
():
try
:
yield
except
:
# Swallow the exception
pass
try
:
with
nested
(
a
(),
b
()):
1
/
0
except
ZeroDivisionError
:
self
.
fail
(
"Didn't swallow ZeroDivisionError"
)
def
test_nested_break
(
self
):
@
contextmanager
def
a
():
yield
state
=
0
while
True
:
state
+=
1
with
nested
(
a
(),
a
()):
break
state
+=
10
self
.
assertEqual
(
state
,
1
)
def
test_nested_continue
(
self
):
@
contextmanager
def
a
():
yield
state
=
0
while
state
<
3
:
state
+=
1
with
nested
(
a
(),
a
()):
continue
state
+=
10
self
.
assertEqual
(
state
,
3
)
def
test_nested_return
(
self
):
@
contextmanager
def
a
():
try
:
yield
except
:
pass
def
foo
():
with
nested
(
a
(),
a
()):
return
1
return
10
self
.
assertEqual
(
foo
(),
1
)
class
ClosingTestCase
(
unittest
.
TestCase
):
# XXX This needs more work
...
...
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