File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -362,6 +362,39 @@ async fn test_async_gen_v2() -> PyResult<()> {
362362 Ok ( ( ) )
363363}
364364
365+ #[ cfg( feature = "unstable-streams" ) ]
366+ const TOKIO_TEST_MOD_FASTGEN : & str = r#"
367+ import asyncio
368+
369+ async def gen():
370+ for i in range(1000):
371+ yield i
372+ "# ;
373+
374+ #[ cfg( feature = "unstable-streams" ) ]
375+ #[ pyo3_async_runtimes:: tokio:: test]
376+ async fn test_async_gen_full_buffer ( ) -> PyResult < ( ) > {
377+ let stream = Python :: attach ( |py| {
378+ let test_mod = PyModule :: from_code (
379+ py,
380+ & CString :: new ( TOKIO_TEST_MOD_FASTGEN ) . unwrap ( ) ,
381+ & CString :: new ( "test_rust_coroutine/tokio_test_mod.py" ) . unwrap ( ) ,
382+ & CString :: new ( "tokio_test_mod" ) . unwrap ( ) ,
383+ ) ?;
384+
385+ pyo3_async_runtimes:: tokio:: into_stream_v2 ( test_mod. call_method0 ( "gen" ) ?)
386+ } ) ?;
387+
388+ let vals = stream
389+ . map ( |item| Python :: attach ( |py| -> PyResult < i32 > { item. bind ( py) . extract ( ) } ) )
390+ . try_collect :: < Vec < i32 > > ( )
391+ . await ?;
392+
393+ assert_eq ! ( ( 0 ..1000 ) . collect:: <Vec <i32 >>( ) , vals) ;
394+
395+ Ok ( ( ) )
396+ }
397+
365398const CONTEXTVARS_CODE : & str = r#"
366399cx = contextvars.ContextVar("cx")
367400
You can’t perform that action at this time.
0 commit comments