@@ -47,32 +47,24 @@ def test_repr(self):
47
47
self .assertTrue (repr (lock ).endswith ('[unlocked]>' ))
48
48
self .assertTrue (RGX_REPR .match (repr (lock )))
49
49
50
- with self .assertWarns (DeprecationWarning ):
51
- @asyncio .coroutine
52
- def acquire_lock ():
53
- with self .assertWarns (DeprecationWarning ):
54
- yield from lock
55
-
56
- self .loop .run_until_complete (acquire_lock ())
50
+ self .loop .run_until_complete (lock .acquire ())
57
51
self .assertTrue (repr (lock ).endswith ('[locked]>' ))
58
52
self .assertTrue (RGX_REPR .match (repr (lock )))
59
53
60
54
def test_lock (self ):
61
55
with self .assertWarns (DeprecationWarning ):
62
56
lock = asyncio .Lock (loop = self .loop )
63
57
64
-
65
58
@asyncio .coroutine
66
59
def acquire_lock ():
67
- with self .assertWarns (DeprecationWarning ):
68
- return (yield from lock )
69
-
70
- res = self .loop .run_until_complete (acquire_lock ())
60
+ return (yield from lock )
71
61
72
- self .assertTrue (res )
73
- self .assertTrue (lock .locked ())
62
+ with self .assertRaisesRegex (
63
+ TypeError ,
64
+ "object is not iterable"
65
+ ):
66
+ self .loop .run_until_complete (acquire_lock ())
74
67
75
- lock .release ()
76
68
self .assertFalse (lock .locked ())
77
69
78
70
def test_lock_by_with_statement (self ):
@@ -90,13 +82,13 @@ def test_lock_by_with_statement(self):
90
82
def test (lock ):
91
83
yield from asyncio .sleep (0.01 )
92
84
self .assertFalse (lock .locked ())
93
- with self .assertWarns ( DeprecationWarning ):
94
- with ( yield from lock ) as _lock :
95
- self . assertIs ( _lock , None )
96
- self . assertTrue ( lock . locked ())
97
- yield from asyncio . sleep ( 0.01 )
98
- self . assertTrue ( lock . locked ())
99
- self .assertFalse (lock .locked ())
85
+ with self .assertRaisesRegex (
86
+ TypeError ,
87
+ "object is not iterable"
88
+ ):
89
+ with ( yield from lock ):
90
+ pass
91
+ self .assertFalse (lock .locked ())
100
92
101
93
for primitive in primitives :
102
94
loop .run_until_complete (test (primitive ))
@@ -302,52 +294,16 @@ def test_release_no_waiters(self):
302
294
self .assertFalse (lock .locked ())
303
295
304
296
def test_context_manager (self ):
305
- with self .assertWarns (DeprecationWarning ):
306
- lock = asyncio .Lock (loop = self .loop )
297
+ async def f ():
298
+ lock = asyncio .Lock ()
299
+ self .assertFalse (lock .locked ())
307
300
308
- @asyncio .coroutine
309
- def acquire_lock ():
310
- with self .assertWarns (DeprecationWarning ):
311
- return (yield from lock )
301
+ async with lock :
302
+ self .assertTrue (lock .locked ())
312
303
313
- with self .loop .run_until_complete (acquire_lock ()):
314
- self .assertTrue (lock .locked ())
304
+ self .assertFalse (lock .locked ())
315
305
316
- self .assertFalse (lock .locked ())
317
-
318
- def test_context_manager_cant_reuse (self ):
319
- with self .assertWarns (DeprecationWarning ):
320
- lock = asyncio .Lock (loop = self .loop )
321
-
322
- @asyncio .coroutine
323
- def acquire_lock ():
324
- with self .assertWarns (DeprecationWarning ):
325
- return (yield from lock )
326
-
327
- # This spells "yield from lock" outside a generator.
328
- cm = self .loop .run_until_complete (acquire_lock ())
329
- with cm :
330
- self .assertTrue (lock .locked ())
331
-
332
- self .assertFalse (lock .locked ())
333
-
334
- with self .assertRaises (AttributeError ):
335
- with cm :
336
- pass
337
-
338
- def test_context_manager_no_yield (self ):
339
- with self .assertWarns (DeprecationWarning ):
340
- lock = asyncio .Lock (loop = self .loop )
341
-
342
- try :
343
- with lock :
344
- self .fail ('RuntimeError is not raised in with expression' )
345
- except RuntimeError as err :
346
- self .assertEqual (
347
- str (err ),
348
- '"yield from" should be used as context manager expression' )
349
-
350
- self .assertFalse (lock .locked ())
306
+ self .loop .run_until_complete (f ())
351
307
352
308
353
309
class EventTests (test_utils .TestCase ):
@@ -809,33 +765,14 @@ def test_repr(self):
809
765
self .assertTrue (RGX_REPR .match (repr (cond )))
810
766
811
767
def test_context_manager (self ):
812
- with self .assertWarns (DeprecationWarning ):
813
- cond = asyncio .Condition (loop = self .loop )
814
-
815
- with self .assertWarns (DeprecationWarning ):
816
- @asyncio .coroutine
817
- def acquire_cond ():
818
- with self .assertWarns (DeprecationWarning ):
819
- return (yield from cond )
820
-
821
- with self .loop .run_until_complete (acquire_cond ()):
822
- self .assertTrue (cond .locked ())
823
-
824
- self .assertFalse (cond .locked ())
825
-
826
- def test_context_manager_no_yield (self ):
827
- with self .assertWarns (DeprecationWarning ):
828
- cond = asyncio .Condition (loop = self .loop )
829
-
830
- try :
831
- with cond :
832
- self .fail ('RuntimeError is not raised in with expression' )
833
- except RuntimeError as err :
834
- self .assertEqual (
835
- str (err ),
836
- '"yield from" should be used as context manager expression' )
768
+ async def f ():
769
+ cond = asyncio .Condition ()
770
+ self .assertFalse (cond .locked ())
771
+ async with cond :
772
+ self .assertTrue (cond .locked ())
773
+ self .assertFalse (cond .locked ())
837
774
838
- self .assertFalse ( cond . locked ())
775
+ self .loop . run_until_complete ( f ())
839
776
840
777
def test_explicit_lock (self ):
841
778
with self .assertWarns (DeprecationWarning ):
@@ -920,16 +857,14 @@ def test_semaphore(self):
920
857
with self .assertWarns (DeprecationWarning ):
921
858
@asyncio .coroutine
922
859
def acquire_lock ():
923
- with self .assertWarns (DeprecationWarning ):
924
- return (yield from sem )
860
+ return (yield from sem )
925
861
926
- res = self .loop . run_until_complete ( acquire_lock ())
927
-
928
- self . assertTrue ( res )
929
- self . assertTrue ( sem . locked ())
930
- self .assertEqual ( 0 , sem . _value )
862
+ with self .assertRaisesRegex (
863
+ TypeError ,
864
+ "'Semaphore' object is not iterable" ,
865
+ ):
866
+ self .loop . run_until_complete ( acquire_lock () )
931
867
932
- sem .release ()
933
868
self .assertFalse (sem .locked ())
934
869
self .assertEqual (1 , sem ._value )
935
870
@@ -1064,38 +999,6 @@ def test_release_no_waiters(self):
1064
999
sem .release ()
1065
1000
self .assertFalse (sem .locked ())
1066
1001
1067
- def test_context_manager (self ):
1068
- with self .assertWarns (DeprecationWarning ):
1069
- sem = asyncio .Semaphore (2 , loop = self .loop )
1070
-
1071
- @asyncio .coroutine
1072
- def acquire_lock ():
1073
- with self .assertWarns (DeprecationWarning ):
1074
- return (yield from sem )
1075
-
1076
- with self .loop .run_until_complete (acquire_lock ()):
1077
- self .assertFalse (sem .locked ())
1078
- self .assertEqual (1 , sem ._value )
1079
-
1080
- with self .loop .run_until_complete (acquire_lock ()):
1081
- self .assertTrue (sem .locked ())
1082
-
1083
- self .assertEqual (2 , sem ._value )
1084
-
1085
- def test_context_manager_no_yield (self ):
1086
- with self .assertWarns (DeprecationWarning ):
1087
- sem = asyncio .Semaphore (2 , loop = self .loop )
1088
-
1089
- try :
1090
- with sem :
1091
- self .fail ('RuntimeError is not raised in with expression' )
1092
- except RuntimeError as err :
1093
- self .assertEqual (
1094
- str (err ),
1095
- '"yield from" should be used as context manager expression' )
1096
-
1097
- self .assertEqual (2 , sem ._value )
1098
-
1099
1002
1100
1003
if __name__ == '__main__' :
1101
1004
unittest .main ()
0 commit comments