Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
non-destructive text micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
badge fixer
non-destructive text micropython
Commits
4970e9bc
Commit
4970e9bc
authored
Sep 4, 2018
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
tests/basics: Add test cases for context manager raising in enter/exit.
parent
b14c705c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/basics/with_raise.py
+44
-0
44 additions, 0 deletions
tests/basics/with_raise.py
with
44 additions
and
0 deletions
tests/basics/with_raise.py
0 → 100644
+
44
−
0
View file @
4970e9bc
# test with when context manager raises in __enter__/__exit__
class
CtxMgr
:
def
__init__
(
self
,
id
):
self
.
id
=
id
def
__enter__
(
self
):
print
(
"
__enter__
"
,
self
.
id
)
if
10
<=
self
.
id
<
20
:
raise
Exception
(
'
enter
'
,
self
.
id
)
return
self
def
__exit__
(
self
,
a
,
b
,
c
):
print
(
"
__exit__
"
,
self
.
id
,
repr
(
a
),
repr
(
b
))
if
15
<=
self
.
id
<
25
:
raise
Exception
(
'
exit
'
,
self
.
id
)
# no raising
try
:
with
CtxMgr
(
1
):
pass
except
Exception
as
e
:
print
(
e
)
# raise in enter
try
:
with
CtxMgr
(
10
):
pass
except
Exception
as
e
:
print
(
e
)
# raise in enter and exit
try
:
with
CtxMgr
(
15
):
pass
except
Exception
as
e
:
print
(
e
)
# raise in exit
try
:
with
CtxMgr
(
20
):
pass
except
Exception
as
e
:
print
(
e
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment