Skip to content

Commit

Permalink
Remove inaccessible code
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Mar 14, 2021
1 parent 4917948 commit f0687bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
11 changes: 8 additions & 3 deletions sanic/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import asyncio
import logging
import logging.config
import os
import re

from asyncio import CancelledError, Protocol, ensure_future, get_event_loop
from asyncio import (
CancelledError,
Protocol,
ensure_future,
get_event_loop,
wait_for,
)
from asyncio.futures import Future
from collections import defaultdict, deque
from functools import partial
Expand Down Expand Up @@ -332,7 +337,7 @@ def event(self, event: str, timeout: Optional[Union[int, float]] = None):
signal = self.signal_router.name_index.get(event)
if not signal:
raise NotFound("Could not find signal %s" % event)
return asyncio.wait_for(signal.ctx.event.wait(), timeout=timeout)
return wait_for(signal.ctx.event.wait(), timeout=timeout)

def enable_websocket(self, enable=True):
"""Enable or disable the support for websocket.
Expand Down
13 changes: 5 additions & 8 deletions sanic/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,8 @@ def event(self, event: str, timeout: Optional[Union[int, float]] = None):
raise NotFound("Could not find signal %s" % event)
events.add(signal.ctx.event)

if events:
return asyncio.wait(
[event.wait() for event in events],
return_when=asyncio.FIRST_COMPLETED,
timeout=timeout,
)

raise NotFound("Could not find signal %s" % event)
return asyncio.wait(
[event.wait() for event in events],
return_when=asyncio.FIRST_COMPLETED,
timeout=timeout,
)
16 changes: 15 additions & 1 deletion tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sanic_routing.exceptions import NotFound

from sanic import Blueprint
from sanic.exceptions import InvalidSignal
from sanic.exceptions import InvalidSignal, SanicException


def test_add_signal(app):
Expand Down Expand Up @@ -257,3 +257,17 @@ def test_event_not_exist_on_bp(app):

with pytest.raises(NotFound, match="Could not find signal does.not.exist"):
bp.event("does.not.exist")


def test_event_on_bp_not_registered():
bp = Blueprint("bp")

@bp.signal("foo.bar.baz")
def bp_signal():
...

with pytest.raises(
SanicException,
match="<Blueprint bp> has not yet been registered to an app",
):
bp.event("foo.bar.baz")

0 comments on commit f0687bb

Please sign in to comment.