o
    Ci                     @   s   d dl Z ddlmZmZmZmZ edd Zdd Zdd	 Zd
Z	ze
d W n ey1   dZ	Y nw e jje	 dddd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    N   )aclosingasync_generatoryield_asynccontextmanagerc                    sB   zt | D ]	}t|I d H  qW d S  ty    d|d< Y d S w )NTr   )ranger   GeneratorExit)countclosed_sloti r   S/home/kuhnn/.local/lib/python3.10/site-packages/async_generator/_tests/test_util.pyasync_range   s   r   c               	      s@  dg} t td| 4 I d H )}ttd}|2 z3 d H W }|t|ks&J |dkr, nq6 W d   I d H  n1 I d H s>w   Y  | d sIJ dg} zBt td| 4 I d H *}ttd}|2 z3 d H W }|t|ksoJ |dkrvt qa6 W d   I d H  n1 I d H sw   Y  W n	 ty   Y nw | d sJ d S )NF
      r   )r   r   iterr   next
ValueError)r
   genititemr   r   r   test_aclosing   s8   ((r   c               
      s
  t tdd } tt}|  4 I d H  t1 I d H sw   Y  W d    n1 s.w   Y  |jjd dks=J t|jj	tsFJ tt!}|  4 I d H  t
d}|1 I d H s`w   Y  W d    n1 sow   Y  |jjd dks~J |jj	}|jd dksJ |j	|u sJ tt}|  4 I d H  td1 I d H sw   Y  W d    n1 sw   Y  |jjd dksJ |jj	d u sJ t tdd }tt
 | 4 I d H  t
1 I d H sw   Y  W d    d S 1 sw   Y  d S )	Nc               
      s8   z	t  I d H  W d S  ty }  ztd| d } ~ ww )Nissue29692:Chained)r   	ExceptionRuntimeError)excr   r   r   manager_issue29692'   s   
z[test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.manager_issue29692r   r   issue29692:Unchainedzgenerator raised StopIterationc                         t  I d H  d S Nr   r   r   r   r   noop_async_context_managerF      zctest_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.noop_async_context_manager)r   r   pytestraisesr   ZeroDivisionErrorvalueargs
isinstance	__cause__StopIterationStopAsyncIteration)r   excinfor   causer!   r   r   r   ?test_contextmanager_do_not_unchain_non_stopiteration_exceptions&   sH   "r.   Tz
@asynccontextmanager
async def manager_issue29692_2():
    try:
        yield
    except Exception as exc:
        raise RuntimeError('issue29692:Chained') from exc
Fz1Python < 3.6 doesn't have native async generators)reasonc                     s
  t t} t 4 I d H  t1 I d H sw   Y  W d    n1 s&w   Y  | jjd dks5J t| jjts>J t	t
fD ]@}t |} t 4 I d H  |d1 I d H s\w   Y  W d    n1 skw   Y  | jjd dkszJ | jjd u sJ qBd S )Nr   r   r   )r#   r$   r   manager_issue29692_2r%   r&   r'   r(   r)   r*   r+   )r,   clsr   r   r   Ftest_native_contextmanager_do_not_unchain_non_stopiteration_exceptionsa   s"   r2   c                     s   t tdd } tttfD ],}t| |  4 I d H  |1 I d H s&w   Y  W d    n1 s5w   Y  q|  4 I d H  W d   I d H  d S 1 I d H sTw   Y  d S )Nc                      r   r   r    r   r   r   r   r!   x   r"   zRtest_asynccontextmanager_exception_passthrough.<locals>.noop_async_context_manager)r   r   r+   r   r   r#   r$   )r!   exc_typer   r   r   .test_asynccontextmanager_exception_passthroughv   s   .r4   c               	      s@   t tdd } |  4 I d H  t1 I d H sw   Y  d S )Nc                      s>   t t t I d H  W d    d S 1 sw   Y  d S r   )r#   r$   r   r   r   r   r   r   catch_it   s   "z<test_asynccontextmanager_catches_exception.<locals>.catch_it)r   r   r   )r5   r   r   r   *test_asynccontextmanager_catches_exception   s   r6   c               
      sl   t tdd } tt |  4 I d H  t1 I d H sw   Y  W d    d S 1 s/w   Y  d S )Nc                      s(   z	t  I d H  W d S  ty   tw r   )r   KeyErrorr   r   r   r   r   	switch_it   s   z?test_asynccontextmanager_different_exception.<locals>.switch_it)r   r   r#   r$   r   r7   )r8   r   r   r   ,test_asynccontextmanager_different_exception   s   "r9   c               	      s   t tdd } |  }tt}| W d    n1 sw   Y  W d    n1 s.w   Y  dt|jv s<J |4 I d H  W d   I d H  d S 1 I d H sTw   Y  d S )Nc                      r   r   r    r   r   r   r   xxx   r"   z@test_asynccontextmanager_nice_message_on_sync_enter.<locals>.xxxz
async withr   r   r#   r$   r   strr&   )r:   cmr,   r   r   r   3test_asynccontextmanager_nice_message_on_sync_enter   s   .r>   c               
      s|   t tdd } tt}|  4 I d H  J 1 I d H sw   Y  W d    n1 s.w   Y  dt|jv s<J d S )Nc                      s   d S r   r   r   r   r   r   yeehaw   s   z1test_asynccontextmanager_no_yield.<locals>.yeehawFzdidn't yieldr;   )r?   r,   r   r   r   !test_asynccontextmanager_no_yield   s   r@   c               
      s  d t t fdd} tt%}|  4 I d H  W d   I d H  n1 I d H s+w   Y  W d    n1 s:w   Y  dt|jv sHJ  dksNJ tt}|  4 I d H  t1 I d H sdw   Y  W d    n1 ssw   Y  dt|jv sJ  dksJ d S )Nr   c                      sL   zt  I d H  W n	 ty   Y nw zt  I d H  W  d7  d S  d7  w )N   )r   r   r   closed_countr   r   doubleyield   s   z=test_asynccontextmanager_too_many_yields.<locals>.doubleyieldzdidn't stoprA   zdidn't stop after athrowr   )r   r   r#   r$   r   r<   r&   r   )rD   r,   r   rB   r   (test_asynccontextmanager_too_many_yields   s(   (rE   c                     s>   t t tdd } W d    d S 1 sw   Y  d S )Nc                   s   s    d V  d S r   r   r   r   r   r   syncgen   s   
zCtest_asynccontextmanager_requires_asyncgenfunction.<locals>.syncgen)r#   r$   	TypeErrorr   )rF   r   r   r   2test_asynccontextmanager_requires_asyncgenfunction   s
   "rH   )r#    r   r   r   r   r   r   r.   nativeasyncgeneratorsexecSyntaxErrormarkskipifr2   r4   r6   r9   r>   r@   rE   rH   r   r   r   r   <module>   s4    
+

