Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
7b12f843
Commit
7b12f843
authored
Mar 29, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: support CallError(str) for service.py.
parent
c33bc22f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
7 deletions
+79
-7
mitogen/core.py
mitogen/core.py
+12
-7
test.sh
test.sh
+1
-0
tests/call_error_test.py
tests/call_error_test.py
+66
-0
No files found.
mitogen/core.py
View file @
7b12f843
...
...
@@ -95,13 +95,18 @@ class LatchError(Error):
class
CallError
(
Error
):
def
__init__
(
self
,
e
):
s
=
'%s.%s: %s'
%
(
type
(
e
).
__module__
,
type
(
e
).
__name__
,
e
)
tb
=
sys
.
exc_info
()[
2
]
if
tb
:
s
+=
'
\
n
'
s
+=
''
.
join
(
traceback
.
format_tb
(
tb
))
Error
.
__init__
(
self
,
s
)
def
__init__
(
self
,
fmt
=
None
,
*
args
):
if
not
isinstance
(
fmt
,
Exception
):
Error
.
__init__
(
self
,
fmt
,
*
args
)
else
:
e
=
fmt
fmt
=
'%s.%s: %s'
%
(
type
(
e
).
__module__
,
type
(
e
).
__name__
,
e
)
args
=
()
tb
=
sys
.
exc_info
()[
2
]
if
tb
:
fmt
+=
'
\
n
'
fmt
+=
''
.
join
(
traceback
.
format_tb
(
tb
))
Error
.
__init__
(
self
,
fmt
)
def
__reduce__
(
self
):
return
(
_unpickle_call_error
,
(
self
[
0
],))
...
...
test.sh
View file @
7b12f843
...
...
@@ -36,6 +36,7 @@ run_test()
}
run_test tests/ansible_helpers_test.py
run_test tests/call_error_test.py
run_test tests/call_function_test.py
run_test tests/channel_test.py
run_test tests/fakessh_test.py
...
...
tests/call_error_test.py
0 → 100644
View file @
7b12f843
import
os
import
pickle
import
unittest2
import
mitogen.core
class
ConstructorTest
(
unittest2
.
TestCase
):
klass
=
mitogen
.
core
.
CallError
def
test_string_noargs
(
self
):
e
=
self
.
klass
(
'%s%s'
)
self
.
assertEquals
(
e
[
0
],
'%s%s'
)
def
test_string_args
(
self
):
e
=
self
.
klass
(
'%s%s'
,
1
,
1
)
self
.
assertEquals
(
e
[
0
],
'11'
)
def
test_from_exc
(
self
):
ve
=
ValueError
(
'eek'
)
e
=
self
.
klass
(
ve
)
self
.
assertEquals
(
e
[
0
],
'exceptions.ValueError: eek'
)
def
test_from_exc_tb
(
self
):
try
:
raise
ValueError
(
'eek'
)
except
ValueError
,
ve
:
e
=
self
.
klass
(
ve
)
self
.
assertTrue
(
e
[
0
].
startswith
(
'exceptions.ValueError: eek'
))
self
.
assertTrue
(
'test_from_exc_tb'
in
e
[
0
])
class
PickleTest
(
unittest2
.
TestCase
):
klass
=
mitogen
.
core
.
CallError
def
test_string_noargs
(
self
):
e
=
self
.
klass
(
'%s%s'
)
e2
=
pickle
.
loads
(
pickle
.
dumps
(
e
))
self
.
assertEquals
(
e2
[
0
],
'%s%s'
)
def
test_string_args
(
self
):
e
=
self
.
klass
(
'%s%s'
,
1
,
1
)
e2
=
pickle
.
loads
(
pickle
.
dumps
(
e
))
self
.
assertEquals
(
e2
[
0
],
'11'
)
def
test_from_exc
(
self
):
ve
=
ValueError
(
'eek'
)
e
=
self
.
klass
(
ve
)
e2
=
pickle
.
loads
(
pickle
.
dumps
(
e
))
self
.
assertEquals
(
e2
[
0
],
'exceptions.ValueError: eek'
)
def
test_from_exc_tb
(
self
):
try
:
raise
ValueError
(
'eek'
)
except
ValueError
,
ve
:
e
=
self
.
klass
(
ve
)
e2
=
pickle
.
loads
(
pickle
.
dumps
(
e
))
self
.
assertTrue
(
e2
[
0
].
startswith
(
'exceptions.ValueError: eek'
))
self
.
assertTrue
(
'test_from_exc_tb'
in
e2
[
0
])
if
__name__
==
'__main__'
:
unittest2
.
main
()
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