Skip to content

Commit

Permalink
Add test for default logger
Browse files Browse the repository at this point in the history
  • Loading branch information
0az committed Oct 9, 2018
1 parent 992f92f commit e86dbbf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
app = loop.run_until_complete(app)

# Configure if and only if in debugging mode and using the default logger
if app.debug and access_log is access_logger:
if app.debug and access_log.name == 'aiohttp.access':
if access_log.level == logging.NOTSET:
access_log.setLevel(logging.DEBUG)
if not access_log.hasHandlers():
Expand Down
25 changes: 25 additions & 0 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import contextlib
import logging
import os
import platform
import signal
Expand Down Expand Up @@ -539,3 +540,27 @@ async def make_app():
reuse_port=None)
startup_handler.assert_called_once_with(mock.ANY)
cleanup_handler.assert_called_once_with(mock.ANY)


def test_run_app_default_logger(monkeypatch, patched_loop):
logger = web.access_logger
attrs = {
'hasHandlers.return_value': False,
'level': logging.NOTSET,
'name': 'aiohttp.access',
}
mock_logger = mock.create_autospec(logger, name='mock_access_logger')
mock_logger.configure_mock(**attrs)
# with monkeypatch.context() as m:
# m.setattr(web,
# 'run_app',
# functools.partial(web.run_app,
# access_log=mock_logger))
app = web.Application(debug=True)
web.run_app(app,
print=stopper(patched_loop),
access_log=mock_logger)
mock_logger.setLevel.assert_any_call(logging.DEBUG)
mock_logger.hasHandlers.assert_called_with()
assert isinstance(mock_logger.addHandler.call_args[0][0],
logging.StreamHandler)

0 comments on commit e86dbbf

Please sign in to comment.