Skip to content
Myr

test_exceptions.py

This file

Path

tests/test_exceptions.py

61 lines · 1.8 KiB · Python

Last changed by

Use ruff instead of flake8, autoflake and isort (#2648)Marcelo Trylesinskibefore adoptiondaec2bd

History of this file

Take it

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

Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5

line 1why, one step back
1import typing

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 2–7why, one step back
2
3import httpcore4import pytest56import httpx7

Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5

lines 8–9why, one step back
8if typing.TYPE_CHECKING: # pragma: no cover
9 from conftest import TestServer

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

line 10why, one step back
10

Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5

line 11why, one step back
11

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 12–16why, one step back
12def test_httpcore_all_exceptions_mapped() -> None:
13 """14 All exception classes exposed by HTTPCore are properly mapped to an HTTPX-specific15 exception class.16 """

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

lines 17–19why, one step back
17 expected_mapped_httpcore_exceptions = {
18 value.__name__19 for _, value in vars(httpcore).items()

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 20–22why, one step back
20 if isinstance(value, type)
21 and issubclass(value, Exception)22 and value is not httpcore.ConnectionNotAvailable

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

line 23why, one step back
23 }

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

line 24why, one step back
24

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

lines 25–29why, one step back
25 httpx_exceptions = {
26 value.__name__27 for _, value in vars(httpx).items()28 if isinstance(value, type) and issubclass(value, Exception)29 }

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

line 30why, one step back
30

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

line 31why, one step back
31 unmapped_exceptions = expected_mapped_httpcore_exceptions - httpx_exceptions

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

line 32why, one step back
32

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

lines 33–36why, one step back
33 if unmapped_exceptions: # pragma: no cover
34 pytest.fail(f"Unmapped httpcore exceptions: {unmapped_exceptions}")3536

Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5

line 37why, one step back
37def test_httpcore_exception_mapping(server: "TestServer") -> None:

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 38–40why, one step back
38 """
39 HTTPCore exception mapping works as expected.40 """

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

lines 41–43why, one step back
41 impossible_port = 123456
42 with pytest.raises(httpx.ConnectError):43 httpx.get(server.url.copy_with(port=impossible_port))

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

line 44why, one step back
44

Drop private imports from test_exceptions.py (#2571)Florimond Mancabefore adoption7488b15

lines 45–49why, one step back
45 with pytest.raises(httpx.ReadTimeout):
46 httpx.get(47 server.url.copy_with(path="/slow_response"),48 timeout=httpx.Timeout(5, read=0.01),49 )

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 50–55why, one step back
50
5152def test_request_attribute() -> None:53 # Exception without request attribute54 exc = httpx.ReadTimeout("Read operation timed out")55 with pytest.raises(RuntimeError):

Use ruff instead of flake8, autoflake and isort (#2648)Marcelo Trylesinskibefore adoptiondaec2bd

line 56why, one step back
56 exc.request # noqa: B018

Fix raise_for_status exception docs (#2159)Johannesbefore adoption781076c

lines 57–61why, one step back
57
58 # Exception with request attribute59 request = httpx.Request("GET", "https://www.example.com")60 exc = httpx.ReadTimeout("Read operation timed out", request=request)61 assert exc.request == request