Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
e7286ef2
Commit
e7286ef2
authored
Mar 29, 2014
by
Paul Sokolovsky
Browse files
tests: Add "with" statement testcases.
parent
44307d5e
Changes
4
Hide whitespace changes
Inline
Side-by-side
tests/basics/with-break.py
0 → 100644
View file @
e7286ef2
class
CtxMgr
:
def
__enter__
(
self
):
print
(
"__enter__"
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"__exit__"
,
repr
(
a
),
repr
(
b
))
for
i
in
range
(
5
):
print
(
i
)
with
CtxMgr
():
if
i
==
3
:
break
tests/basics/with-continue.py
0 → 100644
View file @
e7286ef2
class
CtxMgr
:
def
__enter__
(
self
):
print
(
"__enter__"
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"__exit__"
,
repr
(
a
),
repr
(
b
))
for
i
in
range
(
5
):
print
(
i
)
with
CtxMgr
():
if
i
==
3
:
continue
tests/basics/with-return.py
0 → 100644
View file @
e7286ef2
class
CtxMgr
:
def
__enter__
(
self
):
print
(
"__enter__"
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"__exit__"
,
repr
(
a
),
repr
(
b
))
def
foo
():
with
CtxMgr
():
return
4
print
(
foo
())
tests/basics/with1.py
0 → 100644
View file @
e7286ef2
class
CtxMgr
:
def
__enter__
(
self
):
print
(
"__enter__"
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"__exit__"
,
repr
(
a
),
repr
(
b
))
with
CtxMgr
()
as
a
:
print
(
isinstance
(
a
,
CtxMgr
))
try
:
with
CtxMgr
()
as
a
:
raise
ValueError
except
ValueError
:
print
(
"ValueError"
)
class
CtxMgr2
:
def
__enter__
(
self
):
print
(
"__enter__"
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"__exit__"
,
repr
(
a
),
repr
(
b
))
return
True
try
:
with
CtxMgr2
()
as
a
:
raise
ValueError
print
(
"No ValueError2"
)
except
ValueError
:
print
(
"ValueError2"
)
# These recursive try-finally tests are attempt to get some interpretation
# of last phrase in http://docs.python.org/3.4/library/dis.html#opcode-WITH_CLEANUP
# "If the stack represents an exception, and the function call returns a ‘true’
# value, this information is “zapped” and replaced with a single WHY_SILENCED
# to prevent END_FINALLY from re-raising the exception. (But non-local gotos
# will still be resumed.)"
print
(
"==="
)
with
CtxMgr2
()
as
a
:
try
:
try
:
raise
ValueError
print
(
"No ValueError3"
)
finally
:
print
(
"finally1"
)
finally
:
print
(
"finally2"
)
print
(
"==="
)
try
:
try
:
with
CtxMgr2
()
as
a
:
try
:
try
:
raise
ValueError
print
(
"No ValueError3"
)
finally
:
print
(
"finally1"
)
finally
:
print
(
"finally2"
)
finally
:
print
(
"finally3"
)
finally
:
print
(
"finally4"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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