Skip to content

Commit 1f4c3ae

Browse files
authored
Merge pull request #173 from OldSneerJaw/mocker-type-stub
2 parents 850671f + bb47a36 commit 1f4c3ae

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

requests_mock/adapter.pyi

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from requests.adapters import BaseAdapter
44
from requests_mock import _RequestObjectProxy
5-
from typing import Any, List, Optional
5+
from typing import Any, Callable, Dict, List, NewType, Optional, Pattern, Union
66

7-
ANY: object = ...
7+
AnyMatcher = NewType("AnyMatcher", object)
8+
9+
ANY: AnyMatcher = ...
810

911
class _RequestHistoryTracker:
1012
request_history: List[_RequestObjectProxy] = ...
@@ -26,5 +28,17 @@ class _Matcher(_RequestHistoryTracker):
2628

2729
class Adapter(BaseAdapter, _RequestHistoryTracker):
2830
def __init__(self, case_sensitive: bool = ...) -> None: ...
29-
def register_uri(self, method: Any, url: Any, response_list: Optional[Any] = ..., **kwargs: Any) -> Any: ...
31+
def register_uri(
32+
self,
33+
method: Union[str, AnyMatcher],
34+
url: Union[str, Pattern[str], AnyMatcher],
35+
response_list: Optional[List[Dict[str, Any]]] = ...,
36+
request_headers: Dict[str, str] = ...,
37+
complete_qs: bool = ...,
38+
status_code: int = ...,
39+
text: str = ...,
40+
headers: Optional[Dict[str, str]] = ...,
41+
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
42+
**kwargs: Any
43+
) -> Any: ...
3044
def add_matcher(self, matcher: Any) -> None: ...

requests_mock/mocker.pyi

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Stubs for requests_mock.mocker
22

3+
from requests_mock.adapter import AnyMatcher
34
from requests import Response
45
from requests_mock.request import _RequestObjectProxy
56
from typing import Any, Callable, Dict, List, Optional, Pattern, Type, TypeVar, Union
@@ -30,71 +31,100 @@ class MockerCore:
3031
def call_count(self) -> int: ...
3132
def register_uri(
3233
self,
33-
method: str,
34+
method: Union[str, AnyMatcher],
35+
url: Union[str, Pattern[str], AnyMatcher],
36+
response_list: Optional[List[Dict[str, Any]]] = ...,
37+
request_headers: Dict[str, str] = ...,
38+
complete_qs: bool = ...,
3439
status_code: int = ...,
3540
text: str = ...,
3641
headers: Optional[Dict[str, str]] = ...,
3742
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
3843
**kwargs: Any) -> Response: ...
3944
def request(
4045
self,
41-
method: str,
46+
method: Union[str, AnyMatcher],
47+
url: Union[str, Pattern[str], AnyMatcher],
48+
response_list: Optional[List[Dict[str, Any]]] = ...,
49+
request_headers: Dict[str, str] = ...,
50+
complete_qs: bool = ...,
4251
status_code: int = ...,
4352
text: str = ...,
4453
headers: Optional[Dict[str, str]] = ...,
4554
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
4655
**kwargs: Any) -> Response: ...
4756
def get(
4857
self,
49-
path: Union[str, Pattern[str]],
58+
url: Union[str, Pattern[str], AnyMatcher],
59+
response_list: Optional[List[Dict[str, Any]]] = ...,
60+
request_headers: Dict[str, str] = ...,
61+
complete_qs: bool = ...,
5062
status_code: int = ...,
5163
text: str = ...,
5264
headers: Optional[Dict[str, str]] = ...,
5365
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
5466
**kwargs: Any) -> Response: ...
5567
def head(
5668
self,
57-
path: Union[str, Pattern[str]],
69+
url: Union[str, Pattern[str], AnyMatcher],
70+
response_list: Optional[List[Dict[str, Any]]] = ...,
71+
request_headers: Dict[str, str] = ...,
72+
complete_qs: bool = ...,
5873
status_code: int = ...,
5974
text: str = ...,
6075
headers: Optional[Dict[str, str]] = ...,
6176
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
6277
**kwargs: Any) -> Response: ...
6378
def options(
6479
self,
65-
path: Union[str, Pattern[str]],
80+
url: Union[str, Pattern[str], AnyMatcher],
81+
response_list: Optional[List[Dict[str, Any]]] = ...,
82+
request_headers: Dict[str, str] = ...,
83+
complete_qs: bool = ...,
6684
status_code: int = ...,
6785
text: str = ...,
6886
headers: Optional[Dict[str, str]] = ...,
6987
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
7088
**kwargs: Any) -> Response: ...
7189
def post(
7290
self,
73-
path: Union[str, Pattern[str]],
91+
url: Union[str, Pattern[str], AnyMatcher],
92+
response_list: Optional[List[Dict[str, Any]]] = ...,
93+
request_headers: Dict[str, str] = ...,
94+
complete_qs: bool = ...,
7495
status_code: int = ...,
7596
text: str = ...,
7697
headers: Optional[Dict[str, str]] = ...,
7798
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
7899
**kwargs: Any) -> Response: ...
79100
def put(
80101
self,
81-
path: Union[str, Pattern[str]],
102+
url: Union[str, Pattern[str], AnyMatcher],
103+
response_list: Optional[List[Dict[str, Any]]] = ...,
104+
request_headers: Dict[str, str] = ...,
105+
complete_qs: bool = ...,
82106
status_code: int = ...,
83107
text: str = ...,
84108
headers: Optional[Dict[str, str]] = ...,
85109
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
86110
**kwargs: Any) -> Response: ...
87111
def patch(
88112
self,
89-
path: Union[str, Pattern[str]],
113+
url: Union[str, Pattern[str], AnyMatcher],
114+
response_list: Optional[List[Dict[str, Any]]] = ...,
115+
request_headers: Dict[str, str] = ...,
116+
complete_qs: bool = ...,
90117
status_code: int = ...,
91118
text: str = ...,
92119
headers: Optional[Dict[str, str]] = ...,
93120
additional_matcher: Optional[Callable[[_RequestObjectProxy], bool]] = ...,
94121
**kwargs: Any) -> Response: ...
95122
def delete(
96123
self,
97-
path: Union[str, Pattern[str]],
124+
url: Union[str, Pattern[str], AnyMatcher],
125+
response_list: Optional[List[Dict[str, Any]]] = ...,
126+
request_headers: Dict[str, str] = ...,
127+
complete_qs: bool = ...,
98128
status_code: int = ...,
99129
text: str = ...,
100130
headers: Optional[Dict[str, str]] = ...,

0 commit comments

Comments
 (0)