tests: 'fix' responder test.

Needs a complete rewrite, but this will do for now.
pull/193/head
David Wilson 7 years ago
parent f9eb66e76e
commit ce6fb05d87

@ -646,7 +646,7 @@ class ModuleResponder(object):
except Exception: except Exception:
LOG.debug('While importing %r', fullname, exc_info=True) LOG.debug('While importing %r', fullname, exc_info=True)
msg.reply((fullname, None, None, None, []), msg.reply((fullname, None, None, None, ()),
handle=mitogen.core.LOAD_MODULE) handle=mitogen.core.LOAD_MODULE)

@ -2,17 +2,14 @@
I am a self-contained program! I am a self-contained program!
""" """
import mitogen.master import mitogen
def repr_stuff(): def repr_stuff():
return repr([__name__, 50]) return repr([__name__, 50])
@mitogen.main()
def main(router): def main(router):
context = router.local() context = router.local()
print context.call(repr_stuff) print context.call(repr_stuff)
if __name__ == '__main__' and mitogen.is_master:
import mitogen.utils
mitogen.utils.run_with_router(main)

@ -39,20 +39,26 @@ class BrokenModulesTest(unittest2.TestCase):
# Ensure we don't crash in the case of a module legitimately being # Ensure we don't crash in the case of a module legitimately being
# unavailable. Should never happen in the real world. # unavailable. Should never happen in the real world.
stream = mock.Mock()
stream.sent_modules = set()
router = mock.Mock() router = mock.Mock()
responder = mitogen.master.ModuleResponder(router) router.stream_by_id = lambda n: stream
responder._on_get_module(
mitogen.core.Message( msg = mitogen.core.Message(
data='non_existent_module', data='non_existent_module',
reply_to=50, reply_to=50,
) )
) msg.router = router
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(msg)
self.assertEquals(1, len(router.route.mock_calls)) self.assertEquals(1, len(router.route.mock_calls))
call = router.route.mock_calls[0] call = router.route.mock_calls[0]
msg, = call[1] msg, = call[1]
self.assertEquals(50, msg.handle) self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle)
self.assertIsNone(msg.unpickle()) self.assertEquals(('non_existent_module', None, None, None, ()),
msg.unpickle())
def test_ansible_six_messed_up_path(self): def test_ansible_six_messed_up_path(self):
# The copy of six.py shipped with Ansible appears in a package whose # The copy of six.py shipped with Ansible appears in a package whose
@ -62,19 +68,24 @@ class BrokenModulesTest(unittest2.TestCase):
# cause an attempt to request ansible.compat.six._six from the master. # cause an attempt to request ansible.compat.six._six from the master.
import six_brokenpkg import six_brokenpkg
stream = mock.Mock()
stream.sent_modules = set()
router = mock.Mock() router = mock.Mock()
responder = mitogen.master.ModuleResponder(router) router.stream_by_id = lambda n: stream
responder._on_get_module(
mitogen.core.Message( msg = mitogen.core.Message(
data='six_brokenpkg._six', data='six_brokenpkg._six',
reply_to=50, reply_to=50,
) )
) msg.router = router
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(msg)
self.assertEquals(1, len(router.route.mock_calls)) self.assertEquals(1, len(router.route.mock_calls))
call = router.route.mock_calls[0] call = router.route.mock_calls[0]
msg, = call[1] msg, = call[1]
self.assertEquals(50, msg.handle) self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle)
self.assertIsInstance(msg.unpickle(), tuple) self.assertIsInstance(msg.unpickle(), tuple)

Loading…
Cancel
Save