
    g5                        d dl mZ d dlZ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j                  dk  rd dlmZ 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dZddZddZddZddZddZy)    )annotationsN)TracebackType)MatcherRaisesGroup)      )ExceptionGroupc                8    dt        j                  |       z   dz   S )N^$)reescape)ss    W/var/www/html/venv/lib/python3.12/site-packages/trio/_tests/test_testing_raisesgroup.pywrap_escaper      s    1##    c                 r   t        j                  t        t        dt	               d            5  t        t	                      d d d        t        t              5  t        dt               f      # 1 sw Y   .xY w# 1 sw Y   nxY wt        t              5  t        t              5  t        dt               f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        t        t              5  t        dt               t               f      # 1 sw Y   nxY wt        t        t              5  t        dt               t               f      # 1 sw Y   nxY wt        t        t                    5  t        dt        dt               f      f      # 1 sw Y   nxY wt        t        t        t              t        t                    5  t        dt               t        dt               f      t        dt               f      f      # 1 sw Y   nxY wt        j                  t              5  t        t              5  t        dt               t               f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        j                  t              5  t        t              5  t        dt               t               f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        j                  t              5  t        t        t              5  t        dt               f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        j                  t              5  t        t        t              5  t        dt               f      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)NzInvalid argument "z2" must be exception type, Matcher, or RaisesGroup.matchfoobar )	pytestraises
ValueErrorr   	TypeErrorr   r	   SyntaxErrorRuntimeError r   r   test_raises_groupr       s1   	 /ab

 ! 	IK ! 
Z	  5UZ\O44! !5 5 
[	! :$ 	: (899	: 	: 	:: : :
 
Z	- CUZ\;=$ABBC C 
[*	- CUZ\;=$ABBC C 
[,	- OU^EJL?%K$MNNO O 
JL!
 

 uz|o6rLN#45
 	

 
 
~	& C$ 	C jlJL%ABB	C 	C 	CC C C 
~	& E$ 	E lnjl%CDD	E 	E 	EE E E
 
~	& 6Z0 	6 jl_55	6 	6 	66 6 6 
~	& 6[1 	6 jl_55	6 	6 	66 6 6s   A2A>2A;>BC)B??C	CC5DD4EE7!FF!>HH2I7I!!I*	&I77J K!,KK	K!!K*ML11L:	6MM,N-NN 	N--N6c                 N   t        t        d      5  t        dt        dt               f      f      # 1 sw Y   nxY wt        t        t        d      5  t        dt        dt               t               f      f      # 1 sw Y   nxY wt        t        t        d      5  t        dt        dt               g      t               g      # 1 sw Y   nxY wt        t        t        d            5  t        dt        dt               f      f      # 1 sw Y   nxY wt        t        t        d            5  t        dt        dt        dt               f      f      f      # 1 sw Y   nxY wt	        j
                  t              5  t        t        t        d            5  t        dt               f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt	        j
                  t        d      5  t        t        t              d       d d d        y # 1 sw Y   y xY w)NT)flatten_subgroupsr   z@^You cannot specify a nested structure inside a RaisesGroup withr   )r   r   r	   r   r   r   r   r   r   test_flatten_subgroupsr#   Q   s   	Z4	8 IR.jl_"E!GHHI I 
Zd	C UR.jlIK5P"Q!STTU U	Zd	C TR.jl^"Dik!RSST T 
[tD	E IR.jl_"E!GHHI I	[tD	E 
BZ\O!D FGI
 	

 

 
~	& 6Z4HI 	6 jl_55	6 	6 	66 6 6
 
Q
 E 	K
+tD	E E Esb   !3<*A??B!*CC1!DD8,E$$E-	G$F::G	?GG7HH$c            
     ~   t        t        d      5  t        # 1 sw Y   nxY wt        j                  t        d      5  t        t        t        d       d d d        n# 1 sw Y   nxY wt        t        d       d      5  t        # 1 sw Y   nxY wt        j                  t        d      5  t        t        t              d       d d d        n# 1 sw Y   nxY wt        t        t        d            5  t        dt        dt               g      g      # 1 sw Y   nxY wt        t        t        d            5  t        dt               g      # 1 sw Y   nxY wt        j                  t        d	      5  t        t              5  t        d
      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        j                  t              5  t        t        d      5  t        dt        dt               g      g      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        t        dd      5  t        dt        dt               g      g      # 1 sw Y   nxY wt        j                  t              5  t        t        d      5  t        # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)NTallow_unwrappedz,^You cannot specify multiple exceptions withr   c                .    t        | t        t        f      S N)
isinstancer   r   es    r   <lambda>z1test_catch_unwrapped_exceptions.<locals>.<lambda>~   s    
1{J.G H r   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   test_catch_unwrapped_exceptionsr/   o   sl    
Z	6   
=
 C 	KTB	C C C 
HI
  	  
z)G	H CK
+TBC C C
 
[TB	C GR.jl^"D!EFFG G	[TB	C 1R*,001 1 
z)>	? 1$ 	1/00	1 	1 	11 1 1
 
~	& KT: 	K nR*,&H%IJJ	K 	K 	KK K K
 
Z	N GR.jl^"D!EFFG G 
y	! T: 	O	 	 	  s   " A  A)BB2CC<!DD&EE" F2FF%	!F22F;H )!H

H	H  H)>!II(J3JJ&	"J33J<c                    t        t        d      5  t        dt               f      # 1 sw Y   nxY wt        t        d      5  t        dt               f      # 1 sw Y   nxY wt        t        d      5  t        dt               f      } | j                  d       | # 1 sw Y   nxY wt        t        d      5  t        dt               f      } | j                  d       | # 1 sw Y   nxY wt	        j
                  t              5  t        t        d      5  t        dt               f      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nr   r   ^bar$zmy notez^bar
my note$r   )r   r   r	   add_noter   r   r*   s    r   
test_matchr3      s(   	Zu	- 5UZ\O445 5 
Zw	/ 5UZ\O445 5 
Zy	1 5:</2	

9  
Z'7	8 5:</2	

9 
 
~	& 951 	9 88	9 	9 	99 9 9sJ   (1AA$8)B!!B*>)C''C0E
D44D=	9E

Ec                 @    t        dt               f       t        t         fd      5   # 1 sw Y   nxY wt        j                  t               5  t        t         fd      5  t        dt               f      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nr   c                    | u S r(   r   xexcs    r   r,   ztest_check.<locals>.<lambda>   s    c r   r-   c                    | u S r(   r   r6   s    r   r,   ztest_check.<locals>.<lambda>   s    Q#X r   )r	   r   r   r   r   )r8   s   @r   
test_checkr:      s    
jl_
-C	Z'9	: 	 	~	& 6+=> 	6 jl_55	6 	6 	66 6 6s&   .7B(A>>B	BBc                    dd} d}t        j                  t        t        j                  |            5  t        t        dd       d d d        t        j                  t        t        j                  |            5  t        t        d|        d d d        t        t        t        d      d	      }|5  t        d      # 1 sw Y   |xY w# 1 sw Y   ?xY w# 1 sw Y   nxY w|5  t        d
t        d      g      # 1 sw Y   nxY wt        t        d	      5 }t        dt        d      g      # 1 sw Y   nxY wt        j                  t              r-t        t        d      j                  |j                        sJ y y )Nc                     y)NTr   r*   s    r   my_checkz,test_unwrapped_match_check.<locals>.my_check   s    r   av  `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+   objectreturnbool)r   r   r   r   r   r   r   r	   r)   valuematches)r=   msgrgr8   s       r   test_unwrapped_match_checkrE      sJ   	C  
z3	8 CJEBC	z3	8 FJHEF 
WZw7	NB	  C CF F
   	 6R*U"3!4556 6 
Z	6 9#UZ%6$7889 9#))^,:U3;;CIIFFF -s;   C>C7CCCC$)D  D	D44D=c                     t        t              } | j                  d       rJ | j                  t                     rJ | j                  t        dt               f            sJ y )Nr   )r   r   rB   r	   )rD   s    r   test_RaisesGroup_matchesrG      sO    	Z	 Bzz$zz*,'''::nR*,9:::r   c            	     2   	 	 	 	 	 	 dd}  | dt        t                      | dt        t        t                      | dt        t        t                            | dt        t        t        d                    | dt        t        d                    | d	t        t                      | d
t        t        t                            | dt        t        t                            | dt        t        t              t        t                           y )Nc                    t        j                  t        dt        j                  |        d      5  |5  	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nz'^DID NOT RAISE any exception, expected r   r   )r   r   AssertionErrorr   r   )messagebodys     r   check_messagez#test_message.<locals>.check_message   s`     ]];BIIg<N;OqQ
 	  		 	 		 	s!   AA	A	A	AAzExceptionGroup(ValueError)z&ExceptionGroup(ValueError, ValueError)z*ExceptionGroup(ExceptionGroup(ValueError))z3ExceptionGroup(Matcher(ValueError, match='my_str'))my_strz'ExceptionGroup(Matcher(match='my_str'))r   z%BaseExceptionGroup(KeyboardInterrupt)z.BaseExceptionGroup(Matcher(KeyboardInterrupt))z9BaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt))zUBaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt), ExceptionGroup(ValueError)))rK   strrL   zRaisesGroup[BaseException]r?   None)r   r   r   KeyboardInterrupt)rM   s    r   test_messagerR      s   		(	 
	 .J0GH0J
+
 4K
+, =GJ12 1G(+, /%&
 8G-./
 CK 123
 _K 12K
4KLr   c            	        t        j                  t        d      5  t                d d d        t        j                  t        dt	        j
                  t        t                     d      5  t        t               d d d        t        t        t                    5  t        dt               f      # 1 sw Y   xY w# 1 sw Y   CxY w# 1 sw Y   nxY wt        j                  t              5  t        t        t                    5  t        dt               f      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)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   reprr>   r   r	   r   r   r   r   test_matcherrU   %  s    	G
  			
 
 4<!8 99^_
  		 
WZ(	) 2R*,11 
 2 2	~	& 6+, 	6 jl_55	6 	6 	66 6 6sA   B4.C C4B= C	C1D6
D  D)	%D66D?c                    t        t        t        d            5  t        dt        d      f      # 1 sw Y   nxY wt	        j
                  t              5  t        t        t        d            5  t        dt        d      f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        t        d            5  t        dt        d      f      # 1 sw Y   nxY wt	        j
                  t              5  t        t        d            5  t        dt        d      f      # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wt        t        t        d            5  t        dt        d      g      # 1 sw Y   nxY wt	        j
                  t              5  t        t        t        d            5  t        dt        d      g      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nr   r   r   r   r1   barr)r   r   r   r	   r   r   r   r   r   test_matcher_matchrX   8  s   	WZ/	0 7R*U"3!5667 7	~	& ;U34 	; j&7%9::	; 	; 	;; ; ;
 
W5)	* 7R*U"3!5667 7	~	& ;u-. 	; j&7%9::	; 	; 	;; ; ;
 
WZw7	8 6R*U"3!4556 6	~	& ;7;< 	; j&8%9::	; 	; 	;; ; ;sz   1:B0BB	BB&>CC:D=D''D0	,D==E#E::FG':GG	G''G0c            	        dd} t        t        |             5  t        dt        dd      f      # 1 sw Y   nxY wdd}t        t        t        |            5  t        dt        dd      f      # 1 sw Y   nxY wt	        j
                  t              5  t        t        t        |            5  t        dt        dd      f      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)	Nc                D    t        | t              xr | j                  dk(  S N   )r)   OSErrorerrnor*   s    r   check_oserror_and_errno_is_5z8test_Matcher_check.<locals>.check_oserror_and_errno_is_5O  s    !W%6!''Q,6r   r-   r   r\   c                     | j                   dk(  S r[   )r^   r*   s    r   check_errno_is_5z,test_Matcher_check.<locals>.check_errno_is_5V  s    ww!|r      )r+   BaseExceptionr?   r@   )r+   r]   r?   r@   )r   r   r	   r]   r   r   )r_   ra   s     r   test_Matcher_checkrd   N  s    7 
W#?@	A 4R'!R.!2334 4 
WW,<=	> 4R'!R.!2334 4 
~	& 80@AB 	8 gan%677	8 	8 	88 8 8s2   2;A44A=C"4CC	C""C+c                    t        t        t                    dk(  sJ t        t        d            dk(  sJ t        j                  dd      } t        t        |             dk(  sJ t        j                  dt        j
                        }t        t        |            d|d	k(  sJ t        t        t        d
t                    dt        d	k(  sJ y )NzMatcher(ValueError)z[a-z]r   zMatcher(match='[a-z]')noflagr   zMatcher(match='noflag')zMatcher(match=)r   )r   r.   z&Matcher(ValueError, match='re', check=)rO   r   r   r   compile
IGNORECASEr@   )pattern_no_flagspattern_flagss     r   test_matcher_tostringrl   a  s    wz"#'<<<<wW%&*BBBBzz)Q/w-./3LLLLJJy"--8Mw]+,.@QQR0SSSSGJd$783D81=	>	>r   c                   | j                  t        j                  j                  dt        j                  j                  j                         t        j                  j                  t              5 }t        dt        d      f      # 1 sw Y   nxY wj                  t        u sJ |j                  j                  d   j                  dk(  sJ t        |j                  t              sJ y )NExceptionInfor   hellor   )ro   )setattrtriotesting_raises_group_ExceptionInfor   r   r	   typerA   
exceptionsargsr)   tbr   )monkeypatchexcinfos     r   test__ExceptionInfor{   n  s    """"11
 
	!	!*	- 9R*W"5!7889 9<<>)))==##A&++z999gjj-000s   1BB)r   rO   r?   rO   )r?   rP   )ry   zpytest.MonkeyPatchr?   rP   )
__future__r   r   systypesr   r   rq   trio.testingr   r   version_infoexceptiongroupr	   r   r    r#   r/   r3   r:   rE   rG   rR   rU   rX   rd   rl   r{   r   r   r   <module>r      sv    " 	 
    -g-$:6zE<0f966G>;6r6&;,8&

1r   