@@ -252,6 +252,36 @@ async def test_result_iteration(method, records):
252
252
await fetch_and_compare_all_records (result , "x" , records , method )
253
253
254
254
255
+ @mark_async_test
256
+ async def test_result_iteration_mixed_methods ():
257
+ records = [[i ] for i in range (10 )]
258
+ connection = AsyncConnectionStub (records = Records (["x" ], records ))
259
+ result = AsyncResult (connection , HydratorStub (), 4 , noop , noop )
260
+ await result ._run ("CYPHER" , {}, None , None , "r" , None )
261
+ iter1 = AsyncUtil .iter (result )
262
+ iter2 = AsyncUtil .iter (result )
263
+ assert (await AsyncUtil .next (iter1 )).get ("x" ) == records [0 ][0 ]
264
+ assert (await AsyncUtil .next (iter2 )).get ("x" ) == records [1 ][0 ]
265
+ assert (await AsyncUtil .next (iter2 )).get ("x" ) == records [2 ][0 ]
266
+ assert (await AsyncUtil .next (iter1 )).get ("x" ) == records [3 ][0 ]
267
+ assert (await AsyncUtil .next (iter1 )).get ("x" ) == records [4 ][0 ]
268
+ assert (await AsyncUtil .next (result )).get ("x" ) == records [5 ][0 ]
269
+ assert (await AsyncUtil .next (iter2 )).get ("x" ) == records [6 ][0 ]
270
+ assert (await AsyncUtil .next (iter1 )).get ("x" ) == records [7 ][0 ]
271
+ assert ((await AsyncUtil .next (AsyncUtil .iter (result ))).get ("x" )
272
+ == records [8 ][0 ])
273
+ assert [r .get ("x" ) async for r in result ] == [records [9 ][0 ]]
274
+ with pytest .raises (StopAsyncIteration ):
275
+ await AsyncUtil .next (iter1 )
276
+ with pytest .raises (StopAsyncIteration ):
277
+ await AsyncUtil .next (iter2 )
278
+ with pytest .raises (StopAsyncIteration ):
279
+ await AsyncUtil .next (result )
280
+ with pytest .raises (StopAsyncIteration ):
281
+ await AsyncUtil .next (AsyncUtil .iter (result ))
282
+ assert [r .get ("x" ) async for r in result ] == []
283
+
284
+
255
285
@pytest .mark .parametrize ("method" ,
256
286
("for loop" , "next" , "one iter" , "new iter" ))
257
287
@pytest .mark .parametrize ("invert_fetch" , (True , False ))
0 commit comments