Fix up importer_test.

pull/45/head
David Wilson 7 years ago
parent 2092568e7c
commit 0db472c97b

@ -12,13 +12,13 @@ import mitogen.core
import testlib
class ImporterMixin(object):
class ImporterMixin(testlib.RouterMixin):
modname = None
def setUp(self):
super(ImporterMixin, self).setUp()
self.context = mock.Mock()
self.importer = mitogen.core.Importer(self.context)
self.importer = mitogen.core.Importer(self.router, self.context, '')
def tearDown(self):
sys.modules.pop(self.modname, None)
@ -32,28 +32,28 @@ class LoadModuleTest(ImporterMixin, unittest.TestCase):
response = (None, path, data)
def test_no_such_module(self):
self.context.enqueue_await_reply.return_value = None
self.context.send_await.return_value = None
self.assertRaises(ImportError,
lambda: self.importer.load_module(self.modname))
def test_module_added_to_sys_modules(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertTrue(sys.modules[self.modname] is mod)
self.assertTrue(isinstance(mod, types.ModuleType))
def test_module_file_set(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertEquals(mod.__file__, 'master:' + self.path)
def test_module_loader_set(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertTrue(mod.__loader__ is self.importer)
def test_module_package_unset(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertTrue(mod.__package__ is None)
@ -65,7 +65,7 @@ class LoadSubmoduleTest(ImporterMixin, unittest.TestCase):
response = (None, path, data)
def test_module_package_unset(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertEquals(mod.__package__, 'mypkg')
@ -77,45 +77,45 @@ class LoadModulePackageTest(ImporterMixin, unittest.TestCase):
response = ([], path, data)
def test_module_file_set(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertEquals(mod.__file__, 'master:' + self.path)
def test_get_filename(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
filename = mod.__loader__.get_filename(self.modname)
self.assertEquals('master:fake_pkg/__init__.py', filename)
def test_get_source(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
source = mod.__loader__.get_source(self.modname)
self.assertEquals(source, zlib.decompress(self.data))
def test_module_loader_set(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertTrue(mod.__loader__ is self.importer)
def test_module_path_present(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertEquals(mod.__path__, [])
def test_module_package_set(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertEquals(mod.__package__, self.modname)
def test_module_data(self):
self.context.enqueue_await_reply.return_value = self.response
self.context.send_await.return_value = self.response
mod = self.importer.load_module(self.modname)
self.assertTrue(isinstance(mod.func, types.FunctionType))
self.assertEquals(mod.func.__module__, self.modname)
class EmailParseAddrSysTest(testlib.BrokerMixin, unittest.TestCase):
class EmailParseAddrSysTest(testlib.RouterMixin, unittest.TestCase):
@pytest.fixture(autouse=True)
def initdir(self, caplog):
self.caplog = caplog

Loading…
Cancel
Save