issue #477: call_function_test fixes for 2.4.

issue510
David Wilson 5 years ago
parent dd30a907ce
commit 61297c24e5

@ -76,8 +76,10 @@ itervalues = getattr(dict, 'itervalues', dict.values)
if mitogen.core.PY3:
xrange = range
closure_attr = '__closure__'
IM_SELF_ATTR = '__self__'
else:
closure_attr = 'func_closure'
IM_SELF_ATTR = 'im_self'
try:
@ -786,8 +788,9 @@ class CallSpec(object):
def _get_name(self):
bits = [self.func.__module__]
if inspect.ismethod(self.func):
bits.append(getattr(self.func.__self__, '__name__', None) or
getattr(type(self.func.__self__), '__name__', None))
im_self = getattr(self.func, IM_SELF_ATTR)
bits.append(getattr(im_self, '__name__', None) or
getattr(type(im_self), '__name__', None))
bits.append(self.func.__name__)
return u'.'.join(bits)
@ -1472,9 +1475,10 @@ class CallChain(object):
raise TypeError(self.lambda_msg)
if inspect.ismethod(fn):
if not inspect.isclass(fn.__self__):
im_self = getattr(fn, IM_SELF_ATTR)
if not inspect.isclass(im_self):
raise TypeError(self.method_msg)
klass = mitogen.core.to_text(fn.__self__.__name__)
klass = mitogen.core.to_text(im_self.__name__)
else:
klass = None

@ -6,6 +6,7 @@ import unittest2
import mitogen.core
import mitogen.parent
import mitogen.master
from mitogen.core import str_partition
import testlib
import plain_old_module
@ -50,7 +51,7 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
def setUp(self):
super(CallFunctionTest, self).setUp()
self.local = self.router.fork()
self.local = self.router.local()
def test_succeeds(self):
self.assertEqual(3, self.local.call(function_that_adds_numbers, 1, 2))
@ -65,11 +66,11 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
exc = self.assertRaises(mitogen.core.CallError,
lambda: self.local.call(function_that_fails))
s = str(exc)
etype, _, s = s.partition(': ')
self.assertEqual(etype, 'plain_old_module.MyError')
s = mitogen.core.to_text(exc)
etype, _, s = str_partition(s, u': ')
self.assertEqual(etype, u'plain_old_module.MyError')
msg, _, s = s.partition('\n')
msg, _, s = str_partition(s, u'\n')
self.assertEqual(msg, 'exception text')
# Traceback
@ -127,7 +128,7 @@ class CallChainTest(testlib.RouterMixin, testlib.TestCase):
def setUp(self):
super(CallChainTest, self).setUp()
self.local = self.router.fork()
self.local = self.router.local()
def test_subsequent_calls_produce_same_error(self):
chain = self.klass(self.local, pipelined=True)
@ -162,7 +163,7 @@ class UnsupportedCallablesTest(testlib.RouterMixin, testlib.TestCase):
def setUp(self):
super(UnsupportedCallablesTest, self).setUp()
self.local = self.router.fork()
self.local = self.router.local()
def test_closures_unsuppored(self):
a = 1

Loading…
Cancel
Save