@@ -30,23 +30,7 @@ def wrapper(*args, **kwargs):
30
30
return wrapper
31
31
32
32
33
- class TestAbstractAsyncContextManager (unittest .IsolatedAsyncioTestCase ):
34
-
35
- def test_async_test_self_test (self ):
36
- class _async_yield :
37
- def __init__ (self , v ):
38
- self .v = v
39
-
40
- def __await__ (self ):
41
- return (yield self .v )
42
-
43
- @_async_test
44
- async def do_not_stop_coro ():
45
- while True :
46
- await _async_yield (None )
47
-
48
- with self .assertRaisesRegex (AssertionError , "coroutine did not stop" ):
49
- do_not_stop_coro ()
33
+ class TestAbstractAsyncContextManager (unittest .TestCase ):
50
34
51
35
@_async_test
52
36
async def test_enter (self ):
@@ -60,6 +44,7 @@ async def __aexit__(self, *args):
60
44
async with manager as context :
61
45
self .assertIs (manager , context )
62
46
47
+ @_async_test
63
48
async def test_slots (self ):
64
49
class DefaultAsyncContextManager (AbstractAsyncContextManager ):
65
50
__slots__ = ()
@@ -71,6 +56,7 @@ async def __aexit__(self, *args):
71
56
manager = DefaultAsyncContextManager ()
72
57
manager .var = 42
73
58
59
+ @_async_test
74
60
async def test_async_gen_propagates_generator_exit (self ):
75
61
# A regression test for https://bugs.python.org/issue33786.
76
62
@@ -121,8 +107,9 @@ class NoneAexit(ManagerFromScratch):
121
107
self .assertFalse (issubclass (NoneAexit , AbstractAsyncContextManager ))
122
108
123
109
124
- class AsyncContextManagerTestCase (unittest .IsolatedAsyncioTestCase ):
110
+ class AsyncContextManagerTestCase (unittest .TestCase ):
125
111
112
+ @_async_test
126
113
async def test_contextmanager_plain (self ):
127
114
state = []
128
115
@asynccontextmanager
@@ -136,6 +123,7 @@ async def woohoo():
136
123
state .append (x )
137
124
self .assertEqual (state , [1 , 42 , 999 ])
138
125
126
+ @_async_test
139
127
async def test_contextmanager_finally (self ):
140
128
state = []
141
129
@asynccontextmanager
@@ -153,6 +141,7 @@ async def woohoo():
153
141
raise ZeroDivisionError ()
154
142
self .assertEqual (state , [1 , 42 , 999 ])
155
143
144
+ @_async_test
156
145
async def test_contextmanager_traceback (self ):
157
146
@asynccontextmanager
158
147
async def f ():
@@ -208,6 +197,7 @@ class StopAsyncIterationSubclass(StopAsyncIteration):
208
197
self .assertEqual (frames [0 ].name , 'test_contextmanager_traceback' )
209
198
self .assertEqual (frames [0 ].line , 'raise stop_exc' )
210
199
200
+ @_async_test
211
201
async def test_contextmanager_no_reraise (self ):
212
202
@asynccontextmanager
213
203
async def whee ():
@@ -217,6 +207,7 @@ async def whee():
217
207
# Calling __aexit__ should not result in an exception
218
208
self .assertFalse (await ctx .__aexit__ (TypeError , TypeError ("foo" ), None ))
219
209
210
+ @_async_test
220
211
async def test_contextmanager_trap_yield_after_throw (self ):
221
212
@asynccontextmanager
222
213
async def whoo ():
@@ -232,6 +223,7 @@ async def whoo():
232
223
# The "gen" attribute is an implementation detail.
233
224
self .assertFalse (ctx .gen .ag_suspended )
234
225
226
+ @_async_test
235
227
async def test_contextmanager_trap_no_yield (self ):
236
228
@asynccontextmanager
237
229
async def whoo ():
@@ -241,6 +233,7 @@ async def whoo():
241
233
with self .assertRaises (RuntimeError ):
242
234
await ctx .__aenter__ ()
243
235
236
+ @_async_test
244
237
async def test_contextmanager_trap_second_yield (self ):
245
238
@asynccontextmanager
246
239
async def whoo ():
@@ -254,6 +247,7 @@ async def whoo():
254
247
# The "gen" attribute is an implementation detail.
255
248
self .assertFalse (ctx .gen .ag_suspended )
256
249
250
+ @_async_test
257
251
async def test_contextmanager_non_normalised (self ):
258
252
@asynccontextmanager
259
253
async def whoo ():
@@ -267,6 +261,7 @@ async def whoo():
267
261
with self .assertRaises (SyntaxError ):
268
262
await ctx .__aexit__ (RuntimeError , None , None )
269
263
264
+ @_async_test
270
265
async def test_contextmanager_except (self ):
271
266
state = []
272
267
@asynccontextmanager
@@ -284,6 +279,7 @@ async def woohoo():
284
279
raise ZeroDivisionError (999 )
285
280
self .assertEqual (state , [1 , 42 , 999 ])
286
281
282
+ @_async_test
287
283
async def test_contextmanager_except_stopiter (self ):
288
284
@asynccontextmanager
289
285
async def woohoo ():
@@ -310,6 +306,7 @@ class StopAsyncIterationSubclass(StopAsyncIteration):
310
306
else :
311
307
self .fail (f'{ stop_exc } was suppressed' )
312
308
309
+ @_async_test
313
310
async def test_contextmanager_wrap_runtimeerror (self ):
314
311
@asynccontextmanager
315
312
async def woohoo ():
@@ -354,12 +351,14 @@ def test_contextmanager_doc_attrib(self):
354
351
self .assertEqual (baz .__doc__ , "Whee!" )
355
352
356
353
@support .requires_docstrings
354
+ @_async_test
357
355
async def test_instance_docstring_given_cm_docstring (self ):
358
356
baz = self ._create_contextmanager_attribs ()(None )
359
357
self .assertEqual (baz .__doc__ , "Whee!" )
360
358
async with baz :
361
359
pass # suppress warning
362
360
361
+ @_async_test
363
362
async def test_keywords (self ):
364
363
# Ensure no keyword arguments are inhibited
365
364
@asynccontextmanager
@@ -368,6 +367,7 @@ async def woohoo(self, func, args, kwds):
368
367
async with woohoo (self = 11 , func = 22 , args = 33 , kwds = 44 ) as target :
369
368
self .assertEqual (target , (11 , 22 , 33 , 44 ))
370
369
370
+ @_async_test
371
371
async def test_recursive (self ):
372
372
depth = 0
373
373
ncols = 0
@@ -394,6 +394,7 @@ async def recursive():
394
394
self .assertEqual (ncols , 10 )
395
395
self .assertEqual (depth , 0 )
396
396
397
+ @_async_test
397
398
async def test_decorator (self ):
398
399
entered = False
399
400
@@ -412,6 +413,7 @@ async def test():
412
413
await test ()
413
414
self .assertFalse (entered )
414
415
416
+ @_async_test
415
417
async def test_decorator_with_exception (self ):
416
418
entered = False
417
419
@@ -434,6 +436,7 @@ async def test():
434
436
await test ()
435
437
self .assertFalse (entered )
436
438
439
+ @_async_test
437
440
async def test_decorating_method (self ):
438
441
439
442
@asynccontextmanager
@@ -468,14 +471,15 @@ async def method(self, a, b, c=None):
468
471
self .assertEqual (test .b , 2 )
469
472
470
473
471
- class AclosingTestCase (unittest .IsolatedAsyncioTestCase ):
474
+ class AclosingTestCase (unittest .TestCase ):
472
475
473
476
@support .requires_docstrings
474
477
def test_instance_docs (self ):
475
478
cm_docstring = aclosing .__doc__
476
479
obj = aclosing (None )
477
480
self .assertEqual (obj .__doc__ , cm_docstring )
478
481
482
+ @_async_test
479
483
async def test_aclosing (self ):
480
484
state = []
481
485
class C :
@@ -487,6 +491,7 @@ async def aclose(self):
487
491
self .assertEqual (x , y )
488
492
self .assertEqual (state , [1 ])
489
493
494
+ @_async_test
490
495
async def test_aclosing_error (self ):
491
496
state = []
492
497
class C :
@@ -500,6 +505,7 @@ async def aclose(self):
500
505
1 / 0
501
506
self .assertEqual (state , [1 ])
502
507
508
+ @_async_test
503
509
async def test_aclosing_bpo41229 (self ):
504
510
state = []
505
511
@@ -525,7 +531,7 @@ async def agenfunc():
525
531
self .assertEqual (state , [1 ])
526
532
527
533
528
- class TestAsyncExitStack (TestBaseExitStack , unittest .IsolatedAsyncioTestCase ):
534
+ class TestAsyncExitStack (TestBaseExitStack , unittest .TestCase ):
529
535
class SyncAsyncExitStack (AsyncExitStack ):
530
536
531
537
def close (self ):
@@ -589,6 +595,7 @@ async def _exit(*args, **kwds):
589
595
stack .push_async_callback (callback = _exit , arg = 3 )
590
596
self .assertEqual (result , [])
591
597
598
+ @_async_test
592
599
async def test_async_push (self ):
593
600
exc_raised = ZeroDivisionError
594
601
async def _expect_exc (exc_type , exc , exc_tb ):
@@ -624,6 +631,7 @@ async def __aexit__(self, *exc_details):
624
631
self .assertIs (stack ._exit_callbacks [- 1 ][1 ], _expect_exc )
625
632
1 / 0
626
633
634
+ @_async_test
627
635
async def test_enter_async_context (self ):
628
636
class TestCM (object ):
629
637
async def __aenter__ (self ):
@@ -645,6 +653,7 @@ async def _exit():
645
653
646
654
self .assertEqual (result , [1 , 2 , 3 , 4 ])
647
655
656
+ @_async_test
648
657
async def test_enter_async_context_errors (self ):
649
658
class LacksEnterAndExit :
650
659
pass
@@ -664,6 +673,7 @@ async def __aenter__(self):
664
673
await stack .enter_async_context (LacksExit ())
665
674
self .assertFalse (stack ._exit_callbacks )
666
675
676
+ @_async_test
667
677
async def test_async_exit_exception_chaining (self ):
668
678
# Ensure exception chaining matches the reference behaviour
669
679
async def raise_exc (exc ):
@@ -695,6 +705,7 @@ async def suppress_exc(*exc_details):
695
705
self .assertIsInstance (inner_exc , ValueError )
696
706
self .assertIsInstance (inner_exc .__context__ , ZeroDivisionError )
697
707
708
+ @_async_test
698
709
async def test_async_exit_exception_explicit_none_context (self ):
699
710
# Ensure AsyncExitStack chaining matches actual nested `with` statements
700
711
# regarding explicit __context__ = None.
@@ -729,6 +740,7 @@ async def my_cm_with_exit_stack():
729
740
else :
730
741
self .fail ("Expected IndexError, but no exception was raised" )
731
742
743
+ @_async_test
732
744
async def test_instance_bypass_async (self ):
733
745
class Example (object ): pass
734
746
cm = Example ()
@@ -741,7 +753,8 @@ class Example(object): pass
741
753
self .assertIs (stack ._exit_callbacks [- 1 ][1 ], cm )
742
754
743
755
744
- class TestAsyncNullcontext (unittest .IsolatedAsyncioTestCase ):
756
+ class TestAsyncNullcontext (unittest .TestCase ):
757
+ @_async_test
745
758
async def test_async_nullcontext (self ):
746
759
class C :
747
760
pass
0 commit comments