@@ -2146,99 +2146,6 @@ async def f():
2146
2146
self .assertEqual (buffer , [1 , 2 , 'MyException' ])
2147
2147
2148
2148
2149
- class SysSetCoroWrapperTest (unittest .TestCase ):
2150
-
2151
- def test_set_wrapper_1 (self ):
2152
- async def foo ():
2153
- return 'spam'
2154
-
2155
- wrapped = None
2156
- def wrap (gen ):
2157
- nonlocal wrapped
2158
- wrapped = gen
2159
- return gen
2160
-
2161
- with self .assertWarns (DeprecationWarning ):
2162
- self .assertIsNone (sys .get_coroutine_wrapper ())
2163
-
2164
- with self .assertWarns (DeprecationWarning ):
2165
- sys .set_coroutine_wrapper (wrap )
2166
- with self .assertWarns (DeprecationWarning ):
2167
- self .assertIs (sys .get_coroutine_wrapper (), wrap )
2168
- try :
2169
- f = foo ()
2170
- self .assertTrue (wrapped )
2171
-
2172
- self .assertEqual (run_async (f ), ([], 'spam' ))
2173
- finally :
2174
- with self .assertWarns (DeprecationWarning ):
2175
- sys .set_coroutine_wrapper (None )
2176
- f .close ()
2177
-
2178
- with self .assertWarns (DeprecationWarning ):
2179
- self .assertIsNone (sys .get_coroutine_wrapper ())
2180
-
2181
- wrapped = None
2182
- coro = foo ()
2183
- self .assertFalse (wrapped )
2184
- coro .close ()
2185
-
2186
- def test_set_wrapper_2 (self ):
2187
- with self .assertWarns (DeprecationWarning ):
2188
- self .assertIsNone (sys .get_coroutine_wrapper ())
2189
- with self .assertRaisesRegex (TypeError , "callable expected, got int" ):
2190
- with self .assertWarns (DeprecationWarning ):
2191
- sys .set_coroutine_wrapper (1 )
2192
- with self .assertWarns (DeprecationWarning ):
2193
- self .assertIsNone (sys .get_coroutine_wrapper ())
2194
-
2195
- def test_set_wrapper_3 (self ):
2196
- async def foo ():
2197
- return 'spam'
2198
-
2199
- def wrapper (coro ):
2200
- async def wrap (coro ):
2201
- return await coro
2202
- return wrap (coro )
2203
-
2204
- with self .assertWarns (DeprecationWarning ):
2205
- sys .set_coroutine_wrapper (wrapper )
2206
- try :
2207
- with silence_coro_gc (), self .assertRaisesRegex (
2208
- RuntimeError ,
2209
- r"coroutine wrapper.*\.wrapper at 0x.*attempted to "
2210
- r"recursively wrap .* wrap .*" ):
2211
-
2212
- foo ()
2213
-
2214
- finally :
2215
- with self .assertWarns (DeprecationWarning ):
2216
- sys .set_coroutine_wrapper (None )
2217
-
2218
- def test_set_wrapper_4 (self ):
2219
- @types .coroutine
2220
- def foo ():
2221
- return 'spam'
2222
-
2223
- wrapped = None
2224
- def wrap (gen ):
2225
- nonlocal wrapped
2226
- wrapped = gen
2227
- return gen
2228
-
2229
- with self .assertWarns (DeprecationWarning ):
2230
- sys .set_coroutine_wrapper (wrap )
2231
- try :
2232
- foo ()
2233
- self .assertIs (
2234
- wrapped , None ,
2235
- "generator-based coroutine was wrapped via "
2236
- "sys.set_coroutine_wrapper" )
2237
- finally :
2238
- with self .assertWarns (DeprecationWarning ):
2239
- sys .set_coroutine_wrapper (None )
2240
-
2241
-
2242
2149
class OriginTrackingTest (unittest .TestCase ):
2243
2150
def here (self ):
2244
2151
info = inspect .getframeinfo (inspect .currentframe ().f_back )
0 commit comments