2017-09-15 06:24:41 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
import unittest2
|
2017-09-15 06:24:41 +00:00
|
|
|
|
|
|
|
import mitogen.master
|
|
|
|
import mitogen.utils
|
|
|
|
|
|
|
|
|
2017-09-21 18:59:53 +00:00
|
|
|
def func0(router):
|
|
|
|
return router
|
2017-09-15 06:24:41 +00:00
|
|
|
|
|
|
|
|
2017-09-21 18:59:53 +00:00
|
|
|
@mitogen.utils.with_router
|
|
|
|
def func(router):
|
|
|
|
return router
|
2017-09-15 06:24:41 +00:00
|
|
|
|
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
class RunWithRouterTest(unittest2.TestCase):
|
2017-09-15 06:24:41 +00:00
|
|
|
# test_shutdown_on_exception
|
|
|
|
# test_shutdown_on_success
|
|
|
|
|
|
|
|
def test_run_with_broker(self):
|
2017-09-21 18:59:53 +00:00
|
|
|
router = mitogen.utils.run_with_router(func0)
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertIsInstance(router, mitogen.master.Router)
|
2017-09-21 18:59:53 +00:00
|
|
|
self.assertFalse(router.broker._thread.isAlive())
|
2017-09-15 06:24:41 +00:00
|
|
|
|
|
|
|
|
2017-11-12 12:42:27 +00:00
|
|
|
class WithRouterTest(unittest2.TestCase):
|
2017-09-15 06:24:41 +00:00
|
|
|
def test_with_broker(self):
|
2017-09-21 18:59:53 +00:00
|
|
|
router = func()
|
2017-11-11 23:08:08 +00:00
|
|
|
self.assertIsInstance(router, mitogen.master.Router)
|
2017-09-21 18:59:53 +00:00
|
|
|
self.assertFalse(router.broker._thread.isAlive())
|
2017-10-02 09:06:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-11-12 12:42:27 +00:00
|
|
|
unittest2.main()
|