Use enhanced assertRaises in call_function_test.py.

wip-fakessh-exit-status
David Wilson 7 years ago
parent 9b13a4cc61
commit 118fe01be5

@ -1,8 +1,11 @@
import logging
import unittest import unittest
import mitogen.core import mitogen.core
import mitogen.master import mitogen.master
import testlib
class CrazyType(object): class CrazyType(object):
pass pass
@ -28,7 +31,7 @@ def func_accepts_returns_context(context):
return context return context
class CallFunctionTest(testlib.RouterMixin, unittest.TestCase): class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
def setUp(self): def setUp(self):
super(CallFunctionTest, self).setUp() super(CallFunctionTest, self).setUp()
self.local = self.router.local() self.local = self.router.local()
@ -37,13 +40,10 @@ class CallFunctionTest(testlib.RouterMixin, unittest.TestCase):
assert 3 == self.local.call(function_that_adds_numbers, 1, 2) assert 3 == self.local.call(function_that_adds_numbers, 1, 2)
def test_crashes(self): def test_crashes(self):
try: exc = self.assertRaises(mitogen.core.CallError,
self.local.call(function_that_fails) lambda: self.local.call(function_that_fails))
assert 0, 'call didnt fail'
except mitogen.core.CallError, e:
pass
s = str(e) s = str(exc)
etype, _, s = s.partition(': ') etype, _, s = s.partition(': ')
assert etype == 'exceptions.ValueError' assert etype == 'exceptions.ValueError'
@ -54,13 +54,9 @@ class CallFunctionTest(testlib.RouterMixin, unittest.TestCase):
assert len(s) > 0 assert len(s) > 0
def test_bad_return_value(self): def test_bad_return_value(self):
try: exc = self.assertRaises(mitogen.core.StreamError,
self.local.call(func_with_bad_return_value) lambda: self.local.call(func_with_bad_return_value))
assert 0, 'call didnt fail' self.assertEquals(exc[0], "cannot unpickle '__main__'/'CrazyType'")
except mitogen.core.StreamError, e:
pass
self.assertEquals(e[0], "cannot unpickle '__main__'/'CrazyType'")
def test_returns_dead(self): def test_returns_dead(self):
assert mitogen.core._DEAD == self.local.call(func_returns_dead) assert mitogen.core._DEAD == self.local.call(func_returns_dead)

Loading…
Cancel
Save