a
    ø£Be  ã                   @   s|   d dl Z d dlmZ d dlZd dlZd dlmZmZ edd„ ƒZdd„ Z	dd	„ Z
d
d„ Zejj dd„ ƒZejj dd„ ƒZdS )é    N)Ú	MagicMock)Úrun_hookÚrun_syncc                   Ã   s   t  d¡I d H  dS )Ng{®Gáz„?é*   )ÚasyncioÚsleep© r   r   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbclient/tests/test_util.pyÚsome_async_function
   s    r
   c                  C   s6   dd„ } t  ¡ }t  |¡ | | ƒ ¡}||u s2J ‚d S )Nc                   Ó   s   t ƒ dksJ ‚t ¡ S ©Nr   )r
   r   Úget_running_loopr   r   r   r	   Ú_test   s    z7test_nested_asyncio_with_existing_ioloop.<locals>._test)r   Únew_event_loopÚset_event_loopÚrun_until_complete)r   ÚloopZ
event_loopr   r   r	   Ú(test_nested_asyncio_with_existing_ioloop   s
    
r   c                   C   s   t  d ¡ tƒ dksJ ‚d S r   )r   r   r
   r   r   r   r	   Ú"test_nested_asyncio_with_no_ioloop   s    
r   c                     sN   t  t  ¡ ¡ tjj ¡ ‰ ‡ fdd„‰‡fdd„‰‡‡fdd„} ˆ  | ¡ d S )Nc                  “   s.   t  t  d¡¡} ˆ  | dd„ ¡ | I d H  dS )Ngš™™™™™¹?c                 S   s   |   ¡ S ©N)Úresult)Úfr   r   r	   Ú<lambda>)   ó    zOtest_nested_asyncio_with_tornado.<locals>.some_async_function.<locals>.<lambda>r   )r   Úensure_futurer   Z
add_future)Úfuture)Úioloopr   r	   r
   &   s    
z=test_nested_asyncio_with_tornado.<locals>.some_async_functionc                      s
   t ˆ ƒƒ S r   )r   r   )r
   r   r	   Úsome_sync_function-   s    z<test_nested_asyncio_with_tornado.<locals>.some_sync_functionc                   “   s&   ˆ ƒ I d H dksJ ‚ˆƒ dks"J ‚d S r   r   r   )r
   r   r   r	   Úrun0   s    z-test_nested_asyncio_with_tornado.<locals>.run)r   r   r   Útornador   ZIOLoopÚcurrentr   )r   r   )r   r
   r   r	   Ú test_nested_asyncio_with_tornado    s    r    c                  Ã   s&   t ƒ } t| ƒI d H  | jdks"J ‚d S )Né   )r   r   Ú
call_count)r   r   r   r	   Útest_run_hook_sync8   s    r#   c                  Ã   s,   t tƒ d�} t| ƒI d H  | jdks(J ‚d S )N)Zreturn_valuer!   )r   r
   r   r"   )Úhookr   r   r	   Útest_run_hook_async?   s    r%   )r   Zunittest.mockr   Zpytestr   Znbclient.utilr   r   r
   r   r   r    Úmarkr#   r%   r   r   r   r	   Ú<module>   s   

