File: test_http_response.mypy-testing

package info (click to toggle)
python-scrapy 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,664 kB
  • sloc: python: 52,028; xml: 199; makefile: 25; sh: 7
file content (59 lines) | stat: -rw-r--r-- 2,164 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Any, Dict

import pytest

from scrapy.http import HtmlResponse, Response, TextResponse


@pytest.mark.mypy_testing
def mypy_test_headers():
    Response("data:,", headers=1)  # E: Argument "headers" to "Response" has incompatible type "int"; expected "Union[Mapping[str, Any], Iterable[tuple[str, Any]], None]"
    Response("data:,", headers=None)
    Response("data:,", headers={})
    Response("data:,", headers=[])
    Response("data:,", headers={"foo": "bar"})
    Response("data:,", headers={b"foo": "bar"})
    Response("data:,", headers={"foo": b"bar"})
    Response("data:,", headers=[("foo", "bar")])
    Response("data:,", headers=[(b"foo", "bar")])
    Response("data:,", headers=[("foo", b"bar")])


@pytest.mark.mypy_testing
def mypy_test_copy():
    resp = Response("data:,")
    reveal_type(resp)  # R: scrapy.http.response.Response
    resp_copy = resp.copy()
    reveal_type(resp_copy)  # R: scrapy.http.response.Response


@pytest.mark.mypy_testing
def mypy_test_copy_subclass():
    resp = HtmlResponse("data:,")
    reveal_type(resp)  # R: scrapy.http.response.html.HtmlResponse
    resp_copy = resp.copy()
    reveal_type(resp_copy)  # R: scrapy.http.response.html.HtmlResponse


@pytest.mark.mypy_testing
def mypy_test_replace():
    resp = Response("data:,")
    reveal_type(resp)  # R: scrapy.http.response.Response
    resp_copy = resp.replace(body=b"a")
    reveal_type(resp_copy)  # R: scrapy.http.response.Response
    kwargs: Dict[str, Any] = {}
    resp_copy2 = resp.replace(body=b"a", **kwargs)
    reveal_type(resp_copy2)  # R: Any


@pytest.mark.mypy_testing
def mypy_test_replace_subclass():
    resp = HtmlResponse("data:,")
    reveal_type(resp)  # R: scrapy.http.response.html.HtmlResponse
    resp_copy = resp.replace(body=b"a")
    reveal_type(resp_copy)  # R: scrapy.http.response.html.HtmlResponse
    resp_copy2 = resp.replace(body=b"a", cls=TextResponse)
    reveal_type(resp_copy2)  # R: scrapy.http.response.text.TextResponse
    kwargs: Dict[str, Any] = {}
    resp_copy3 = resp.replace(body=b"a", cls=TextResponse, **kwargs)
    reveal_type(resp_copy3)  # R: scrapy.http.response.text.TextResponse