From ec176bf1f8d83c1d1c01f6d0f4952a800dbe3230 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 26 Jun 2018 02:17:50 +0100 Subject: [PATCH] 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. --- tests/call_error_test.py | 25 ++++++++++++------------- tests/call_function_test.py | 9 +++------ tests/data/plain_old_module.py | 4 ++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/call_error_test.py b/tests/call_error_test.py index 15de01f8..b78d9f48 100644 --- a/tests/call_error_test.py +++ b/tests/call_error_test.py @@ -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]) diff --git a/tests/call_function_test.py b/tests/call_function_test.py index b9951e20..f0074258 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -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') diff --git a/tests/data/plain_old_module.py b/tests/data/plain_old_module.py index 342b25a8..67991973 100755 --- a/tests/data/plain_old_module.py +++ b/tests/data/plain_old_module.py @@ -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()