1+ import asyncio
12from operator import add
23import random
34import time
1617
1718
1819@gen_cluster (client = True )
19- def test_map (c , s , a , b ):
20+ async def test_map (c , s , a , b ):
2021 source = Stream (asynchronous = True )
2122 futures = scatter (source ).map (inc )
2223 futures_L = futures .sink_to_list ()
2324 L = futures .gather ().sink_to_list ()
2425
2526 for i in range (5 ):
26- yield source .emit (i )
27+ await source .emit (i )
2728
2829 assert L == [1 , 2 , 3 , 4 , 5 ]
2930 assert all (isinstance (f , Future ) for f in futures_L )
3031
3132
3233@gen_cluster (client = True )
33- def test_map_on_dict (c , s , a , b ):
34+ async def test_map_on_dict (c , s , a , b ):
3435 # dask treats dicts differently, so we have to make sure
3536 # the user sees no difference in the streamz api.
3637 # Regression test against #336
@@ -43,7 +44,7 @@ def add_to_dict(d):
4344 L = futures .gather ().sink_to_list ()
4445
4546 for i in range (5 ):
46- yield source .emit ({"i" : i })
47+ await source .emit ({"i" : i })
4748
4849 assert len (L ) == 5
4950 for i , item in enumerate (sorted (L , key = lambda x : x ["x" ])):
@@ -52,7 +53,7 @@ def add_to_dict(d):
5253
5354
5455@gen_cluster (client = True )
55- def test_partition_then_scatter_async (c , s , a , b ):
56+ async def test_partition_then_scatter_async (c , s , a , b ):
5657 # Ensure partition w/ timeout before scatter works correctly for
5758 # asynchronous
5859 start = time .monotonic ()
@@ -63,10 +64,10 @@ def test_partition_then_scatter_async(c, s, a, b):
6364
6465 rc = RefCounter (loop = source .loop )
6566 for i in range (3 ):
66- yield source .emit (i , metadata = [{'ref' : rc }])
67+ await source .emit (i , metadata = [{'ref' : rc }])
6768
6869 while rc .count != 0 and time .monotonic () - start < 1. :
69- yield gen .sleep (1e-2 )
70+ await gen .sleep (1e-2 )
7071
7172 assert L == [1 , 2 , 3 ]
7273
@@ -92,7 +93,7 @@ def test_partition_then_scatter_sync(loop):
9293
9394
9495@gen_cluster (client = True )
95- def test_non_unique_emit (c , s , a , b ):
96+ async def test_non_unique_emit (c , s , a , b ):
9697 """Regression for https://github.com/python-streamz/streams/issues/397
9798
9899 Non-unique stream entries still need to each be processed.
@@ -103,28 +104,28 @@ def test_non_unique_emit(c, s, a, b):
103104
104105 for _ in range (3 ):
105106 # Emit non-unique values
106- yield source .emit (0 )
107+ await source .emit (0 )
107108
108109 assert len (L ) == 3
109110 assert L [0 ] != L [1 ] or L [0 ] != L [2 ]
110111
111112
112113@gen_cluster (client = True )
113- def test_scan (c , s , a , b ):
114+ async def test_scan (c , s , a , b ):
114115 source = Stream (asynchronous = True )
115116 futures = scatter (source ).map (inc ).scan (add )
116117 futures_L = futures .sink_to_list ()
117118 L = futures .gather ().sink_to_list ()
118119
119120 for i in range (5 ):
120- yield source .emit (i )
121+ await source .emit (i )
121122
122123 assert L == [1 , 3 , 6 , 10 , 15 ]
123124 assert all (isinstance (f , Future ) for f in futures_L )
124125
125126
126127@gen_cluster (client = True )
127- def test_scan_state (c , s , a , b ):
128+ async def test_scan_state (c , s , a , b ):
128129 source = Stream (asynchronous = True )
129130
130131 def f (acc , i ):
@@ -133,33 +134,33 @@ def f(acc, i):
133134
134135 L = scatter (source ).scan (f , returns_state = True ).gather ().sink_to_list ()
135136 for i in range (3 ):
136- yield source .emit (i )
137+ await source .emit (i )
137138
138139 assert L == [0 , 1 , 3 ]
139140
140141
141142@gen_cluster (client = True )
142- def test_zip (c , s , a , b ):
143+ async def test_zip (c , s , a , b ):
143144 a = Stream (asynchronous = True )
144145 b = Stream (asynchronous = True )
145146 c = scatter (a ).zip (scatter (b ))
146147
147148 L = c .gather ().sink_to_list ()
148149
149- yield a .emit (1 )
150- yield b .emit ('a' )
151- yield a .emit (2 )
152- yield b .emit ('b' )
150+ await a .emit (1 )
151+ await b .emit ('a' )
152+ await a .emit (2 )
153+ await b .emit ('b' )
153154
154155 assert L == [(1 , 'a' ), (2 , 'b' )]
155156
156157
157158@gen_cluster (client = True )
158- def test_accumulate (c , s , a , b ):
159+ async def test_accumulate (c , s , a , b ):
159160 source = Stream (asynchronous = True )
160161 L = source .scatter ().accumulate (lambda acc , x : acc + x , with_state = True ).gather ().sink_to_list ()
161162 for i in range (3 ):
162- yield source .emit (i )
163+ await source .emit (i )
163164 assert L [- 1 ][1 ] == 3
164165
165166
@@ -169,10 +170,9 @@ def test_sync(loop): # noqa: F811
169170 source = Stream ()
170171 L = source .scatter ().map (inc ).gather ().sink_to_list ()
171172
172- @gen .coroutine
173- def f ():
173+ async def f ():
174174 for i in range (10 ):
175- yield source .emit (i , asynchronous = True )
175+ await source .emit (i , asynchronous = True )
176176
177177 sync (loop , f )
178178
@@ -193,24 +193,24 @@ def test_sync_2(loop): # noqa: F811
193193
194194
195195@gen_cluster (client = True , nthreads = [('127.0.0.1' , 1 )] * 2 )
196- def test_buffer (c , s , a , b ):
196+ async def test_buffer (c , s , a , b ):
197197 source = Stream (asynchronous = True )
198198 L = source .scatter ().map (slowinc , delay = 0.5 ).buffer (5 ).gather ().sink_to_list ()
199199
200200 start = time .time ()
201201 for i in range (5 ):
202- yield source .emit (i )
202+ await source .emit (i )
203203 end = time .time ()
204204 assert end - start < 0.5
205205
206206 for i in range (5 , 10 ):
207- yield source .emit (i )
207+ await source .emit (i )
208208
209209 end2 = time .time ()
210210 assert end2 - start > (0.5 / 3 )
211211
212212 while len (L ) < 10 :
213- yield gen .sleep (0.01 )
213+ await gen .sleep (0.01 )
214214 assert time .time () - start < 5
215215
216216 assert L == list (map (inc , range (10 )))
@@ -242,7 +242,7 @@ def test_buffer_sync(loop): # noqa: F811
242242
243243
244244@pytest .mark .xfail (reason = '' )
245- def test_stream_shares_client_loop (loop ): # noqa: F811
245+ async def test_stream_shares_client_loop (loop ): # noqa: F811
246246 with cluster () as (s , [a , b ]):
247247 with Client (s ['address' ], loop = loop ) as client : # noqa: F841
248248 source = Stream ()
@@ -251,14 +251,14 @@ def test_stream_shares_client_loop(loop): # noqa: F811
251251
252252
253253@gen_cluster (client = True )
254- def test_starmap (c , s , a , b ):
254+ async def test_starmap (c , s , a , b ):
255255 def add (x , y , z = 0 ):
256256 return x + y + z
257257
258258 source = Stream (asynchronous = True )
259259 L = source .scatter ().starmap (add , z = 10 ).gather ().sink_to_list ()
260260
261261 for i in range (5 ):
262- yield source .emit ((i , i ))
262+ await source .emit ((i , i ))
263263
264264 assert L == [10 , 12 , 14 , 16 , 18 ]
0 commit comments