issue #72: second attempt WIP
parent
0e98cd4590
commit
68cf29c284
@ -0,0 +1,31 @@
|
||||
|
||||
import mitogen.core
|
||||
import mitogen.error
|
||||
|
||||
|
||||
@mitogen.main()
|
||||
def main(router):
|
||||
ve = ValueError('eep')
|
||||
ke = KeyError('eep')
|
||||
|
||||
cve = mitogen.core.CallError.from_exception(ve)
|
||||
kve = mitogen.core.CallError.from_exception(ke)
|
||||
|
||||
print([cve, type(cve)])
|
||||
print([kve])
|
||||
|
||||
mve = mitogen.error.match(ValueError)
|
||||
assert isinstance(cve, mve)
|
||||
assert not isinstance(kve, mve)
|
||||
|
||||
print
|
||||
print
|
||||
print
|
||||
print
|
||||
|
||||
|
||||
try:
|
||||
raise cve
|
||||
except mve:
|
||||
pass
|
||||
|
@ -0,0 +1,57 @@
|
||||
|
||||
import unittest2
|
||||
|
||||
import mitogen.core
|
||||
import mitogen.error
|
||||
|
||||
import testlib
|
||||
|
||||
|
||||
class MagicValueError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def func_throws_value_error(*args):
|
||||
raise ValueError(*args)
|
||||
|
||||
|
||||
def func_throws_value_error_subclass(*args):
|
||||
raise MagicValueError(*args)
|
||||
|
||||
|
||||
class MatchTest(testlib.RouterMixin, testlib.TestCase):
|
||||
def _test_no_match(self):
|
||||
context = self.router.fork()
|
||||
try:
|
||||
context.call(func_throws_value_error_subclass)
|
||||
except mitogen.error.match(ValueError):
|
||||
pass
|
||||
|
||||
def test_no_match(self):
|
||||
self.assertRaises(mitogen.core.CallError,
|
||||
lambda: self._test_no_match())
|
||||
|
||||
def test_builtin_match(self):
|
||||
context = self.router.fork()
|
||||
try:
|
||||
context.call(func_throws_value_error)
|
||||
except mitogen.error.match(ValueError):
|
||||
pass
|
||||
|
||||
def test_direct_custom_match(self):
|
||||
context = self.router.fork()
|
||||
try:
|
||||
context.call(func_throws_value_error_subclass)
|
||||
except mitogen.error.match(MagicValueError):
|
||||
pass
|
||||
|
||||
def test_indirect_match(self):
|
||||
context = self.router.fork()
|
||||
try:
|
||||
context.call(func_throws_value_error_subclass)
|
||||
except mitogen.error.match(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
Loading…
Reference in New Issue