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
653dd7e0
Commit
653dd7e0
authored
10 months ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix rethrow
parent
68aa2471
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
satella/coding/recast_exceptions.py
+12
-2
12 additions, 2 deletions
satella/coding/recast_exceptions.py
tests/test_coding/test_rethrow.py
+9
-4
9 additions, 4 deletions
tests/test_coding/test_rethrow.py
with
22 additions
and
6 deletions
.gitignore
+
1
−
0
View file @
653dd7e0
...
...
@@ -13,6 +13,7 @@ hs_err_pid*.log
venv
coverage.xml
.coverage.*
*__pycache__*
.metadata
test
lock
...
...
This diff is collapsed.
Click to expand it.
satella/coding/recast_exceptions.py
+
12
−
2
View file @
653dd7e0
...
...
@@ -86,9 +86,15 @@ class log_exceptions:
"""
Return whether the exception has been logged
"""
if
not
isinstance
(
e
,
self
.
exc_types
):
return
False
format_dict
=
{
'
args
'
:
args
,
'
kwargs
'
:
kwargs
}
format_dict
=
{}
if
'
{args}
'
in
self
.
format_string
:
format_dict
[
'
args
'
]
=
args
if
'
{kwargs}
'
in
self
.
format_string
:
format_dict
[
'
kwargs
'
]
=
kwargs
if
self
.
locals
is
not
None
:
format_dict
.
update
(
self
.
locals
)
for
key
,
value
in
self
.
locals
.
items
():
if
'
{%s}
'
%
(
key
,)
in
self
.
format_string
:
format_dict
[
key
]
=
value
format_dict
[
'
e
'
]
=
e
self
.
logger
.
log
(
self
.
severity
,
self
.
format_string
.
format
(
**
format_dict
),
exc_info
=
e
)
...
...
@@ -217,6 +223,8 @@ class rethrow_as:
However, during to richer set of switches and capability to return a value
this is not deprecated.
.. deprecated:: v
:param exception_preprocessor: other callable/1 to use instead of repr.
Should return a str, a text description of the exception
:param returns: what value should the function return if this is used as a decorator
...
...
@@ -283,6 +291,8 @@ class rethrow_as:
raise
to
(
self
.
exception_preprocessor
(
exc_val
))
def
raises_exception
(
exc_class
:
tp
.
Union
[
ExceptionClassType
,
tp
.
Tuple
[
ExceptionClassType
,
...]],
clb
:
NoArgCallable
[
None
])
->
bool
:
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_rethrow.py
+
9
−
4
View file @
653dd7e0
import
logging
import
sys
import
unittest
from
satella.coding
import
rethrow_as
,
silence_excs
,
catch_exception
,
log_exceptions
,
\
raises_exception
,
reraise_as
raises_exception
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -46,8 +45,14 @@ class TestStuff(unittest.TestCase):
pass
get_me_normal
(
KeyError
)
@log_exceptions
(
logger
,
logging
.
CRITICAL
,
'
{args}
'
,
exc_types
=
IndexError
,
swallow_exception
=
False
)
def
dupa2
():
dupa
=
[]
dupa
[
1
]
self
.
assertRaises
(
ValueError
,
lambda
:
list
(
get_me
(
ValueError
)))
self
.
assertRaises
(
ValueError
,
lambda
:
get_me_normal
(
ValueError
))
self
.
assertRaises
(
IndexError
,
dupa2
)
def
test_log_exceptions_decorator
(
self
):
...
...
@@ -139,7 +144,7 @@ class TestStuff(unittest.TestCase):
def
test_reraise
(
self
):
try
:
with
re
raise
_as
(
ValueError
,
NameError
):
with
re
throw
_as
(
ValueError
,
NameError
):
raise
ValueError
()
except
NameError
:
return
...
...
@@ -148,7 +153,7 @@ class TestStuff(unittest.TestCase):
def
test_reraise_silencer
(
self
):
@re
raise
_as
(
ValueError
,
None
)
@re
throw
_as
(
ValueError
,
None
)
def
lol
():
raise
ValueError
()
...
...
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