Merge pull request #350 from jesteria/issue313

Python 3 support for classmethod call targets
pull/353/head
dw 6 years ago committed by GitHub
commit 18685da0d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,7 +47,6 @@ import termios
import textwrap
import threading
import time
import types
import zlib
# Absolute imports for <2.5.
@ -490,9 +489,8 @@ def upgrade_router(econtext):
def make_call_msg(fn, *args, **kwargs):
if isinstance(fn, types.MethodType) and \
isinstance(fn.im_self, (type, types.ClassType)):
klass = mitogen.core.to_text(fn.im_self.__name__)
if inspect.ismethod(fn) and inspect.isclass(fn.__self__):
klass = mitogen.core.to_text(fn.__self__.__name__)
else:
klass = None

@ -36,7 +36,17 @@ def func_accepts_returns_sender(sender):
return sender
class TargetClass:
offset = 100
@classmethod
def add_numbers_with_offset(cls, x, y):
return cls.offset + x + y
class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
def setUp(self):
super(CallFunctionTest, self).setUp()
self.local = self.router.fork()
@ -44,6 +54,12 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
def test_succeeds(self):
self.assertEqual(3, self.local.call(function_that_adds_numbers, 1, 2))
def test_succeeds_class_method(self):
self.assertEqual(
self.local.call(TargetClass.add_numbers_with_offset, 1, 2),
103,
)
def test_crashes(self):
exc = self.assertRaises(mitogen.core.CallError,
lambda: self.local.call(function_that_fails))

Loading…
Cancel
Save