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
Provenance
- Commit
ef06f7d- Tree
26fded0- Author
Florimond Manca <florimond.manca@protonmail.com>- Committer
GitHub <noreply@github.com>- Parent
78d381f
1 file changed+18 added−16 removed
modified:tests/conftest.py+18 added-16 removed
15 unmodified lines16 )17 from uvicorn.config import Config18 from uvicorn.server import Server19 20-from httpx import URL20+import httpx21 from tests.concurrency import sleep22 23-if typing.TYPE_CHECKING: # pragma: no cover24- from httpx._transports.asgi import _Receive, _Send25-23 ENVIRONMENT_VARIABLES = {24 "SSL_CERT_FILE",25 "SSL_CERT_DIR",26 "HTTP_PROXY",20 unmodified lines47 os.environ.clear()48 os.environ.update(original_environ)49 50 54-_Scope = typing.Dict[str, typing.Any]51+Message = typing.Dict[str, typing.Any]52+Receive = typing.Callable[[], typing.Awaitable[Message]]53+Send = typing.Callable[54+ [typing.Dict[str, typing.Any]], typing.Coroutine[None, None, None]55+]56+Scope = typing.Dict[str, typing.Any]57 58 57-async def app(scope: _Scope, receive: "_Receive", send: "_Send") -> None:59+async 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 lines75 else:76 await hello_world(scope, receive, send)77 78 77-async def hello_world(scope: _Scope, receive: "_Receive", send: "_Send") -> None:79+async def hello_world(scope: Scope, receive: Receive, send: Send) -> None:80 await send(81 {82 "type": "http.response.start",83 "status": 200,2 unmodified lines86 )87 await send({"type": "http.response.body", "body": b"Hello, world!"})88 89 88-async def hello_world_json(scope: _Scope, receive: "_Receive", send: "_Send") -> None:90+async 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 lines97 )98 await send({"type": "http.response.body", "body": b'{"Hello": "world!"}'})99 100 99-async def slow_response(scope: _Scope, receive: "_Receive", send: "_Send") -> None:101+async def slow_response(scope: Scope, receive: Receive, send: Send) -> None:102 await send(103 {104 "type": "http.response.start",105 "status": 200,3 unmodified lines109 await sleep(1.0) # Allow triggering a read timeout.110 await send({"type": "http.response.body", "body": b"Hello, world!"})111 112 111-async def status_code(scope: _Scope, receive: "_Receive", send: "_Send") -> None:113+async 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 lines121 )122 await send({"type": "http.response.body", "body": b"Hello, world!"})123 124 123-async def echo_body(scope: _Scope, receive: "_Receive", send: "_Send") -> None:125+async def echo_body(scope: Scope, receive: Receive, send: Send) -> None:126 body = b""127 more_body = True128 129 while more_body:10 unmodified lines140 )141 await send({"type": "http.response.body", "body": body})142 143 142-async def echo_binary(scope: _Scope, receive: "_Receive", send: "_Send") -> None:144+async def echo_binary(scope: Scope, receive: Receive, send: Send) -> None:145 body = b""146 more_body = True147 148 while more_body:10 unmodified lines159 )160 await send({"type": "http.response.body", "body": body})161 162 161-async def echo_headers(scope: _Scope, receive: "_Receive", send: "_Send") -> None:163+async 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 lines174 )175 await send({"type": "http.response.body", "body": json.dumps(body).encode()})176 177 176-async def redirect_301(scope: _Scope, receive: "_Receive", send: "_Send") -> None:178+async 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 lines228 229 230 class 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}/")235 236 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