MCPcopy
hub / github.com/encode/starlette / __init__

Method __init__

starlette/testclient.py:381–419  ·  view source on GitHub ↗
(
        self,
        app: ASGIApp,
        base_url: str = "http://testserver",
        raise_server_exceptions: bool = True,
        root_path: str = "",
        backend: Literal["asyncio", "trio"] = "asyncio",
        backend_options: dict[str, Any] | None = None,
        cookies: httpx._types.CookieTypes | None = None,
        headers: dict[str, str] | None = None,
        follow_redirects: bool = True,
        client: tuple[str, int] = ("testclient", 50000),
    )

Source from the content-addressed store, hash-verified

379 portal: anyio.abc.BlockingPortal | None = None
380
381 def __init__(
382 self,
383 app: ASGIApp,
384 base_url: str = "http://testserver",
385 raise_server_exceptions: bool = True,
386 root_path: str = "",
387 backend: Literal["asyncio", "trio"] = "asyncio",
388 backend_options: dict[str, Any] | None = None,
389 cookies: httpx._types.CookieTypes | None = None,
390 headers: dict[str, str] | None = None,
391 follow_redirects: bool = True,
392 client: tuple[str, int] = ("testclient", 50000),
393 ) -> None:
394 self.async_backend = _AsyncBackend(backend=backend, backend_options=backend_options or {})
395 if _is_asgi3(app):
396 asgi_app = app
397 else:
398 app = cast(ASGI2App, app) # type: ignore[assignment]
399 asgi_app = _WrapASGI2(app) # type: ignore[arg-type]
400 self.app = asgi_app
401 self.app_state: dict[str, Any] = {}
402 transport = _TestClientTransport(
403 self.app,
404 portal_factory=self._portal_factory,
405 raise_server_exceptions=raise_server_exceptions,
406 root_path=root_path,
407 app_state=self.app_state,
408 client=client,
409 )
410 if headers is None:
411 headers = {}
412 headers.setdefault("user-agent", "testclient")
413 super().__init__(
414 base_url=base_url,
415 headers=headers,
416 transport=transport,
417 follow_redirects=follow_redirects,
418 cookies=cookies,
419 )
420
421 @contextlib.contextmanager
422 def _portal_factory(self) -> Generator[anyio.abc.BlockingPortal, None, None]:

Callers

nothing calls this directly

Calls 6

_AsyncBackendClass · 0.85
_is_asgi3Function · 0.85
_WrapASGI2Class · 0.85
setdefaultMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected