[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
- "pragma: nocover",
"if typing.TYPE_CHECKING:",
"@typing.overload",
"raise NotImplementedError",
await self.middleware_stack(scope, receive, send)
def on_event(self, event_type: str) -> typing.Callable: # type: ignore[type-arg]
- return self.router.on_event(event_type) # pragma: nocover
+ return self.router.on_event(event_type) # pragma: no cover
def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None:
self.router.mount(path, app=app, name=name) # pragma: no cover
try:
import multipart
from multipart.multipart import parse_options_header
-except ModuleNotFoundError: # pragma: nocover
- parse_options_header = None
- multipart = None
+except ModuleNotFoundError: # pragma: no cover
+ parse_options_header = None # type: ignore
+ multipart = None # type: ignore
+
+if typing.TYPE_CHECKING:
+ from multipart.multipart import MultipartCallbacks, QuerystringCallbacks
class FormMessage(Enum):
async def parse(self) -> FormData:
# Callbacks dictionary.
- callbacks = {
+ callbacks: QuerystringCallbacks = {
"on_field_start": self.on_field_start,
"on_field_name": self.on_field_name,
"on_field_data": self.on_field_data,
raise MultiPartException("Missing boundary in multipart.")
# Callbacks dictionary.
- callbacks = {
+ callbacks: MultipartCallbacks = {
"on_part_begin": self.on_part_begin,
"on_part_data": self.on_part_data,
"on_part_end": self.on_part_end,
try:
from multipart.multipart import parse_options_header
-except ModuleNotFoundError: # pragma: nocover
- parse_options_header = None
+except ModuleNotFoundError: # pragma: no cover
+ parse_options_header = None # type: ignore
if typing.TYPE_CHECKING:
def __eq__(self, other: typing.Any) -> bool:
return isinstance(other, Router) and self.routes == other.routes
- def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None: # pragma: nocover
+ def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None: # pragma: no cover
route = Mount(path, app=app, name=name)
self.routes.append(route)
methods: list[str] | None = None,
name: str | None = None,
include_in_schema: bool = True,
- ) -> None: # pragma: nocover
+ ) -> None: # pragma: no cover
route = Route(
path,
endpoint=endpoint,
try:
import yaml
-except ModuleNotFoundError: # pragma: nocover
+except ModuleNotFoundError: # pragma: no cover
yaml = None # type: ignore[assignment]
# adding a type ignore for mypy to let us access an attribute that may not exist
if hasattr(jinja2, "pass_context"):
pass_context = jinja2.pass_context
- else: # pragma: nocover
+ else: # pragma: no cover
pass_context = jinja2.contextfunction # type: ignore[attr-defined]
-except ModuleNotFoundError: # pragma: nocover
+except ModuleNotFoundError: # pragma: no cover
jinja2 = None # type: ignore[assignment]
with pytest.raises(RuntimeError):
client = test_client_factory(app)
with client.websocket_connect("/"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_background_task(test_client_factory: TestClientFactory) -> None:
@requires("authenticated")
def foo() -> None:
- pass # pragma: nocover
+ pass # pragma: no cover
def test_user_interface(test_client_factory: TestClientFactory) -> None:
with test_client_factory(app) as client:
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/ws"):
- pass # pragma: nocover
+ pass # pragma: no cover
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/ws", headers={"Authorization": "basic foobar"}):
- pass # pragma: nocover
+ pass # pragma: no cover
with client.websocket_connect("/ws", auth=("tomchristie", "example")) as websocket:
data = websocket.receive_json()
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/ws/decorated"):
- pass # pragma: nocover
+ pass # pragma: no cover
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/ws/decorated", headers={"Authorization": "basic foobar"}):
- pass # pragma: nocover
+ pass # pragma: no cover
with client.websocket_connect("/ws/decorated", auth=("tomchristie", "example")) as websocket:
data = websocket.receive_json()
async def task2() -> None:
await task1_finished.wait()
- await anyio.sleep(0) # pragma: nocover
- task2_finished.set() # pragma: nocover
+ await anyio.sleep(0) # pragma: no cover
+ task2_finished.set() # pragma: no cover
await run_until_first_complete((task1, {}), (task2, {}))
assert task1_finished.is_set()
def test_websockets_should_raise(client: TestClient) -> None:
with pytest.raises(RuntimeError):
with client.websocket_connect("/runtime_error"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_handled_exc_after_response(
) -> None:
async def app(scope: Scope, receive: Receive, send: Send) -> None:
if scope["path"] == "/":
- response = Response("hello", media_type="text/plain") # pragma: nocover
+ response = Response("hello", media_type="text/plain") # pragma: no cover
else:
response = RedirectResponse("/")
await response(scope, receive, send)
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/404"):
- pass # pragma: nocover
+ pass # pragma: no cover
ok = PlainTextResponse("OK")
client = test_client_factory(app)
with pytest.raises(WebSocketDisconnect):
with client.websocket_connect("/invalid"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_lifespan_async(test_client_factory: TestClientFactory) -> None:
with pytest.raises(RuntimeError):
with test_client_factory(app):
- pass # pragma: nocover
+ pass # pragma: no cover
assert startup_failed
with pytest.raises(RuntimeError):
with test_client_factory(app):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_partial_async_endpoint(test_client_factory: TestClientFactory) -> None:
with pytest.deprecated_call():
- async def startup() -> None: ... # pragma: nocover
+ async def startup() -> None: ... # pragma: no cover
router.on_event("startup")(startup)
client = test_client_factory(app)
with pytest.raises(RuntimeError):
with client.websocket_connect("/"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_receive_text_before_accept(test_client_factory: TestClientFactory) -> None:
client = test_client_factory(app)
with pytest.raises(RuntimeError):
with client.websocket_connect("/"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_receive_bytes_before_accept(test_client_factory: TestClientFactory) -> None:
client = test_client_factory(app)
with pytest.raises(RuntimeError):
with client.websocket_connect("/"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_receive_json_before_accept(test_client_factory: TestClientFactory) -> None:
client = test_client_factory(app)
with pytest.raises(RuntimeError):
with client.websocket_connect("/"):
- pass # pragma: nocover
+ pass # pragma: no cover
def test_send_wrong_message_type(test_client_factory: TestClientFactory) -> None: