Coverage for tests/test_pool.py: 100%

1 import httpx

2 import pytest

3

4

5 def hello_world(request):

6 content = httpx.Text('Hello, world.')

7 return httpx.Response(200, content=content)

8

9

10@pytest.fixture

11 def server():

12 with httpx.serve_http(hello_world) as server:

13 yield server

14

15

16 def 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]>"

22

23

24# # with httpx.open_connection("https://www.example.com/") as conn:

25# # r = conn.request("GET", "/")

26

27# # >>> pool = httpx.ConnectionPool()

28# # >>> pool

29# # <ConnectionPool [0 active]>

30

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]>

35

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]>

40

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]>

47

48# # >>> with httpx.open_connection_pool() as pool:

49# # >>> pool.close()

50# # <ConnectionPool [0 active]>

51

52# # with httpx.open_connection("https://www.example.com/") as conn:

53# # with conn.upgrade("GET", "/feed", {"Upgrade": "WebSocket") as stream:

54# # ...

55

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# # ...

60