Beispiel #1
0
 def setUp(self):
     self.coro = CoroutineMock()
     self.coro.return_value = None
     self.started_coro = self.coro()
     self.logger = unittest.mock.Mock()
     self.cm = utils.background_task(
         self.started_coro,
         self.logger,
     )
Beispiel #2
0
 def setUp(self):
     self.coro = CoroutineMock()
     self.coro.return_value = None
     self.started_coro = self.coro()
     self.logger = unittest.mock.Mock()
     self.cm = utils.background_task(
         self.started_coro,
         self.logger,
     )
    def test_logs_debug_when_coroutine_cancelled(self):
        async def too_long():
            await asyncio.sleep(10)

        self.cm = utils.background_task(too_long(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.debug.assert_called_with(
            "background task terminated by CM exit: %r",
            unittest.mock.ANY,
        )
Beispiel #4
0
    def test_logs_debug_when_coroutine_cancelled(self):
        @asyncio.coroutine
        def too_long():
            yield from asyncio.sleep(10)

        self.cm = utils.background_task(too_long(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.debug.assert_called_with(
            "background task terminated by CM exit: %r",
            unittest.mock.ANY,
        )
    def test_logs_info_when_coroutine_returns_value(self):
        async def something():
            return unittest.mock.sentinel.result

        self.cm = utils.background_task(something(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.info.assert_called_with(
            "background task (%r) returned a value: %r",
            unittest.mock.ANY,
            unittest.mock.sentinel.result,
        )
    def test_logs_error_when_coroutine_raises(self):
        async def failing():
            raise ValueError()

        self.cm = utils.background_task(failing(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.error.assert_called_with(
            "background task failed: %r",
            unittest.mock.ANY,
            exc_info=True,
        )
Beispiel #7
0
    def test_logs_info_when_coroutine_returns_value(self):
        @asyncio.coroutine
        def something():
            return unittest.mock.sentinel.result

        self.cm = utils.background_task(something(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.info.assert_called_with(
            "background task (%r) returned a value: %r",
            unittest.mock.ANY,
            unittest.mock.sentinel.result,
        )
Beispiel #8
0
    def test_logs_error_when_coroutine_raises(self):
        @asyncio.coroutine
        def failing():
            raise ValueError()

        self.cm = utils.background_task(failing(), self.logger)
        run_coroutine(self._long_wrapper())

        self.logger.error.assert_called_with(
            "background task failed: %r",
            unittest.mock.ANY,
            exc_info=True,
        )