11"""
22Dynamically load all Django assertion cases and expose them for importing.
33"""
4+ from __future__ import annotations
5+
46from 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
88
9- from django .test import (
10- LiveServerTestCase , SimpleTestCase , TestCase , TransactionTestCase ,
11- )
9+ from django .test import LiveServerTestCase , SimpleTestCase , TestCase , TransactionTestCase
1210
1311
1412test_case = TestCase ("run" )
@@ -25,7 +23,7 @@ def assertion_func(*args, **kwargs):
2523
2624
2725__all__ = []
28- assertions_names : Set [str ] = set ()
26+ assertions_names : set [str ] = set ()
2927assertions_names .update (
3028 {attr for attr in vars (TestCase ) if attr .startswith ("assert" )},
3129 {attr for attr in vars (SimpleTestCase ) if attr .startswith ("assert" )},
@@ -35,7 +33,7 @@ def assertion_func(*args, **kwargs):
3533
3634for assert_func in assertions_names :
3735 globals ()[assert_func ] = _wrapper (assert_func )
38- __all__ .append (assert_func )
36+ __all__ .append (assert_func ) # noqa: PYI056
3937
4038
4139if TYPE_CHECKING :
@@ -61,7 +59,7 @@ def assertURLEqual(
6159 def assertContains (
6260 response : HttpResponseBase ,
6361 text : object ,
64- count : Optional [ int ] = ...,
62+ count : int | None = ...,
6563 status_code : int = ...,
6664 msg_prefix : str = ...,
6765 html : bool = False ,
@@ -80,39 +78,39 @@ def assertNotContains(
8078 def assertFormError (
8179 response : HttpResponseBase ,
8280 form : str ,
83- field : Optional [ str ] ,
84- errors : Union [ str , Sequence [str ] ],
81+ field : str | None ,
82+ errors : str | Sequence [str ],
8583 msg_prefix : str = ...,
8684 ) -> None :
8785 ...
8886
8987 def assertFormsetError (
9088 response : HttpResponseBase ,
9189 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 ],
9593 msg_prefix : str = ...,
9694 ) -> None :
9795 ...
9896
9997 def assertTemplateUsed (
100- response : Optional [ Union [ HttpResponseBase , str ]] = ...,
101- template_name : Optional [ str ] = ...,
98+ response : HttpResponseBase | str | None = ...,
99+ template_name : str | None = ...,
102100 msg_prefix : str = ...,
103- count : Optional [ int ] = ...,
101+ count : int | None = ...,
104102 ):
105103 ...
106104
107105 def assertTemplateNotUsed (
108- response : Optional [ Union [ HttpResponseBase , str ]] = ...,
109- template_name : Optional [ str ] = ...,
106+ response : HttpResponseBase | str | None = ...,
107+ template_name : str | None = ...,
110108 msg_prefix : str = ...,
111109 ):
112110 ...
113111
114112 def assertRaisesMessage (
115- expected_exception : Type [Exception ],
113+ expected_exception : type [Exception ],
116114 expected_message : str ,
117115 * args ,
118116 ** kwargs
@@ -140,50 +138,50 @@ def assertFieldOutput(
140138 def assertHTMLEqual (
141139 html1 : str ,
142140 html2 : str ,
143- msg : Optional [ str ] = ...,
141+ msg : str | None = ...,
144142 ) -> None :
145143 ...
146144
147145 def assertHTMLNotEqual (
148146 html1 : str ,
149147 html2 : str ,
150- msg : Optional [ str ] = ...,
148+ msg : str | None = ...,
151149 ) -> None :
152150 ...
153151
154152 def assertInHTML (
155153 needle : str ,
156154 haystack : str ,
157- count : Optional [ int ] = ...,
155+ count : int | None = ...,
158156 msg_prefix : str = ...,
159157 ) -> None :
160158 ...
161159
162160 def assertJSONEqual (
163161 raw : str ,
164162 expected_data : Any ,
165- msg : Optional [ str ] = ...,
163+ msg : str | None = ...,
166164 ) -> None :
167165 ...
168166
169167 def assertJSONNotEqual (
170168 raw : str ,
171169 expected_data : Any ,
172- msg : Optional [ str ] = ...,
170+ msg : str | None = ...,
173171 ) -> None :
174172 ...
175173
176174 def assertXMLEqual (
177175 xml1 : str ,
178176 xml2 : str ,
179- msg : Optional [ str ] = ...,
177+ msg : str | None = ...,
180178 ) -> None :
181179 ...
182180
183181 def assertXMLNotEqual (
184182 xml1 : str ,
185183 xml2 : str ,
186- msg : Optional [ str ] = ...,
184+ msg : str | None = ...,
187185 ) -> None :
188186 ...
189187
@@ -193,7 +191,7 @@ def assertQuerysetEqual(
193191 values ,
194192 transform = ...,
195193 ordered : bool = ...,
196- msg : Optional [ str ] = ...,
194+ msg : str | None = ...,
197195 ) -> None :
198196 ...
199197
@@ -202,7 +200,7 @@ def assertQuerySetEqual(
202200 values ,
203201 transform = ...,
204202 ordered : bool = ...,
205- msg : Optional [ str ] = ...,
203+ msg : str | None = ...,
206204 ) -> None :
207205 ...
208206
0 commit comments