Skip to content

Commit

Permalink
Resolve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Jan 25, 2021
1 parent 1f0f4ef commit 76ef641
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ async def _websocket_handler(
pass
finally:
self.websocket_tasks.remove(fut)
await ws.close()
await ws.close()

# -------------------------------------------------------------------- #
# ASGI
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
collect_ignore = ["test_worker.py"]


@pytest.fixture
def caplog(caplog):
yield caplog


async def _handler(request):
"""
Dummy placeholder method used for route resolver when creating a new
Expand Down
3 changes: 1 addition & 2 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def transport(message_stack, receive, send):


@pytest.fixture
# @pytest.mark.asyncio
def protocol(transport, loop):
def protocol(transport):
return transport.get_protocol()


Expand Down
1 change: 1 addition & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_log(app):
logging.basicConfig(
format=logging_format, level=logging.DEBUG, stream=log_stream
)
logging.getLogger("asyncio").setLevel(logging.WARNING)
log = logging.getLogger()
rand_string = str(uuid.uuid4())

Expand Down
8 changes: 4 additions & 4 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,21 @@ async def handler(request, ws):
results.append(ws.subprotocol)
assert ws.subprotocol is not None

request, response = app.test_client.websocket("/ws", subprotocols=["bar"])
_, response = SanicTestClient(app).websocket("/ws", subprotocols=["bar"])
assert response.opened is True
assert results == ["bar"]

request, response = app.test_client.websocket(
_, response = SanicTestClient(app).websocket(
"/ws", subprotocols=["bar", "foo"]
)
assert response.opened is True
assert results == ["bar", "bar"]

request, response = app.test_client.websocket("/ws", subprotocols=["baz"])
_, response = SanicTestClient(app).websocket("/ws", subprotocols=["baz"])
assert response.opened is True
assert results == ["bar", "bar", None]

request, response = app.test_client.websocket("/ws")
_, response = SanicTestClient(app).websocket("/ws")
assert response.opened is True
assert results == ["bar", "bar", None, None]

Expand Down
6 changes: 4 additions & 2 deletions tests/test_url_for.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from sanic_testing.testing import SanicTestClient

from sanic.blueprints import Blueprint


Expand Down Expand Up @@ -48,14 +50,14 @@ async def test_route3(request, ws):

uri = app.url_for("test_bp.test_route")
assert uri == "/bp/route"
request, response = app.test_client.websocket(uri)
request, response = SanicTestClient(app).websocket(uri)
assert response.opened is True
assert event.is_set()

event.clear()
uri = app.url_for("test_bp.test_route2")
assert uri == "/bp/route2"
request, response = app.test_client.websocket(uri)
request, response = SanicTestClient(app).websocket(uri)
assert response.opened is True
assert event.is_set()

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ setenv =
{py36,py37,py38,py39,pyNightly}-no-ext: SANIC_NO_UJSON=1
{py36,py37,py38,py39,pyNightly}-no-ext: SANIC_NO_UVLOOP=1
deps =
sanic-testing
sanic-testing==0.1.2
coverage==5.3
pytest==5.2.1
pytest-cov
Expand Down

0 comments on commit 76ef641

Please sign in to comment.