-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add stubs for httpretty #16048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add stubs for httpretty #16048
Changes from all commits
2eb305f
e8a8d37
fc10a19
4a6c7fe
323320f
28ef155
2e411bf
912e1bb
2006c89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from typing_extensions import assert_type | ||
|
|
||
| import httpretty | ||
|
|
||
|
|
||
| @httpretty.activate(allow_net_connect=False) | ||
| def decorated() -> int: | ||
| httpretty.register_uri(httpretty.GET, "https://example.com/", body="ok", status=200, content_type="text/plain") | ||
| assert_type(httpretty.last_request(), httpretty.HTTPrettyRequest | httpretty.HTTPrettyRequestEmpty) | ||
| assert_type(httpretty.latest_requests(), list[httpretty.HTTPrettyRequest]) | ||
| assert_type(httpretty.has_request(), bool) | ||
| return 1 | ||
|
|
||
|
|
||
| with httpretty.enabled(allow_net_connect=False): | ||
| response = httpretty.Response("ok", status=201) | ||
| assert_type(response, httpretty.Entry) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version = "1.1.4" | ||
| upstream-repository = "https://github.com/gabrielfalcao/HTTPretty" | ||
| partial-stub = true | ||
|
|
||
| [tool.stubtest] | ||
| ignore-missing-stub = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from .core import ( | ||
| EmptyRequestHeaders as EmptyRequestHeaders, | ||
| Entry as Entry, | ||
| HTTPrettyRequest as HTTPrettyRequest, | ||
| HTTPrettyRequestEmpty as HTTPrettyRequestEmpty, | ||
| URIInfo as URIInfo, | ||
| URIMatcher as URIMatcher, | ||
| get_default_thread_timeout as get_default_thread_timeout, | ||
| httprettified as httprettified, | ||
| httprettized as httprettized, | ||
| httpretty as httpretty, | ||
| set_default_thread_timeout as set_default_thread_timeout, | ||
| ) | ||
| from .errors import HTTPrettyError as HTTPrettyError, UnmockedError as UnmockedError | ||
|
|
||
| __version__: str | ||
| HTTPretty = httpretty | ||
| activate = httprettified | ||
| enabled = httprettized | ||
| enable = httpretty.enable | ||
| register_uri = httpretty.register_uri | ||
| disable = httpretty.disable | ||
| is_enabled = httpretty.is_enabled | ||
| reset = httpretty.reset | ||
| Response = httpretty.Response | ||
| GET: Final = "GET" | ||
| PUT: Final = "PUT" | ||
| POST: Final = "POST" | ||
| DELETE: Final = "DELETE" | ||
| HEAD: Final = "HEAD" | ||
| PATCH: Final = "PATCH" | ||
| OPTIONS: Final = "OPTIONS" | ||
| CONNECT: Final = "CONNECT" | ||
|
|
||
| def last_request() -> HTTPrettyRequest | HTTPrettyRequestEmpty: ... | ||
| def latest_requests() -> list[HTTPrettyRequest]: ... | ||
| def has_request() -> bool: ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from typing import TypeVar | ||
|
|
||
| _T = TypeVar("_T") | ||
|
|
||
| class BaseClass: ... | ||
|
|
||
| def encode_obj(in_obj: _T) -> _T: ... |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,203 @@ | ||||||||
| import re | ||||||||
| from collections.abc import Callable, Iterable, Mapping | ||||||||
| from contextlib import AbstractContextManager | ||||||||
| from http.client import HTTPMessage | ||||||||
| from types import TracebackType | ||||||||
| from typing import Any, Literal, TypeAlias, overload | ||||||||
| from typing_extensions import ParamSpec | ||||||||
|
|
||||||||
| from .http import HttpBaseClass | ||||||||
|
|
||||||||
| _P = ParamSpec("_P") | ||||||||
| _HTTPMethod: TypeAlias = Literal["GET", "PUT", "POST", "DELETE", "HEAD", "PATCH", "OPTIONS", "CONNECT"] | ||||||||
| _URI: TypeAlias = str | re.Pattern[str] | ||||||||
| _HeaderValue: TypeAlias = str | int | bool | None | ||||||||
| _Headers: TypeAlias = Mapping[str, _HeaderValue] | ||||||||
| _Body: TypeAlias = str | bytes | ||||||||
| _ResponseBody: TypeAlias = _Body | Callable[[HTTPrettyRequest, str, _Headers], tuple[int, _Headers, _Body]] | ||||||||
|
|
||||||||
| def set_default_thread_timeout(timeout: float) -> None: ... | ||||||||
| def get_default_thread_timeout() -> float: ... | ||||||||
|
|
||||||||
| class HTTPrettyRequest(HttpBaseClass): | ||||||||
| headers: HTTPMessage | ||||||||
| raw_headers: str | ||||||||
| path: str | ||||||||
| querystring: dict[str, list[str]] | ||||||||
| parsed_body: Any # It can be any object after parsing raw (str) body | ||||||||
| created_at: float | ||||||||
| def __init__( | ||||||||
| self, headers: str | bytes, body: _Body = "", sock: object | None = None, path_encoding: str = "iso-8859-1" | ||||||||
| ) -> None: ... | ||||||||
| @property | ||||||||
| def method(self) -> str: ... | ||||||||
| @property | ||||||||
| def protocol(self) -> str: ... | ||||||||
|
|
||||||||
| @property | ||||||||
| def body(self) -> str: ... | ||||||||
| @body.setter | ||||||||
| def body(self, value: _Body) -> None: ... | ||||||||
|
|
||||||||
| @property | ||||||||
| def url(self) -> str: ... | ||||||||
| @property | ||||||||
| def host(self) -> str: ... | ||||||||
| def parse_querystring(self, qs: str) -> dict[str, list[str]]: ... | ||||||||
| def parse_request_body(self, body: str) -> Any: ... | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some explanatory comments:
Suggested change
|
||||||||
|
|
||||||||
| class EmptyRequestHeaders(dict[str, str]): ... | ||||||||
|
|
||||||||
| class HTTPrettyRequestEmpty: | ||||||||
| method: str | None | ||||||||
| url: str | None | ||||||||
| body: str | ||||||||
| headers: EmptyRequestHeaders | ||||||||
|
|
||||||||
| class Entry(HttpBaseClass): | ||||||||
| method: _HTTPMethod | ||||||||
| uri: str | ||||||||
| request: HTTPrettyRequest | ||||||||
| body: _Body | ||||||||
| status: int | ||||||||
| streaming: bool | ||||||||
| adding_headers: dict[str, str] | ||||||||
| forcing_headers: dict[str, str] | ||||||||
| def __init__( | ||||||||
| self, | ||||||||
| method: str, | ||||||||
| uri: str, | ||||||||
| body: _ResponseBody, | ||||||||
| adding_headers: _Headers | None = None, | ||||||||
| forcing_headers: _Headers | None = None, | ||||||||
| status: int = 200, | ||||||||
| streaming: bool = False, | ||||||||
| **headers: str, | ||||||||
| ) -> None: ... | ||||||||
| def validate(self) -> None: ... | ||||||||
| def normalize_headers(self, headers: _Headers) -> dict[str, str]: ... | ||||||||
| def fill_filekind(self, fk: _WritableFileobj) -> None: ... | ||||||||
|
|
||||||||
| class URIInfo(HttpBaseClass): | ||||||||
| default_str_attrs: tuple[str, ...] | ||||||||
| username: str | ||||||||
| password: str | ||||||||
| hostname: str | ||||||||
| port: int | ||||||||
| path: str | ||||||||
| query: str | ||||||||
| scheme: str | ||||||||
| fragment: str | ||||||||
| last_request: HTTPrettyRequest | None | ||||||||
| def __init__( | ||||||||
| self, | ||||||||
| username: str = "", | ||||||||
| password: str = "", | ||||||||
| hostname: str = "", | ||||||||
| port: int = 80, | ||||||||
| path: str = "/", | ||||||||
| query: str = "", | ||||||||
| fragment: str = "", | ||||||||
| scheme: str = "", | ||||||||
| last_request: HTTPrettyRequest | None = None, | ||||||||
| ) -> None: ... | ||||||||
| def to_str(self, attrs: Iterable[str]) -> str: ... | ||||||||
| def str_with_query(self) -> str: ... | ||||||||
| def full_url(self, use_querystring: bool = True) -> str: ... | ||||||||
| def get_full_domain(self) -> str: ... | ||||||||
| @classmethod | ||||||||
| def from_uri(cls, uri: str, entry: Entry) -> URIInfo: ... | ||||||||
|
|
||||||||
| class URIMatcher: | ||||||||
| regex: re.Pattern[str] | None | ||||||||
| info: URIInfo | None | ||||||||
| entries: list[Entry] | ||||||||
| priority: int | ||||||||
| uri: _URI | ||||||||
| def __init__(self, uri: _URI, entries: Iterable[Entry], match_querystring: bool = False, priority: int = 0) -> None: ... | ||||||||
| def matches(self, info: URIInfo) -> bool: ... | ||||||||
| def get_next_entry(self, method: _HTTPMethod, info: URIInfo, request: HTTPrettyRequest) -> Entry: ... | ||||||||
|
|
||||||||
| class httpretty(HttpBaseClass): | ||||||||
| GET: Final = "GET" | ||||||||
| PUT: Final = "PUT" | ||||||||
| POST: Final = "POST" | ||||||||
| DELETE: Final = "DELETE" | ||||||||
| HEAD: Final = "HEAD" | ||||||||
| PATCH: Final = "PATCH" | ||||||||
| OPTIONS: Final = "OPTIONS" | ||||||||
| CONNECT: Final = "CONNECT" | ||||||||
| METHODS: tuple[_HTTPMethod, ...] | ||||||||
| latest_requests: list[HTTPrettyRequest] | ||||||||
| last_request: HTTPrettyRequest | HTTPrettyRequestEmpty | ||||||||
| allow_net_connect: bool | ||||||||
| @classmethod | ||||||||
| def match_uriinfo(cls, info: URIInfo) -> tuple[Entry | None, list[str]]: ... | ||||||||
| @classmethod | ||||||||
| def match_https_hostname(cls, hostname: str) -> bool: ... | ||||||||
| @classmethod | ||||||||
| def match_http_address(cls, hostname: str, port: int) -> bool: ... | ||||||||
| @classmethod | ||||||||
| def record( | ||||||||
| cls, | ||||||||
| filename: str, | ||||||||
| indentation: int = 4, | ||||||||
| encoding: str = "utf-8", | ||||||||
| verbose: bool = False, | ||||||||
| allow_net_connect: bool = True, | ||||||||
| pool_manager_params: Mapping[str, Any] | None = None, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another explanatory comment:
Suggested change
|
||||||||
| ) -> AbstractContextManager[None]: ... | ||||||||
| @classmethod | ||||||||
| def playback(cls, filename: str, allow_net_connect: bool = True, verbose: bool = False) -> AbstractContextManager[None]: ... | ||||||||
| @classmethod | ||||||||
| def reset(cls) -> None: ... | ||||||||
| @classmethod | ||||||||
| def historify_request(cls, headers: str | bytes, body: _Body = "", sock: object | None = None) -> HTTPrettyRequest: ... | ||||||||
| @classmethod | ||||||||
| def register_uri( | ||||||||
| cls, | ||||||||
| method: str, | ||||||||
| uri: _URI, | ||||||||
| body: _ResponseBody = '{"message": "HTTPretty :)"}', | ||||||||
| adding_headers: _Headers | None = None, | ||||||||
| forcing_headers: _Headers | None = None, | ||||||||
| status: int = 200, | ||||||||
| responses: Iterable[Entry] | None = None, | ||||||||
| match_querystring: bool = False, | ||||||||
| priority: int = 0, | ||||||||
| **headers: str, | ||||||||
| ) -> None: ... | ||||||||
| @classmethod | ||||||||
| def Response( | ||||||||
| cls, | ||||||||
| body: _ResponseBody, | ||||||||
| method: _HTTPMethod | None = None, | ||||||||
| uri: str | None = None, | ||||||||
| adding_headers: _Headers | None = None, | ||||||||
| forcing_headers: _Headers | None = None, | ||||||||
| status: int = 200, | ||||||||
| streaming: bool = False, | ||||||||
| **headers: str, | ||||||||
| ) -> Entry: ... | ||||||||
| @classmethod | ||||||||
| def disable(cls) -> None: ... | ||||||||
| @classmethod | ||||||||
| def is_enabled(cls) -> bool: ... | ||||||||
| @classmethod | ||||||||
| def enable(cls, allow_net_connect: bool = True, verbose: bool = False) -> None: ... | ||||||||
|
|
||||||||
| class httprettized: | ||||||||
| allow_net_connect: bool | ||||||||
| verbose: bool | ||||||||
| def __init__(self, allow_net_connect: bool = True, verbose: bool = False) -> None: ... | ||||||||
| def __enter__(self) -> None: ... | ||||||||
| def __exit__( | ||||||||
| self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None | ||||||||
| ) -> None: ... | ||||||||
|
|
||||||||
| @overload | ||||||||
| def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ... | ||||||||
| @overload | ||||||||
| def httprettified( | ||||||||
| test: None = None, allow_net_connect: bool = True, verbose: bool = False | ||||||||
| ) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ... | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class HTTPrettyError(Exception): ... | ||
|
|
||
| class UnmockedError(HTTPrettyError): | ||
| def __init__(self, message: str = ..., request: object | None = None, address: object | None = None) -> None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from collections.abc import Sequence | ||
| from typing_extensions import TypeVar | ||
|
|
||
| _T = TypeVar("_T", str, bytes) | ||
|
|
||
| STATUSES: dict[int, str] | ||
|
|
||
| class HttpBaseClass: | ||
| GET: Final = "GET" | ||
| PUT: Final = "PUT" | ||
| POST: Final = "POST" | ||
| DELETE: Final = "DELETE" | ||
| HEAD: Final = "HEAD" | ||
| PATCH: Final = "PATCH" | ||
| OPTIONS: Final = "OPTIONS" | ||
| CONNECT: Final = "CONNECT" | ||
| METHODS: tuple[_HTTPMethod, ...] | ||
|
|
||
| def parse_requestline(s: str) -> tuple[str, str, str]: ... | ||
| def last_requestline(sent_data: Sequence[_T]) -> _T | None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def utf8(s: str | bytes) -> bytes: ... | ||
| def decode_utf8(s: str | bytes) -> str: ... |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||||||
| version: str | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.