Skip to content
Myr

Drop private imports in tests/conftest.py (#2569)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent 78d381f · Browse files · 1 file+18 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

1 file+18 added−16 removed

  • tests:+18 added−16 removed

1 file+18 added−16 removed

modified:tests/conftest.py+18 added-16 removed
15 unmodified lines
16)17from uvicorn.config import Config18from uvicorn.server import Server1920from httpx import URL20import httpx21from tests.concurrency import sleep2223if typing.TYPE_CHECKING: # pragma: no cover24 from httpx._transports.asgi import _Receive, _Send2523ENVIRONMENT_VARIABLES = {24 "SSL_CERT_FILE",25 "SSL_CERT_DIR",26 "HTTP_PROXY",
20 unmodified lines
47 os.environ.clear()48 os.environ.update(original_environ)495054_Scope = typing.Dict[str, typing.Any]51Message = typing.Dict[str, typing.Any]52Receive = typing.Callable[[], typing.Awaitable[Message]]53Send = typing.Callable[54 [typing.Dict[str, typing.Any]], typing.Coroutine[None, None, None]55]56Scope = typing.Dict[str, typing.Any]575857async def app(scope: _Scope, receive: "_Receive", send: "_Send") -> None:59async def app(scope: Scope, receive: Receive, send: Send) -> None:60 assert scope["type"] == "http"61 if scope["path"].startswith("/slow_response"):62 await slow_response(scope, receive, send)63 elif scope["path"].startswith("/status"):
11 unmodified lines
75 else:76 await hello_world(scope, receive, send)777877async def hello_world(scope: _Scope, receive: "_Receive", send: "_Send") -> None:79async def hello_world(scope: Scope, receive: Receive, send: Send) -> None:80 await send(81 {82 "type": "http.response.start",83 "status": 200,
2 unmodified lines
86 )87 await send({"type": "http.response.body", "body": b"Hello, world!"})888988async def hello_world_json(scope: _Scope, receive: "_Receive", send: "_Send") -> None:90async def hello_world_json(scope: Scope, receive: Receive, send: Send) -> None:91 await send(92 {93 "type": "http.response.start",94 "status": 200,
2 unmodified lines
97 )98 await send({"type": "http.response.body", "body": b'{"Hello": "world!"}'})9910099async def slow_response(scope: _Scope, receive: "_Receive", send: "_Send") -> None:101async def slow_response(scope: Scope, receive: Receive, send: Send) -> None:102 await send(103 {104 "type": "http.response.start",105 "status": 200,
3 unmodified lines
109 await sleep(1.0) # Allow triggering a read timeout.110 await send({"type": "http.response.body", "body": b"Hello, world!"})111112111async def status_code(scope: _Scope, receive: "_Receive", send: "_Send") -> None:113async def status_code(scope: Scope, receive: Receive, send: Send) -> None:114 status_code = int(scope["path"].replace("/status/", ""))115 await send(116 {117 "type": "http.response.start",
3 unmodified lines
121 )122 await send({"type": "http.response.body", "body": b"Hello, world!"})123124123async def echo_body(scope: _Scope, receive: "_Receive", send: "_Send") -> None:125async def echo_body(scope: Scope, receive: Receive, send: Send) -> None:126 body = b""127 more_body = True128129 while more_body:
10 unmodified lines
140 )141 await send({"type": "http.response.body", "body": body})142143142async def echo_binary(scope: _Scope, receive: "_Receive", send: "_Send") -> None:144async def echo_binary(scope: Scope, receive: Receive, send: Send) -> None:145 body = b""146 more_body = True147148 while more_body:
10 unmodified lines
159 )160 await send({"type": "http.response.body", "body": body})161162161async def echo_headers(scope: _Scope, receive: "_Receive", send: "_Send") -> None:163async def echo_headers(scope: Scope, receive: Receive, send: Send) -> None:164 body = {165 name.capitalize().decode(): value.decode()166 for name, value in scope.get("headers", [])167 }
6 unmodified lines
174 )175 await send({"type": "http.response.body", "body": json.dumps(body).encode()})176177176async def redirect_301(scope: _Scope, receive: "_Receive", send: "_Send") -> None:178async def redirect_301(scope: Scope, receive: Receive, send: Send) -> None:179 await send(180 {"type": "http.response.start", "status": 301, "headers": [[b"location", b"/"]]}181 )182 await send({"type": "http.response.body"})
45 unmodified lines
228229230class TestServer(Server):231 @property230 def url(self) -> URL:232 def url(self) -> httpx.URL:233 protocol = "https" if self.config.is_ssl else "http"232 return URL(f"{protocol}://{self.config.host}:{self.config.port}/")234 return httpx.URL(f"{protocol}://{self.config.host}:{self.config.port}/")235236 def install_signal_handlers(self) -> None:237 # Disable the default installation of handlers for signals such as SIGTERM,238 # because it can only be done in the main thread.
69 unmodified lines