Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
d30c31a2
Commit
d30c31a2
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
2.9.12
parent
5389ad42
No related branches found
Branches containing commit
Tags
v2.9.12
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
satella/coding/recast_exceptions.py
+6
-0
6 additions, 0 deletions
satella/coding/recast_exceptions.py
tests/test_coding/test_rethrow.py
+9
-0
9 additions, 0 deletions
tests/test_coding/test_rethrow.py
with
15 additions
and
0 deletions
satella/coding/recast_exceptions.py
+
6
−
0
View file @
d30c31a2
...
...
@@ -30,6 +30,8 @@ def silence_excs(*exc_types: ExcType, returns=None,
>>>
def
returns_5
():
>>>
raise
KeyError
()
>>>
assert
returns_5
()
==
5
:raises ValueError: you gave both returns and returns_factory. You can only pass one of them!
"""
return
rethrow_as
(
exc_types
,
None
,
returns
=
returns
,
returns_factory
=
returns_factory
)
...
...
@@ -143,6 +145,7 @@ class rethrow_as:
:param returns: what value should the function return if this is used as a decorator
:param returns_factory: a callable that returns the value this function should return is this
is used as as decorator
:raises ValueError: you specify both returns and returns_factory
"""
__slots__
=
(
'
mapping
'
,
'
exception_preprocessor
'
,
'
returns
'
,
'
__exception_remapped
'
,
'
returns_factory
'
)
...
...
@@ -167,6 +170,9 @@ class rethrow_as:
self
.
returns
=
returns
self
.
returns_factory
=
returns_factory
if
self
.
returns
is
not
None
and
self
.
returns_factory
is
not
None
:
raise
ValueError
(
'
You can specify only one of (returns, returns_factory)
'
)
# this is threading.local because two threads may execute the same function at the
# same time, and exceptions from one function would leak to another
self
.
__exception_remapped
=
threading
.
local
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_rethrow.py
+
9
−
0
View file @
d30c31a2
...
...
@@ -13,6 +13,15 @@ class TestStuff(unittest.TestCase):
self
.
assertFalse
(
raises_exception
(
NameError
,
lambda
:
None
))
def
test_silence_excs_returns_factory
(
self
):
try
:
@silence_excs
(
KeyError
,
returns
=
5
,
returns_factory
=
5
)
def
errors
():
pass
except
ValueError
:
pass
else
:
self
.
fail
(
'
ValueError not raised
'
)
@silence_excs
(
KeyError
,
returns_factory
=
lambda
:
5
)
def
key_error
():
raise
KeyError
()
...
...
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