add unit tests and make flake8 happy

This commit is contained in:
Yun Xu 2017-08-08 22:21:40 -07:00
parent d5d1d3b45a
commit 80f27b1db9
3 changed files with 22 additions and 1 deletions

View File

@ -641,7 +641,10 @@ class Sanic:
has_log=log_config is not None)
# Trigger before_start events
await self.trigger_events(server_settings.get('before_start', []), server_settings.get('loop'))
await self.trigger_events(
server_settings.get('before_start', []),
server_settings.get('loop')
)
return await serve(**server_settings)

View File

@ -59,3 +59,20 @@ def test_all_listeners():
start_stop_app(random_name_app)
for listener_name in AVAILABLE_LISTENERS:
assert random_name_app.name + listener_name == output.pop()
async def test_trigger_before_events_create_server():
class MySanicDb:
pass
app = Sanic("test_sanic_app")
@app.listener('before_server_start')
async def init_db(app, loop):
app.db = MySanicDb()
await app.create_server()
assert hasattr(app, "db")
assert isinstance(app.db, MySanicDb)

View File

@ -10,6 +10,7 @@ deps =
coverage
pytest
pytest-cov
pytest-sanic
pytest-sugar
aiohttp==1.3.5
chardet<=2.3.0