diff --git a/mitogen/utils.py b/mitogen/utils.py index 4dc4a23d..e0acf7d0 100644 --- a/mitogen/utils.py +++ b/mitogen/utils.py @@ -99,7 +99,10 @@ def run_with_router(func, *args, **kwargs): def with_router(func): def wrapper(*args, **kwargs): return run_with_router(func, *args, **kwargs) - wrapper.func_name = func.func_name + if mitogen.core.PY3: + wrapper.func_name = func.__name__ + else: + wrapper.func_name = func.func_name return wrapper diff --git a/tests/data/plain_old_module.py b/tests/data/plain_old_module.py index 67991973..49294464 100755 --- a/tests/data/plain_old_module.py +++ b/tests/data/plain_old_module.py @@ -12,7 +12,7 @@ class MyError(Exception): def get_sentinel_value(): # Some proof we're even talking to the mitogen-test Docker image - return open('/etc/sentinel').read() + return open('/etc/sentinel').read().decode() def add(x, y): diff --git a/tests/responder_test.py b/tests/responder_test.py index 86e6dd7e..dfdd67fa 100644 --- a/tests/responder_test.py +++ b/tests/responder_test.py @@ -30,7 +30,7 @@ class GoodModulesTest(testlib.RouterMixin, unittest2.TestCase): # Ensure a program composed of a single script can be imported # successfully. args = [sys.executable, testlib.data_path('self_contained_program.py')] - output = testlib.subprocess__check_output(args) + output = testlib.subprocess__check_output(args).decode() self.assertEquals(output, "['__main__', 50]\n") @@ -45,7 +45,7 @@ class BrokenModulesTest(unittest2.TestCase): router.stream_by_id = lambda n: stream msg = mitogen.core.Message( - data='non_existent_module', + data=mitogen.core.b('non_existent_module'), reply_to=50, ) msg.router = router @@ -74,7 +74,7 @@ class BrokenModulesTest(unittest2.TestCase): router.stream_by_id = lambda n: stream msg = mitogen.core.Message( - data='six_brokenpkg._six', + data=mitogen.core.b('six_brokenpkg._six'), reply_to=50, ) msg.router = router diff --git a/tests/router_test.py b/tests/router_test.py index f02746ce..68474e00 100644 --- a/tests/router_test.py +++ b/tests/router_test.py @@ -1,4 +1,3 @@ -import StringIO import logging import subprocess import time @@ -146,7 +145,7 @@ class PolicyTest(testlib.RouterMixin, testlib.TestCase): # Verify CallError received by reply_to target. e = self.assertRaises(mitogen.core.CallError, lambda: reply_target.get().unpickle()) - self.assertEquals(e[0], self.router.refused_msg) + self.assertEquals(e.args[0], self.router.refused_msg) class CrashTest(testlib.BrokerMixin, unittest2.TestCase): diff --git a/tests/service_test.py b/tests/service_test.py index 8cb18258..8e2cdac3 100644 --- a/tests/service_test.py +++ b/tests/service_test.py @@ -83,7 +83,7 @@ class PermissionTest(testlib.RouterMixin, testlib.TestCase): exc = self.assertRaises(mitogen.core.CallError, lambda: l2.call(call_service_in, l1, MyService.name(), 'privileged_op')) msg = mitogen.service.Invoker.unauthorized_msg % ( - 'privileged_op', + u'privileged_op', MyService.name(), ) self.assertTrue(msg in exc.args[0]) diff --git a/tests/ssh_test.py b/tests/ssh_test.py index 70a3f2d3..35f88cc8 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -58,7 +58,7 @@ class SshTest(testlib.DockerMixin, unittest2.TestCase): except mitogen.ssh.PasswordError: e = sys.exc_info()[1] - self.assertEqual(e[0], self.stream_class.password_required_msg) + self.assertEqual(e.args[0], self.stream_class.password_required_msg) def test_password_incorrect(self): try: @@ -70,7 +70,7 @@ class SshTest(testlib.DockerMixin, unittest2.TestCase): except mitogen.ssh.PasswordError: e = sys.exc_info()[1] - self.assertEqual(e[0], self.stream_class.password_incorrect_msg) + self.assertEqual(e.args[0], self.stream_class.password_incorrect_msg) def test_password_specified(self): context = self.docker_ssh( @@ -92,7 +92,7 @@ class SshTest(testlib.DockerMixin, unittest2.TestCase): except mitogen.ssh.PasswordError: e = sys.exc_info()[1] - self.assertEqual(e[0], self.stream_class.password_required_msg) + self.assertEqual(e.args[0], self.stream_class.password_required_msg) def test_pubkey_specified(self): context = self.docker_ssh( diff --git a/tests/testlib.py b/tests/testlib.py index 4fd2fa42..008a3dc0 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -214,7 +214,7 @@ class DockerizedSshDaemon(object): def _get_container_port(self): s = subprocess__check_output(['docker', 'port', self.container_name]) - for line in s.splitlines(): + for line in s.decode().splitlines(): dport, proto, baddr, bport = self.PORT_RE.match(line).groups() if dport == '22' and proto == 'tcp': self.port = int(bport) @@ -291,7 +291,7 @@ class DockerMixin(RouterMixin): kwargs.setdefault('hostname', self.dockerized_ssh.host) kwargs.setdefault('port', self.dockerized_ssh.port) kwargs.setdefault('check_host_keys', 'ignore') - kwargs.setdefault('ssh_debug_level', '3') + kwargs.setdefault('ssh_debug_level', 3) return self.router.ssh(**kwargs) def docker_ssh_any(self, **kwargs): diff --git a/tests/types_test.py b/tests/types_test.py index 44296656..4f80e076 100644 --- a/tests/types_test.py +++ b/tests/types_test.py @@ -1,16 +1,22 @@ -import cStringIO +try: + from io import StringIO + from io import BytesIO +except ImportError: + from StringIO import StringIO as StringIO + from StringIO import StringIO as BytesIO import unittest2 import mitogen.core +from mitogen.core import b class BlobTest(unittest2.TestCase): klass = mitogen.core.Blob def make(self): - return self.klass('x' * 128) + return self.klass(b('x') * 128) def test_repr(self): blob = self.make() @@ -18,14 +24,14 @@ class BlobTest(unittest2.TestCase): def test_decays_on_constructor(self): blob = self.make() - self.assertEquals('x'*128, mitogen.core.BytesType(blob)) + self.assertEquals(b('x')*128, mitogen.core.BytesType(blob)) def test_decays_on_write(self): blob = self.make() - io = cStringIO.StringIO() + io = BytesIO() io.write(blob) self.assertEquals(128, io.tell()) - self.assertEquals('x'*128, io.getvalue()) + self.assertEquals(b('x')*128, io.getvalue()) def test_message_roundtrip(self): blob = self.make() @@ -53,7 +59,7 @@ class SecretTest(unittest2.TestCase): def test_decays_on_write(self): secret = self.make() - io = cStringIO.StringIO() + io = StringIO() io.write(secret) self.assertEquals(8, io.tell()) self.assertEquals('password', io.getvalue()) @@ -64,8 +70,8 @@ class SecretTest(unittest2.TestCase): secret2 = msg.unpickle() self.assertEquals(type(secret), type(secret2)) self.assertEquals(repr(secret), repr(secret2)) - self.assertEquals(mitogen.core.BytesType(secret), - mitogen.core.BytesType(secret2)) + self.assertEquals(mitogen.core.b(secret), + mitogen.core.b(secret2)) if __name__ == '__main__':