Run linter

This commit is contained in:
Adam Hopkins
2018-12-30 13:18:06 +02:00
parent 040468755c
commit 05dd3b2e9d
47 changed files with 3092 additions and 2852 deletions

View File

@@ -5,30 +5,30 @@ import pytest
from sanic.testing import HOST, PORT
AVAILABLE_LISTENERS = [
'before_server_start',
'after_server_start',
'before_server_stop',
'after_server_stop'
"before_server_start",
"after_server_start",
"before_server_stop",
"after_server_stop",
]
skipif_no_alarm = pytest.mark.skipif(
not hasattr(signal, 'SIGALRM'),
reason='SIGALRM is not implemented for this platform, we have to come '
'up with another timeout strategy to test these'
not hasattr(signal, "SIGALRM"),
reason="SIGALRM is not implemented for this platform, we have to come "
"up with another timeout strategy to test these",
)
def create_listener(listener_name, in_list):
async def _listener(app, loop):
print('DEBUG MESSAGE FOR PYTEST for {}'.format(listener_name))
print("DEBUG MESSAGE FOR PYTEST for {}".format(listener_name))
in_list.insert(0, app.name + listener_name)
return _listener
def start_stop_app(random_name_app, **run_kwargs):
def stop_on_alarm(signum, frame):
raise KeyboardInterrupt('SIGINT for sanic to stop gracefully')
raise KeyboardInterrupt("SIGINT for sanic to stop gracefully")
signal.signal(signal.SIGALRM, stop_on_alarm)
signal.alarm(1)
@@ -39,19 +39,18 @@ def start_stop_app(random_name_app, **run_kwargs):
@skipif_no_alarm
@pytest.mark.parametrize('listener_name', AVAILABLE_LISTENERS)
@pytest.mark.parametrize("listener_name", AVAILABLE_LISTENERS)
def test_single_listener(app, listener_name):
"""Test that listeners on their own work"""
output = []
# Register listener
app.listener(listener_name)(
create_listener(listener_name, output))
app.listener(listener_name)(create_listener(listener_name, output))
start_stop_app(app)
assert app.name + listener_name == output.pop()
@skipif_no_alarm
@pytest.mark.parametrize('listener_name', AVAILABLE_LISTENERS)
@pytest.mark.parametrize("listener_name", AVAILABLE_LISTENERS)
def test_register_listener(app, listener_name):
"""
Test that listeners on their own work with
@@ -77,11 +76,10 @@ def test_all_listeners(app):
async def test_trigger_before_events_create_server(app):
class MySanicDb:
pass
@app.listener('before_server_start')
@app.listener("before_server_start")
async def init_db(app, loop):
app.db = MySanicDb()