2018-03-29 06:08:02 +00:00
|
|
|
import os
|
|
|
|
import pickle
|
2018-04-17 16:40:45 +00:00
|
|
|
import sys
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
import mitogen.core
|
|
|
|
|
|
|
|
|
2018-04-17 16:40:45 +00:00
|
|
|
class MyError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-03-29 06:08:02 +00:00
|
|
|
class ConstructorTest(unittest2.TestCase):
|
|
|
|
klass = mitogen.core.CallError
|
|
|
|
|
|
|
|
def test_string_noargs(self):
|
|
|
|
e = self.klass('%s%s')
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e.args[0], '%s%s')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
def test_string_args(self):
|
|
|
|
e = self.klass('%s%s', 1, 1)
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e.args[0], '11')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
def test_from_exc(self):
|
2018-04-17 16:40:45 +00:00
|
|
|
ve = MyError('eek')
|
2018-03-29 06:08:02 +00:00
|
|
|
e = self.klass(ve)
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e.args[0], '__main__.MyError: eek')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
2018-05-11 13:56:20 +00:00
|
|
|
def test_form_base_exc(self):
|
|
|
|
ve = SystemExit('eek')
|
|
|
|
e = self.klass(ve)
|
|
|
|
self.assertEquals(e[0], 'exceptions.SystemExit: eek')
|
|
|
|
|
2018-03-29 06:08:02 +00:00
|
|
|
def test_from_exc_tb(self):
|
|
|
|
try:
|
2018-04-17 16:40:45 +00:00
|
|
|
raise MyError('eek')
|
|
|
|
except MyError:
|
|
|
|
ve = sys.exc_info()[1]
|
2018-03-29 06:08:02 +00:00
|
|
|
e = self.klass(ve)
|
|
|
|
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertTrue(e.args[0].startswith('__main__.MyError: eek'))
|
|
|
|
self.assertTrue('test_from_exc_tb' in e.args[0])
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PickleTest(unittest2.TestCase):
|
|
|
|
klass = mitogen.core.CallError
|
|
|
|
|
|
|
|
def test_string_noargs(self):
|
|
|
|
e = self.klass('%s%s')
|
|
|
|
e2 = pickle.loads(pickle.dumps(e))
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e2.args[0], '%s%s')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
def test_string_args(self):
|
|
|
|
e = self.klass('%s%s', 1, 1)
|
|
|
|
e2 = pickle.loads(pickle.dumps(e))
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e2.args[0], '11')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
def test_from_exc(self):
|
2018-04-17 16:40:45 +00:00
|
|
|
ve = MyError('eek')
|
2018-03-29 06:08:02 +00:00
|
|
|
e = self.klass(ve)
|
|
|
|
e2 = pickle.loads(pickle.dumps(e))
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertEquals(e2.args[0], '__main__.MyError: eek')
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
def test_from_exc_tb(self):
|
|
|
|
try:
|
2018-04-17 16:40:45 +00:00
|
|
|
raise MyError('eek')
|
|
|
|
except MyError:
|
|
|
|
ve = sys.exc_info()[1]
|
2018-03-29 06:08:02 +00:00
|
|
|
e = self.klass(ve)
|
|
|
|
|
|
|
|
e2 = pickle.loads(pickle.dumps(e))
|
2018-04-17 16:40:45 +00:00
|
|
|
self.assertTrue(e2.args[0].startswith('__main__.MyError: eek'))
|
|
|
|
self.assertTrue('test_from_exc_tb' in e2.args[0])
|
2018-03-29 06:08:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|