tests: unittest2 import behaviour appears to differ between 2/3.

In 2 the module is loaded as __main__
In 3 it has its actual name.
pull/295/head
David Wilson 7 years ago
parent 410016ff47
commit ec176bf1f8

@ -6,9 +6,8 @@ import unittest2
import mitogen.core
class MyError(Exception):
pass
import testlib
import plain_old_module
class ConstructorTest(unittest2.TestCase):
@ -23,9 +22,9 @@ class ConstructorTest(unittest2.TestCase):
self.assertEquals(e.args[0], '11')
def test_from_exc(self):
ve = MyError('eek')
ve = plain_old_module.MyError('eek')
e = self.klass(ve)
self.assertEquals(e.args[0], '__main__.MyError: eek')
self.assertEquals(e.args[0], 'plain_old_module.MyError: eek')
def test_form_base_exc(self):
ve = SystemExit('eek')
@ -34,12 +33,12 @@ class ConstructorTest(unittest2.TestCase):
def test_from_exc_tb(self):
try:
raise MyError('eek')
except MyError:
raise plain_old_module.MyError('eek')
except plain_old_module.MyError:
ve = sys.exc_info()[1]
e = self.klass(ve)
self.assertTrue(e.args[0].startswith('__main__.MyError: eek'))
self.assertTrue(e.args[0].startswith('plain_old_module.MyError: eek'))
self.assertTrue('test_from_exc_tb' in e.args[0])
@ -57,20 +56,20 @@ class PickleTest(unittest2.TestCase):
self.assertEquals(e2.args[0], '11')
def test_from_exc(self):
ve = MyError('eek')
ve = plain_old_module.MyError('eek')
e = self.klass(ve)
e2 = pickle.loads(pickle.dumps(e))
self.assertEquals(e2.args[0], '__main__.MyError: eek')
self.assertEquals(e2.args[0], 'plain_old_module.MyError: eek')
def test_from_exc_tb(self):
try:
raise MyError('eek')
except MyError:
raise plain_old_module.MyError('eek')
except plain_old_module.MyError:
ve = sys.exc_info()[1]
e = self.klass(ve)
e2 = pickle.loads(pickle.dumps(e))
self.assertTrue(e2.args[0].startswith('__main__.MyError: eek'))
self.assertTrue(e2.args[0].startswith('plain_old_module.MyError: eek'))
self.assertTrue('test_from_exc_tb' in e2.args[0])

@ -7,10 +7,7 @@ import mitogen.core
import mitogen.master
import testlib
class MyError(Exception):
pass
import plain_old_module
class CrazyType(object):
@ -22,7 +19,7 @@ def function_that_adds_numbers(x, y):
def function_that_fails():
raise MyError('exception text')
raise plain_old_module.MyError('exception text')
def func_with_bad_return_value():
@ -53,7 +50,7 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
s = str(exc)
etype, _, s = s.partition(': ')
self.assertEqual(etype, '__main__.MyError')
self.assertEqual(etype, 'plain_old_module.MyError')
msg, _, s = s.partition('\n')
self.assertEqual(msg, 'exception text')

@ -6,6 +6,10 @@ fiddlery.
import math
class MyError(Exception):
pass
def get_sentinel_value():
# Some proof we're even talking to the mitogen-test Docker image
return open('/etc/sentinel').read()

Loading…
Cancel
Save