48800e657f
* Remove remove_route, deprecated in 19.6. * No need for py35 compat anymore. * Rewrite asyncio.coroutines with async/await. * Remove deprecated request.raw_args. * response.text() takes str only: avoid deprecation warning in all but one test. * Remove unused import. * Revert unnecessary deprecation warning. * Remove apparently unnecessary py38 compat. * Avoid asyncio.Task.all_tasks deprecation warning. * Avoid warning on a test that tests deprecated response.text(int). * Add pytest-asyncio to tox deps. * Run the coroutine returned by AsyncioServer.close. Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
48 lines
943 B
Python
48 lines
943 B
Python
import asyncio
|
|
|
|
from queue import Queue
|
|
from threading import Event
|
|
|
|
from sanic.response import text
|
|
|
|
|
|
def test_create_task(app):
|
|
e = Event()
|
|
|
|
async def coro():
|
|
await asyncio.sleep(0.05)
|
|
e.set()
|
|
|
|
app.add_task(coro)
|
|
|
|
@app.route("/early")
|
|
def not_set(request):
|
|
return text(str(e.is_set()))
|
|
|
|
@app.route("/late")
|
|
async def set(request):
|
|
await asyncio.sleep(0.1)
|
|
return text(str(e.is_set()))
|
|
|
|
request, response = app.test_client.get("/early")
|
|
assert response.body == b"False"
|
|
|
|
request, response = app.test_client.get("/late")
|
|
assert response.body == b"True"
|
|
|
|
|
|
def test_create_task_with_app_arg(app):
|
|
q = Queue()
|
|
|
|
@app.route("/")
|
|
def not_set(request):
|
|
return "hello"
|
|
|
|
async def coro(app):
|
|
q.put(app.name)
|
|
|
|
app.add_task(coro)
|
|
|
|
request, response = app.test_client.get("/")
|
|
assert q.get() == "test_create_task_with_app_arg"
|