Coverage for tests/test_pool.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-05-26 22:55 +0100
« prev ^ index » next coverage.py v7.6.12, created at 2025-05-26 22:55 +0100
1import httpx
2import pytest
5def hello_world(request):
6 content = httpx.Text('Hello, world.')
7 return httpx.Response(200, content=content)
10@pytest.fixture
11def server():
12 with httpx.serve_http(hello_world) as server:
13 yield server
16def test_connection_pool(server):
17 with httpx.open_connection_pool() as pool:
18 assert repr(pool) == "<ConnectionPool [0 active]>"
19 r = pool.request("GET", server.url)
20 assert r.code == 200
21 assert repr(pool) == "<ConnectionPool [0 active, 1 idle]>"
24# # with httpx.open_connection("https://www.example.com/") as conn:
25# # r = conn.request("GET", "/")
27# # >>> pool = httpx.ConnectionPool()
28# # >>> pool
29# # <ConnectionPool [0 active]>
31# # >>> with httpx.open_connection_pool() as pool:
32# # >>> res = pool.request("GET", "https://www.example.com")
33# # >>> res, pool
34# # <Response [200 OK]>, <ConnectionPool [1 idle]>
36# # >>> with httpx.open_connection_pool() as pool:
37# # >>> with pool.stream("GET", "https://www.example.com") as res:
38# # >>> res, pool
39# # <Response [200 OK]>, <ConnectionPool [1 active]>
41# # >>> with httpx.open_connection_pool() as pool:
42# # >>> req = httpx.Request("GET", "https://www.example.com")
43# # >>> with pool.send(req) as res:
44# # >>> res.read()
45# # >>> res, pool
46# # <Response [200 OK]>, <ConnectionPool [1 idle]>
48# # >>> with httpx.open_connection_pool() as pool:
49# # >>> pool.close()
50# # <ConnectionPool [0 active]>
52# # with httpx.open_connection("https://www.example.com/") as conn:
53# # with conn.upgrade("GET", "/feed", {"Upgrade": "WebSocket") as stream:
54# # ...
56# # with httpx.open_connection("http://127.0.0.1:8080") as conn:
57# # with conn.upgrade("CONNECT", "www.encode.io:443") as stream:
58# # stream.start_tls(ctx, hostname="www.encode.io")
59# # ...