if no matching route exists.
"""
+ def __init__(self, name: str, path_params: typing.Dict[str, typing.Any]) -> None:
+ params = ", ".join(list(path_params.keys()))
+ super().__init__(f'No route exists for name "{name}" and params "{params}".')
+
class Match(Enum):
NONE = 0
expected_params = set(self.param_convertors.keys())
if name != self.name or seen_params != expected_params:
- raise NoMatchFound()
+ raise NoMatchFound(name, path_params)
path, remaining_params = replace_params(
self.path_format, self.param_convertors, path_params
expected_params = set(self.param_convertors.keys())
if name != self.name or seen_params != expected_params:
- raise NoMatchFound()
+ raise NoMatchFound(name, path_params)
path, remaining_params = replace_params(
self.path_format, self.param_convertors, path_params
)
except NoMatchFound:
pass
- raise NoMatchFound()
+ raise NoMatchFound(name, path_params)
async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
await self.app(scope, receive, send)
return URLPath(path=str(url), protocol=url.protocol, host=host)
except NoMatchFound:
pass
- raise NoMatchFound()
+ raise NoMatchFound(name, path_params)
async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
await self.app(scope, receive, send)
return route.url_path_for(name, **path_params)
except NoMatchFound:
pass
- raise NoMatchFound()
+ raise NoMatchFound(name, path_params)
async def startup(self) -> None:
"""
assert app.url_path_for("homepage") == "/"
assert app.url_path_for("user", username="tomchristie") == "/users/tomchristie"
assert app.url_path_for("websocket_endpoint") == "/ws"
- with pytest.raises(NoMatchFound):
+ with pytest.raises(
+ NoMatchFound, match='No route exists for name "broken" and params "".'
+ ):
assert app.url_path_for("broken")
+ with pytest.raises(
+ NoMatchFound, match='No route exists for name "broken" and params "key, key2".'
+ ):
+ assert app.url_path_for("broken", key="value", key2="value2")
with pytest.raises(AssertionError):
app.url_path_for("user", username="tom/christie")
with pytest.raises(AssertionError):