コード例 #1
0
ファイル: test_files.py プロジェクト: jasperlin451/aiologger
    async def test_emit_does_rollover_if_should_rollover(self):
        handler = BaseAsyncRotatingFileHandler(filename=self.temp_file.name)
        handler.should_rollover = Mock(return_value=True)

        async def rollover_is_done():
            """
            sleep is needed so that the loop can schedule the other
            `do_rollover` coroutines, simulating a real `do_rollover` behaviour
            """
            await asyncio.sleep(0.1)
            handler.should_rollover.return_value = False

        handler.do_rollover = CoroutineMock(side_effect=rollover_is_done)

        await asyncio.gather(*(handler.emit(
            LogRecord(
                name=str(i),
                level=20,
                pathname="/aiologger/tests/test_logger.py",
                lineno=17,
                msg="Xablau!",
                exc_info=None,
                args=None,
            )) for i in range(42)))

        handler.do_rollover.assert_awaited_once()
コード例 #2
0
ファイル: test_files.py プロジェクト: jasperlin451/aiologger
 async def test_emit_awaits_for_handle_error_is_an_exceptions_is_raised(
         self):
     handler = BaseAsyncRotatingFileHandler(filename=self.temp_file.name)
     handler.should_rollover = Mock(return_value=False)
     exc = OSError()
     with patch("aiologger.handlers.files.AsyncFileHandler.emit",
                side_effect=exc), patch.object(
                    handler, "handle_error",
                    CoroutineMock()) as handleError:
         log_record = LogRecord(
             name="Xablau",
             level=20,
             pathname="/aiologger/tests/test_logger.py",
             lineno=17,
             msg="Xablau!",
             exc_info=None,
             args=None,
         )
         await handler.emit(log_record)
         handleError.assert_awaited_once_with(log_record, exc)