Skip to content

Commit a54ae98

Browse files
committed
asserts: add type annotations
It's the only user-visible part so let's put some effort.
1 parent 6ab338f commit a54ae98

File tree

1 file changed

+168
-1
lines changed

1 file changed

+168
-1
lines changed

pytest_django/asserts.py

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Dynamically load all Django assertion cases and expose them for importing.
33
"""
4-
from typing import Any, Callable, Set
4+
from typing import Any, Callable, Optional, Sequence, Set, Union
55
from functools import wraps
66

77
from django.test import (
@@ -40,5 +40,172 @@ def assertion_func(*args, **kwargs):
4040

4141

4242
if TYPE_CHECKING:
43+
from django.http import HttpResponse
44+
45+
def assertRedirects(
46+
response: HttpResponse,
47+
expected_url: str,
48+
status_code: int = ...,
49+
target_status_code: int = ...,
50+
msg_prefix: str = ...,
51+
fetch_redirect_response: bool = ...,
52+
) -> None:
53+
...
54+
55+
def assertURLEqual(
56+
url1: str,
57+
url2: str,
58+
msg_prefix: str = ...,
59+
) -> None:
60+
...
61+
62+
def assertContains(
63+
response: HttpResponse,
64+
text: object,
65+
count: Optional[int] = ...,
66+
status_code: int = ...,
67+
msg_prefix: str = ...,
68+
html: bool = False,
69+
) -> None:
70+
...
71+
72+
def assertNotContains(
73+
response: HttpResponse,
74+
text: object,
75+
status_code: int = ...,
76+
msg_prefix: str = ...,
77+
html: bool = False,
78+
) -> None:
79+
...
80+
81+
def assertFormError(
82+
response: HttpResponse,
83+
form: str,
84+
field: Optional[str],
85+
errors: Union[str, Sequence[str]],
86+
msg_prefix: str = ...,
87+
) -> None:
88+
...
89+
90+
def assertFormsetError(
91+
response: HttpResponse,
92+
formset: str,
93+
form_index: Optional[int],
94+
field: Optional[str],
95+
errors: Union[str, Sequence[str]],
96+
msg_prefix: str = ...,
97+
) -> None:
98+
...
99+
100+
def assertTemplateUsed(
101+
response: Optional[HttpResponse] = ...,
102+
template_name: Optional[str] = ...,
103+
msg_prefix: str = ...,
104+
count: Optional[int] = ...,
105+
) -> None:
106+
...
107+
108+
def assertTemplateNotUsed(
109+
response: Optional[HttpResponse] = ...,
110+
template_name: Optional[str] = ...,
111+
msg_prefix: str = ...,
112+
) -> None:
113+
...
114+
115+
def assertRaisesMessage(
116+
expected_exception: BaseException,
117+
expected_message: str,
118+
*args,
119+
**kwargs,
120+
):
121+
...
122+
123+
def assertWarnsMessage(
124+
expected_warning: Warning,
125+
expected_message: str,
126+
*args,
127+
**kwargs,
128+
):
129+
...
130+
131+
def assertFieldOutput(
132+
fieldclass,
133+
valid,
134+
invalid,
135+
field_args=...,
136+
field_kwargs=...,
137+
empty_value: str = ...,
138+
) -> None:
139+
...
140+
141+
def assertHTMLEqual(
142+
html1: str,
143+
html2: str,
144+
msg: Optional[str] = ...,
145+
) -> None:
146+
...
147+
148+
def assertHTMLNotEqual(
149+
html1: str,
150+
html2: str,
151+
msg: Optional[str] = ...,
152+
) -> None:
153+
...
154+
155+
def assertInHTML(
156+
needle: str,
157+
haystack: str,
158+
count: Optional[int] = ...,
159+
msg_prefix: str = ...,
160+
) -> None:
161+
...
162+
163+
def assertJSONEqual(
164+
raw: str,
165+
expected_data: Any,
166+
msg: Optional[str] = ...,
167+
) -> None:
168+
...
169+
170+
def assertJSONNotEqual(
171+
raw: str,
172+
expected_data: Any,
173+
msg: Optional[str] = ...,
174+
) -> None:
175+
...
176+
177+
def assertXMLEqual(
178+
xml1: str,
179+
xml2: str,
180+
msg: Optional[str] = ...,
181+
) -> None:
182+
...
183+
184+
def assertXMLNotEqual(
185+
xml1: str,
186+
xml2: str,
187+
msg: Optional[str] = ...,
188+
) -> None:
189+
...
190+
191+
def assertQuerysetEqual(
192+
qs,
193+
values,
194+
transform=...,
195+
ordered: bool = ...,
196+
msg: Optional[str] = ...,
197+
) -> None:
198+
...
199+
200+
def assertNumQueries(
201+
num: int,
202+
func=...,
203+
*args,
204+
using: str = ...,
205+
**kwargs,
206+
):
207+
...
208+
209+
# Fallback in case Django adds new asserts.
43210
def __getattr__(name: str) -> Callable[..., Any]:
44211
...

0 commit comments

Comments
 (0)