U
    œËúgš5  ã                   @  s6  d dl mZ d dlZd dlZd dlmZ d dlmZ d dlZd dl	Z	d dl
mZmZ ejdk rjd dlmZ ddd	œd
d„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœd d!„Zddœd"d#„Zddœd$d%„Zd&dd'œd(d)„ZdS )*é    )ÚannotationsN)ÚTracebackType)ÚAny)ÚMatcherÚRaisesGroup)é   é   )ÚExceptionGroupÚstr)ÚsÚreturnc                 C  s   dt  | ¡ d S )Nú^ú$)ÚreÚescape)r   © r   úH/tmp/pip-unpacked-wheel-ks04xdmi/trio/_tests/test_testing_raisesgroup.pyÚwrap_escape   s    r   ÚNone)r   c                
   C  s>  t jttdtƒ ›dƒd ttƒ ƒ W 5 Q R X ttƒ tdtƒ fƒ‚W 5 Q R X ttƒ( ttƒ tdtƒ fƒ‚W 5 Q R X W 5 Q R X tttƒ tdtƒ tƒ fƒ‚W 5 Q R X tttƒ tdtƒ tƒ fƒ‚W 5 Q R X tttƒƒ tdtdtƒ fƒfƒ‚W 5 Q R X ttttƒttƒƒ, tdtƒ tdtƒ fƒtdtƒ fƒfƒ‚W 5 Q R X t  t¡, ttƒ tdtƒ tƒ fƒ‚W 5 Q R X W 5 Q R X t  t¡, ttƒ tdtƒ tƒ fƒ‚W 5 Q R X W 5 Q R X t  t¡* tttƒ tdtƒ fƒ‚W 5 Q R X W 5 Q R X t  t¡* tttƒ tdtƒ fƒ‚W 5 Q R X W 5 Q R X d S )NzInvalid argument "z2" must be exception type, Matcher, or RaisesGroup.©ÚmatchÚfooÚbarÚ )	ÚpytestÚraisesÚ
ValueErrorr   Ú	TypeErrorr   r	   ÚSyntaxErrorÚRuntimeErrorr   r   r   r   Útest_raises_group   sT    ÿþ


" ýýþ

&
&"r    c                
   C  sp  t tdd tdtdtƒ fƒfƒ‚W 5 Q R X t ttdd  tdtdtƒ tƒ fƒfƒ‚W 5 Q R X t ttdd  tdtdtƒ gƒtƒ gƒ‚W 5 Q R X t t tddƒ tdtdtƒ fƒfƒ‚W 5 Q R X t t tddƒ$ tdtdtdtƒ fƒfƒfƒ‚W 5 Q R X t t¡0 t t tddƒ tdtƒ fƒ‚W 5 Q R X W 5 Q R X tjtdd t t tƒdd W 5 Q R X d S )NT)Úflatten_subgroupsr   z@^You cannot specify a nested structure inside a RaisesGroup withr   )r   r   r	   r   r   r   r   r   r   r   Útest_flatten_subgroupsR   s*     $$ þ"þr"   c                
   C  sÐ  t tdd
 t‚W 5 Q R X tjtdd t ttdd W 5 Q R X t tdd„ ddd
 t‚W 5 Q R X tjtdd t t tƒdd W 5 Q R X t t tddƒ td	td	tƒ gƒgƒ‚W 5 Q R X t t tddƒ td	tƒ gƒ‚W 5 Q R X tjtd
d" t tƒ tdƒ‚W 5 Q R X W 5 Q R X t t¡4 t tdd td	td	tƒ gƒgƒ‚W 5 Q R X W 5 Q R X t tddd td	td	tƒ gƒgƒ‚W 5 Q R X t t¡" t tdd
 t‚W 5 Q R X W 5 Q R X d S )NT©Úallow_unwrappedz,^You cannot specify multiple exceptions withr   c                 S  s   t | ttfƒS ©N)Ú
isinstancer   r   ©Úer   r   r   Ú<lambda>   ó    z1test_catch_unwrapped_exceptions.<locals>.<lambda>©Úcheckzhas no effect when expectingr   z^value error text$zvalue error text)r$   r!   )r   r   r   r   r   r   r	   r   r   r   r   r   Útest_catch_unwrapped_exceptionsp   s:    þþ 
* r-   c               
   C  sô   t tdd tdtƒ fƒ‚W 5 Q R X t tdd tdtƒ fƒ‚W 5 Q R X t tdd" tdtƒ fƒ} |  d¡ | ‚W 5 Q R X t tdd" tdtƒ fƒ} |  d¡ | ‚W 5 Q R X t t¡, t tdd tdtƒ fƒ‚W 5 Q R X W 5 Q R X d S )Nr   r   ú^bar$zmy notez^bar
my note$r   )r   r   r	   Zadd_noter   r   r'   r   r   r   Ú
test_match£   s    

r/   c                
     sz   t dtƒ fƒ‰ tt‡ fdd„d
 ˆ ‚W 5 Q R X t t ¡4 tt‡ fdd„d t dtƒ fƒ‚W 5 Q R X W 5 Q R X d S )Nr   c                   s   | ˆ kS r%   r   ©Úx©Úexcr   r   r)   À   r*   ztest_check.<locals>.<lambda>r+   c                   s   | ˆ kS r%   r   r0   r2   r   r   r)   Ã   r*   )r	   r   r   r   r   r   r   r2   r   Ú
test_check¾   s    r4   c               	   C  s  dddœdd„} d}t jtt |¡d ttdd	d
 W 5 Q R X t jtt |¡d ttd| d W 5 Q R X tttdddd}| td	ƒ‚W 5 Q R X | tdtd	ƒgƒ‚W 5 Q R X ttdd}tdtd	ƒgƒ‚W 5 Q R X t|j	tƒrttdd 
|j	¡st‚d S )NÚobjectÚbool©r(   r   c                 S  s   dS )NTr   r'   r   r   r   Úmy_checkÈ   s    z,test_unwrapped_match_check.<locals>.my_checkav  `allow_unwrapped=True` bypasses the `match` and `check` parameters if the exception is unwrapped. If you intended to match/check the exception you should use a `Matcher` object. If you want to match/check the exceptiongroup when the exception *is* wrapped you need to do e.g. `if isinstance(exc.value, ExceptionGroup): assert RaisesGroup(...).matches(exc.value)` afterwards.r   Tr   )r$   r   )r$   r,   z^foo$r#   r   r   )r   r   r   r   r   r   r   r	   r&   ÚvalueÚmatchesÚAssertionError)r8   ÚmsgÚrgr3   r   r   r   Útest_unwrapped_match_checkÇ   s     ÿr>   c                  C  sB   t tƒ} |  d ¡rt‚|  tƒ ¡r&t‚|  tdtƒ fƒ¡s>t‚d S )Nr   )r   r   r:   r;   r	   )r=   r   r   r   Útest_RaisesGroup_matchesæ   s    r?   c                  C  s¸   ddddœdd„} | dt tƒƒ | dt ttƒƒ | d	t t tƒƒƒ | d
t ttdƒƒƒ | dt tddƒƒ | dt tƒƒ | dt ttƒƒƒ | dt t tƒƒƒ | dt t tƒt tƒƒƒ d S )Nr
   zRaisesGroup[Any]r   )ÚmessageÚbodyr   c              
   S  s<   t jtdt | ¡› dd | W 5 Q R X W 5 Q R X d S )Nz'^DID NOT RAISE any exception, expected r   r   )r   r   r;   r   r   )r@   rA   r   r   r   Úcheck_messageî   s    þz#test_message.<locals>.check_messagezExceptionGroup(ValueError)z&ExceptionGroup(ValueError, ValueError)z*ExceptionGroup(ExceptionGroup(ValueError))z3ExceptionGroup(Matcher(ValueError, match='my_str'))Zmy_strz'ExceptionGroup(Matcher(match='my_str'))r   z%BaseExceptionGroup(KeyboardInterrupt)z.BaseExceptionGroup(Matcher(KeyboardInterrupt))z9BaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt))zUBaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt), ExceptionGroup(ValueError)))r   r   r   ÚKeyboardInterrupt)rB   r   r   r   Útest_messageí   sD    	þ
þþþþ
þ
þþrD   c                
   C  sº   t jtdd tƒ  W 5 Q R X t jtdt ttƒ¡› dd ttƒ W 5 Q R X tttƒƒ t	dtƒ fƒ‚W 5 Q R X t  t	¡, ttt
ƒƒ t	dtƒ fƒ‚W 5 Q R X W 5 Q R X d S )Nz6^You must specify at least one parameter to match on.$r   z^exception_type z% must be a subclass of BaseException$r   )r   r   r   r   r   r   Úreprr5   r   r	   r   r   r   r   r   Útest_matcher#  s    þþrF   c                
   C  sF  t ttdƒƒ tdtdƒfƒ‚W 5 Q R X t t¡0 t ttdƒƒ tdtdƒfƒ‚W 5 Q R X W 5 Q R X t tddƒ tdtdƒfƒ‚W 5 Q R X t t¡0 t tddƒ tdtdƒfƒ‚W 5 Q R X W 5 Q R X t ttddƒ tdtdƒgƒ‚W 5 Q R X t t¡2 t ttddƒ tdtdƒgƒ‚W 5 Q R X W 5 Q R X d S )Nr   r   r   r   r.   Zbarr)r   r   r   r	   r   r   r   r   r   r   Útest_matcher_match6  s    $$rG   c               
   C  sÂ   dddœdd„} t t| dƒ tdtddƒfƒ‚W 5 Q R X d	ddœd
d„}t tt|dƒ tdtddƒfƒ‚W 5 Q R X t t¡4 t tt|dƒ tdtddƒfƒ‚W 5 Q R X W 5 Q R X d S )NÚBaseExceptionr6   r7   c                 S  s   t | tƒo| jdkS ©Né   )r&   ÚOSErrorÚerrnor'   r   r   r   Úcheck_oserror_and_errno_is_5M  s    z8test_Matcher_check.<locals>.check_oserror_and_errno_is_5r+   r   rJ   rK   c                 S  s
   | j dkS rI   )rL   r'   r   r   r   Úcheck_errno_is_5T  s    z,test_Matcher_check.<locals>.check_errno_is_5é   )r   r   r	   rK   r   r   )rM   rN   r   r   r   Útest_Matcher_checkL  s    rP   c                  C  sž   t ttƒƒdkst‚t tddƒdks*t‚t dd¡} t t| dƒdksLt‚t dtj¡}t t|dƒd|›d	ksxt‚t ttd
tdƒdt›d	ksšt‚d S )NzMatcher(ValueError)z[a-z]r   zMatcher(match='[a-z]')Znoflagr   zMatcher(match='noflag')zMatcher(match=ú)r   )r   r,   z&Matcher(ValueError, match='re', check=)r
   r   r   r;   r   ÚcompileÚ
IGNORECASEr6   )Zpattern_no_flagsZpattern_flagsr   r   r   Útest_matcher_tostring_  s    
ÿÿrT   zpytest.MonkeyPatch)Úmonkeypatchr   c              	   C  sx   |   tjjdtjjj¡ tj t¡}tdtdƒfƒ‚W 5 Q R X |jtksNt	‚|j
jd jdksdt	‚t|jtƒstt	‚d S )NZExceptionInfor   Úhellor   )rV   )ÚsetattrÚtrioZtestingZ_raises_groupZ_ExceptionInfor   r   r	   Útyper;   r9   Ú
exceptionsÚargsr&   Útbr   )rU   Úexcinfor   r   r   Útest__ExceptionInfol  s    ýr^   )Ú
__future__r   r   ÚsysÚtypesr   Útypingr   r   rX   Ztrio.testingr   r   Úversion_infoZexceptiongroupr	   r   r    r"   r-   r/   r4   r>   r?   rD   rF   rG   rP   rT   r^   r   r   r   r   Ú<module>   s.   
=3	6