utils.py
This file
Path
tests/utils.py
75 lines · 2.0 KiB · Python
Last changed by
Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
History of this fileTake it
The walk stopped after 200 commits: lines older than 8c182e2 point at it.
Mark `Response.json()` as returning `Any` (#923)Florimond Mancabefore adoption8c182e2
lines 1–3why, one step back1import contextlib2import logging3import osVersion 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 4why, one step back4from typing import Callable, List, Optional, TupleMark `Response.json()` as returning `Any` (#923)Florimond Mancabefore adoption8c182e2
line 5why, one step back5Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 6–8why, one step back6import httpcore78import httpxMark `Response.json()` as returning `Any` (#923)Florimond Mancabefore adoption8c182e2
lines 9–24why, one step back9from httpx import _utils101112@contextlib.contextmanager13def override_log_level(log_level: str):14 os.environ["HTTPX_LOG_LEVEL"] = log_level1516 # Force a reload on the logging handlers17 _utils._LOGGER_INITIALIZED = False18 _utils.get_logger("httpx")1920 try:21 yield22 finally:23 # Reset the logger so we don't have verbose output in all unit tests24 logging.getLogger("httpx").handlers = []Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 25–26why, one step back2526Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 27why, one step back27class MockTransport(httpcore.SyncHTTPTransport, httpcore.AsyncHTTPTransport):Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 28–36why, one step back28 def __init__(self, handler: Callable) -> None:29 self.handler = handler3031 def request(32 self,33 method: bytes,34 url: Tuple[bytes, bytes, Optional[int], bytes],35 headers: List[Tuple[bytes, bytes]] = None,36 stream: httpcore.SyncByteStream = None,Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
lines 37–38why, one step back37 ext: dict = None,38 ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.SyncByteStream, dict]:Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 39why, one step back39 request = httpx.Request(Requests from transport API (#1293)Tom Christiebefore adoptione1f7791
lines 40–41why, one step back40 method=method,41 url=url,Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
lines 42–43why, one step back42 headers=headers,43 stream=stream,Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 44–49why, one step back44 )45 request.read()46 response = self.handler(request)47 return (48 response.status_code,49 response.headers.raw,Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
line 50why, one step back50 response.stream,Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 51why, one step back51 response.ext,Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 52–53why, one step back52 )53Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 54why, one step back54 async def arequest(Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 55–59why, one step back55 self,56 method: bytes,57 url: Tuple[bytes, bytes, Optional[int], bytes],58 headers: List[Tuple[bytes, bytes]] = None,59 stream: httpcore.AsyncByteStream = None,Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
lines 60–61why, one step back60 ext: dict = None,61 ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]:Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
lines 62–66why, one step back62 request = httpx.Request(63 method=method,64 url=url,65 headers=headers,66 stream=stream,Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 67why, one step back67 )Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
lines 68–69why, one step back68 await request.aread()69 response = self.handler(request)Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 70why, one step back70 return (Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
lines 71–73why, one step back71 response.status_code,72 response.headers.raw,73 response.stream,Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 74why, one step back74 response.ext,Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 75why, one step back75 )