1
1
"""
2
2
Dynamically load all Django assertion cases and expose them for importing.
3
3
"""
4
+ from __future__ import annotations
5
+
4
6
from functools import wraps
5
- from typing import (
6
- TYPE_CHECKING , Any , Callable , Optional , Sequence , Set , Type , Union ,
7
- )
7
+ from typing import TYPE_CHECKING , Any , Callable , Sequence
8
8
9
- from django .test import (
10
- LiveServerTestCase , SimpleTestCase , TestCase , TransactionTestCase ,
11
- )
9
+ from django .test import LiveServerTestCase , SimpleTestCase , TestCase , TransactionTestCase
12
10
13
11
14
12
test_case = TestCase ("run" )
@@ -25,7 +23,7 @@ def assertion_func(*args, **kwargs):
25
23
26
24
27
25
__all__ = []
28
- assertions_names : Set [str ] = set ()
26
+ assertions_names : set [str ] = set ()
29
27
assertions_names .update (
30
28
{attr for attr in vars (TestCase ) if attr .startswith ("assert" )},
31
29
{attr for attr in vars (SimpleTestCase ) if attr .startswith ("assert" )},
@@ -35,7 +33,7 @@ def assertion_func(*args, **kwargs):
35
33
36
34
for assert_func in assertions_names :
37
35
globals ()[assert_func ] = _wrapper (assert_func )
38
- __all__ .append (assert_func )
36
+ __all__ .append (assert_func ) # noqa: PYI056
39
37
40
38
41
39
if TYPE_CHECKING :
@@ -61,7 +59,7 @@ def assertURLEqual(
61
59
def assertContains (
62
60
response : HttpResponseBase ,
63
61
text : object ,
64
- count : Optional [ int ] = ...,
62
+ count : int | None = ...,
65
63
status_code : int = ...,
66
64
msg_prefix : str = ...,
67
65
html : bool = False ,
@@ -80,39 +78,39 @@ def assertNotContains(
80
78
def assertFormError (
81
79
response : HttpResponseBase ,
82
80
form : str ,
83
- field : Optional [ str ] ,
84
- errors : Union [ str , Sequence [str ] ],
81
+ field : str | None ,
82
+ errors : str | Sequence [str ],
85
83
msg_prefix : str = ...,
86
84
) -> None :
87
85
...
88
86
89
87
def assertFormsetError (
90
88
response : HttpResponseBase ,
91
89
formset : str ,
92
- form_index : Optional [ int ] ,
93
- field : Optional [ str ] ,
94
- errors : Union [ str , Sequence [str ] ],
90
+ form_index : int | None ,
91
+ field : str | None ,
92
+ errors : str | Sequence [str ],
95
93
msg_prefix : str = ...,
96
94
) -> None :
97
95
...
98
96
99
97
def assertTemplateUsed (
100
- response : Optional [ Union [ HttpResponseBase , str ]] = ...,
101
- template_name : Optional [ str ] = ...,
98
+ response : HttpResponseBase | str | None = ...,
99
+ template_name : str | None = ...,
102
100
msg_prefix : str = ...,
103
- count : Optional [ int ] = ...,
101
+ count : int | None = ...,
104
102
):
105
103
...
106
104
107
105
def assertTemplateNotUsed (
108
- response : Optional [ Union [ HttpResponseBase , str ]] = ...,
109
- template_name : Optional [ str ] = ...,
106
+ response : HttpResponseBase | str | None = ...,
107
+ template_name : str | None = ...,
110
108
msg_prefix : str = ...,
111
109
):
112
110
...
113
111
114
112
def assertRaisesMessage (
115
- expected_exception : Type [Exception ],
113
+ expected_exception : type [Exception ],
116
114
expected_message : str ,
117
115
* args ,
118
116
** kwargs
@@ -140,50 +138,50 @@ def assertFieldOutput(
140
138
def assertHTMLEqual (
141
139
html1 : str ,
142
140
html2 : str ,
143
- msg : Optional [ str ] = ...,
141
+ msg : str | None = ...,
144
142
) -> None :
145
143
...
146
144
147
145
def assertHTMLNotEqual (
148
146
html1 : str ,
149
147
html2 : str ,
150
- msg : Optional [ str ] = ...,
148
+ msg : str | None = ...,
151
149
) -> None :
152
150
...
153
151
154
152
def assertInHTML (
155
153
needle : str ,
156
154
haystack : str ,
157
- count : Optional [ int ] = ...,
155
+ count : int | None = ...,
158
156
msg_prefix : str = ...,
159
157
) -> None :
160
158
...
161
159
162
160
def assertJSONEqual (
163
161
raw : str ,
164
162
expected_data : Any ,
165
- msg : Optional [ str ] = ...,
163
+ msg : str | None = ...,
166
164
) -> None :
167
165
...
168
166
169
167
def assertJSONNotEqual (
170
168
raw : str ,
171
169
expected_data : Any ,
172
- msg : Optional [ str ] = ...,
170
+ msg : str | None = ...,
173
171
) -> None :
174
172
...
175
173
176
174
def assertXMLEqual (
177
175
xml1 : str ,
178
176
xml2 : str ,
179
- msg : Optional [ str ] = ...,
177
+ msg : str | None = ...,
180
178
) -> None :
181
179
...
182
180
183
181
def assertXMLNotEqual (
184
182
xml1 : str ,
185
183
xml2 : str ,
186
- msg : Optional [ str ] = ...,
184
+ msg : str | None = ...,
187
185
) -> None :
188
186
...
189
187
@@ -193,7 +191,7 @@ def assertQuerysetEqual(
193
191
values ,
194
192
transform = ...,
195
193
ordered : bool = ...,
196
- msg : Optional [ str ] = ...,
194
+ msg : str | None = ...,
197
195
) -> None :
198
196
...
199
197
@@ -202,7 +200,7 @@ def assertQuerySetEqual(
202
200
values ,
203
201
transform = ...,
204
202
ordered : bool = ...,
205
- msg : Optional [ str ] = ...,
203
+ msg : str | None = ...,
206
204
) -> None :
207
205
...
208
206
0 commit comments