File: test_exceptions.py

package info (click to toggle)
python-web-poet 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 908 kB
  • sloc: python: 6,112; makefile: 19
file content (44 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest

from web_poet.exceptions import HttpError, HttpRequestError, HttpResponseError
from web_poet.page_inputs import HttpRequest, HttpResponse

URL = "https://example.com"


def test_http_error_init() -> None:
    exc = HttpError()
    assert exc.request is None
    assert exc.args

    request = HttpRequest(URL)
    exc = HttpError(request=request)
    assert exc.request == request


def test_http_request_error_init() -> None:
    exc = HttpRequestError()
    assert exc.request is None
    assert exc.args

    request = HttpRequest(URL)
    exc = HttpRequestError(request=request)
    assert exc.request == request

    response = HttpResponse(URL, b"")
    with pytest.raises(TypeError):
        HttpRequestError(request=request, response=response)  # type: ignore[call-arg]


def test_http_response_error_init() -> None:
    exc = HttpResponseError()
    assert exc.request is None
    assert exc.response is None
    assert exc.args

    request = HttpRequest(URL)
    response = HttpResponse(URL, b"")

    exc = HttpResponseError(request=request, response=response)
    assert exc.request == request
    assert exc.response == response