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
e75f1d85
Commit
e75f1d85
authored
Sep 16, 2017
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add call_function_test, fix various exception bugs.
parent
e7ff6259
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
4 deletions
+72
-4
mitogen/core.py
mitogen/core.py
+2
-2
mitogen/master.py
mitogen/master.py
+3
-2
tests/call_function_test.py
tests/call_function_test.py
+67
-0
No files found.
mitogen/core.py
View file @
e75f1d85
...
...
@@ -51,7 +51,7 @@ class Error(Exception):
def
__init__
(
self
,
fmt
,
*
args
):
if
args
:
fmt
%=
args
Exception
.
__init__
(
self
,
fmt
%
args
)
Exception
.
__init__
(
self
,
fmt
)
class
CallError
(
Error
):
...
...
@@ -544,7 +544,7 @@ class Stream(BasicStream):
if
len
(
self
.
_input_buf
)
<
self
.
HEADER_LEN
:
return
False
msg
=
Message
()
msg
=
self
.
message_class
()
(
msg
.
dst_id
,
msg
.
src_id
,
msg
.
handle
,
msg
.
reply_to
,
msg_len
)
=
struct
.
unpack
(
self
.
HEADER_FMT
,
...
...
mitogen/master.py
View file @
e75f1d85
...
...
@@ -325,8 +325,9 @@ class Message(mitogen.core.Message):
`StreamError` if the module is not whitelisted."""
if
(
module_name
,
class_name
)
not
in
PERMITTED_CLASSES
:
raise
mitogen
.
core
.
StreamError
(
'%r attempted to unpickle %r in module %r'
,
self
.
_context
,
class_name
,
module_name
)
'attempted to unpickle %r in module %r'
,
class_name
,
module_name
)
return
getattr
(
sys
.
modules
[
module_name
],
class_name
)
...
...
tests/call_function_test.py
0 → 100644
View file @
e75f1d85
import
unittest
import
mitogen.core
import
mitogen.master
class
CrazyType
(
object
):
pass
def
function_that_fails
():
raise
ValueError
(
'exception text'
)
def
func_with_bad_return_value
():
return
CrazyType
()
def
func_returns_dead
():
return
mitogen
.
core
.
_DEAD
class
CallFunctionTest
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
super
(
CallFunctionTest
,
cls
).
setUpClass
()
cls
.
broker
=
mitogen
.
master
.
Broker
()
cls
.
router
=
mitogen
.
master
.
Router
(
cls
.
broker
)
cls
.
local
=
cls
.
router
.
local
()
@
classmethod
def
tearDownClass
(
cls
):
super
(
CallFunctionTest
,
cls
).
tearDownClass
()
cls
.
broker
.
shutdown
()
cls
.
broker
.
join
()
def
test_call_crashes
(
self
):
try
:
self
.
local
.
call
(
function_that_fails
)
assert
0
,
'call didnt fail'
except
mitogen
.
core
.
CallError
,
e
:
pass
s
=
str
(
e
)
etype
,
_
,
s
=
s
.
partition
(
': '
)
assert
etype
==
'exceptions.ValueError'
msg
,
_
,
s
=
s
.
partition
(
'
\
n
'
)
assert
msg
==
'exception text'
# Traceback
assert
len
(
s
)
>
0
def
test_bad_return_value
(
self
):
try
:
self
.
local
.
call
(
func_with_bad_return_value
)
assert
0
,
'call didnt fail'
except
mitogen
.
core
.
StreamError
,
e
:
pass
assert
e
[
0
]
==
(
"attempted to unpickle 'CrazyType' "
"in module 'call_function_test'"
)
def
test_call_returns_dead
(
self
):
assert
mitogen
.
core
.
_DEAD
==
self
.
local
.
call
(
func_returns_dead
)
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