tests: another smattering of 3.x type/API fixes.

pull/295/head
David Wilson 7 years ago
parent 0422a8c263
commit 6cbf34d5fe

@ -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

@ -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):

@ -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

@ -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):

@ -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])

@ -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(

@ -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):

@ -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__':

Loading…
Cancel
Save