issue #477: call_function_test fixes for 2.4.

issue510
David Wilson 6 years ago
parent dd30a907ce
commit 61297c24e5

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

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

Loading…
Cancel
Save