From 61297c24e584507b26d6a8399283652a1e06a2d3 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 23 Jan 2019 12:44:08 +0000 Subject: [PATCH] issue #477: call_function_test fixes for 2.4. --- mitogen/parent.py | 12 ++++++++---- tests/call_function_test.py | 15 ++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 92be06ef..7b79155e 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -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 diff --git a/tests/call_function_test.py b/tests/call_function_test.py index 06d74a8e..9e821b27 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -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