Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than a58be59 point at it.

Add note on streaming uploads (#973)Florimond Mancabefore adoptiona58be59

lines 1–3why, one step back
1import contextlib
2import logging3import os

Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9

line 4why, one step back
4from typing import Callable, List, Optional, Tuple

Add note on streaming uploads (#973)Florimond Mancabefore adoptiona58be59

line 5why, one step back
5

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

lines 6–8why, one step back
6import httpcore
78import httpx

Add note on streaming uploads (#973)Florimond Mancabefore adoptiona58be59

lines 9–24why, one step back
9from httpx import _utils
101112@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 back
25
26

Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9

line 27why, one step back
27class MockTransport(httpcore.SyncHTTPTransport, httpcore.AsyncHTTPTransport):

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

lines 28–36why, one step back
28 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 back
37 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 back
39 request = httpx.Request(

Requests from transport API (#1293)Tom Christiebefore adoptione1f7791

lines 40–41why, one step back
40 method=method,
41 url=url,

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 42–43why, one step back
42 headers=headers,
43 stream=stream,

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

lines 44–49why, one step back
44 )
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 back
50 response.stream,

Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9

line 51why, one step back
51 response.ext,

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

lines 52–53why, one step back
52 )
53

Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9

line 54why, one step back
54 async def arequest(

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

lines 55–59why, one step back
55 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 back
60 ext: dict = None,
61 ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]:

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 62–66why, one step back
62 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 back
67 )

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 68–69why, one step back
68 await request.aread()
69 response = self.handler(request)

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

line 70why, one step back
70 return (

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 71–73why, one step back
71 response.status_code,
72 response.headers.raw,73 response.stream,

Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9

line 74why, one step back
74 response.ext,

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

line 75why, one step back
75 )