
    Eg                          d Z ddlZddlZddlmZmZ ddlmZ  ej	        e
eeeeeeg          d             Z ej	        e
efeefee
feefeefeefeefeefgd           d             Zd	 Zej                            d
          d             Zej                            dg d          d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej                            dddg           G d d                      Z!d Z"d Z#dS )zG"
Test module for testing ``pandas._testing.assert_produces_warning``.
    N)DtypeWarningPerformanceWarning)paramsc                     | j         S )zx
    Return unique warning.

    Useful for testing behavior of tm.assert_produces_warning with various categories.
    paramrequests    c/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/tests/util/test_assert_produces_warning.pycategoryr      s    " =    c                 *    t          |           j        S N)type__name__)xs    r   <lambda>r   /   s    $q''" r   )r   idsc                     | j         S )z
    Return pair or different warnings.

    Useful for testing how several different warnings are handled
    in tm.assert_produces_warning.
    r   r	   s    r   pair_different_warningsr   $   s    ( =r   c                  n    t          j        dt                     t          j        dt                     d S )Nf1f2)warningswarnFutureWarningRuntimeWarning r   r   fr   ;   s,    M$&&&M$'''''r   zignore:f1:FutureWarningc                  r   d} t          j        t          |           5  t          j        t
                    5  t                       d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        t
          d          5  t                       d d d            d S # 1 swxY w Y   d S )NCaused unexpected warning\(s\)matchFraise_on_extra_warnings)pytestraisesAssertionErrortmassert_produces_warningr   r   msgs    r   *test_assert_produces_warning_honors_filterr-   @   sg    ,C	~S	1	1	1  '77 	 	CCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	               
	#NE	R	R	R  	                 sF   A*AA*A	A*A	A**A.1A.B,,B03B0zmessage, match)) N)r.   r.   )Warning messagez.*)r/   War)r/   z
[Ww]arning)r/   age)r/   zage$)Message 12-234 with numbersz\d{2}-\d{3})r2   z^Mes.*\d{2}-\d{3})r2   z\d{2}-\d{3}\s\S+)zMessage, which we do not matchNc                     t          j        | |          5  t          j        ||            d d d            d S # 1 swxY w Y   d S )Nr"   r)   r*   r   r   )r   messager#   s      r   %test_catch_warning_category_and_matchr6   L   s    " 
	#HE	:	:	: ) )gx((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   :>>c                  4   t           } d}d}t          j        t          |          5  t	          j        | |          5  t          j        d|            t          j        d|            d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NzDid not see this warningzDid not see warning 'RuntimeWarning' matching 'Did not see this warning'. The emitted warning messages are \[RuntimeWarning\('This is not a match.'\), RuntimeWarning\('Another unmatched warning.'\)\]r"   This is not a match.Another unmatched warning.)r   r&   r'   r(   r)   r*   r   r   r   r#   	unmatcheds      r   "test_fail_to_match_runtime_warningr<   a   sG   H&E	<  
~Y	7	7	7 B B'>>> 	B 	BM0(;;;M6AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	BB B B B B B B B B B B B B B B B B B4   B+A5)B5A9	9B<A9	=BBBc                  4   t           } d}d}t          j        t          |          5  t	          j        | |          5  t          j        d|            t          j        d|            d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NWarningzDid not see warning 'FutureWarning' matching 'Warning'. The emitted warning messages are \[FutureWarning\('This is not a match.'\), FutureWarning\('Another unmatched warning.'\)\]r"   r8   r9   )r   r&   r'   r(   r)   r*   r   r   r:   s      r   !test_fail_to_match_future_warningr@   p   sG   HE	;  
~Y	7	7	7 B B'>>> 	B 	BM0(;;;M6AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	BB B B B B B B B B B B B B B B B B Br=   c                  4   t           } d}d}t          j        t          |          5  t	          j        | |          5  t          j        d|            t          j        d|            d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz\d+zDid not see warning 'ResourceWarning' matching '\\d\+'. The emitted warning messages are \[ResourceWarning\('This is not a match.'\), ResourceWarning\('Another unmatched warning.'\)\]r"   r8   r9   )ResourceWarningr&   r'   r(   r)   r*   r   r   r:   s      r   #test_fail_to_match_resource_warningrC      sG   HE	=  
~Y	7	7	7 B B'>>> 	B 	BM0(;;;M6AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	BB B B B B B B B B B B B B B B B B Br=   c                     | \  }}d}t          j        t          |          5  t          j        |          5  t          j        d|           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz%Did not see expected warning of classr"   zwarning messager&   r'   r(   r)   r*   r   r   )r   expected_categoryactual_categoryr#   s       r   !test_fail_to_catch_actual_warningrH      s   )@&3E	~U	3	3	3 > >'(9:: 	> 	>M+_===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>> > > > > > > > > > > > > > > > > >s4   A2AA2A	A2!A	"A22A69A6c                     | \  }}t          j        |d          5  t          j        d|           t          j        d|           d d d            d S # 1 swxY w Y   d S )NFr$   Expected warningzUnexpected warning OKr4   )r   rF   extra_categorys      r   test_ignore_extra_warningrL      s    (?%~		#$5u	U	U	U ? ?(*;<<<-~>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s   +AAAc                 (   | \  }}d}t          j        t          |          5  t          j        |          5  t          j        d|           t          j        d|           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr!   r"   rJ   zUnexpected warning NOT OKrE   )r   rF   rK   r#   s       r   test_raise_on_extra_warningrN      s>   (?%~-E	~U	3	3	3 G G'(9:: 	G 	GM,.?@@@M5~FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	GG G G G G G G G G G G G G G G G G Gs4   B+A/#B/A3	3B6A3	7BBBc                      t           } t          j        | d          5  t          j        d|            t          j        d|            t          j        d|            d d d            d S # 1 swxY w Y   d S )N^Match thisr"   
Match thisDo not match thatDo not match that either)UserWarningr)   r*   r   r   r   s    r   1test_same_category_different_messages_first_matchrV      s    H		#HN	C	C	C < <lH---)84440(;;;< < < < < < < < < < < < < < < < < <   A A++A/2A/c                      t           } t          j        | d          5  t          j        d|            t          j        d|            t          j        d|            d d d            d S # 1 swxY w Y   d S )NrP   r"   rR   rS   rQ   )DeprecationWarningr)   r*   r   r   rU   s    r   0test_same_category_different_messages_last_matchrZ      s    !H		#HN	C	C	C . .)84440(;;;lH---. . . . . . . . . . . . . . . . . .rW   c                      t           t          f} t          j        | d          5  t	          j        dt                      t	          j        dt                     d d d            d S # 1 swxY w Y   d S )NrP   r"   rQ   zMatch this too)r   rT   r)   r*   r   r   rU   s    r   test_match_multiple_warningsr\      s    {+H		#HN	C	C	C 5 5lM222&4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s   5A''A+.A+c                 (   | \  }}t          j        t          d          5  t          j        |d          5  t          j        d|           t          j        d|           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NzDid not see warning.*matchingr"   rP   zDo not match itrQ   rE   )r   target_categoryother_categorys      r   &test_right_category_wrong_match_raisesr`      s   &=#O^	~-L	M	M	M 8 8'~NNN 	8 	8M+_===M,777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s4   B+A/#B/A3	3B6A3	7BBBfalse_or_noneFc                        e Zd Zd Zd Zd ZdS )TestFalseOrNoneExpectedWarningc                     d}t          j        t          |          5  t          j        |          5  t                       d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr!   r"   )r&   r'   r(   r)   r*   r   )selfra   r,   s      r   test_raise_on_warningz4TestFalseOrNoneExpectedWarning.test_raise_on_warning   s    /]>555 	 	+M::                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s4   A&AA&A	A&A	A&&A*-A*c                 b    t          j        |          5  	 d d d            d S # 1 swxY w Y   d S r   )r)   r*   re   ra   s     r   test_no_raise_without_warningz<TestFalseOrNoneExpectedWarning.test_no_raise_without_warning   sz    '66 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   $((c                     t          j        |d          5  t                       d d d            d S # 1 swxY w Y   d S )NFr$   )r)   r*   r   rh   s     r   'test_no_raise_with_false_raise_on_extrazFTestFalseOrNoneExpectedWarning.test_no_raise_with_false_raise_on_extra   s    'uUUU 	 	CCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   377N)r   
__module____qualname__rf   ri   rk   r   r   r   rc   rc      sA                r   rc   c                     d} t          j        t          |           5  t          j        t
                    5  t          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   t          j        t          |           5  t          j        t
                    5  t          j        dt                     t          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   d} t          j        t          |           5  t          j        d           5  t          j        dt                     t          # 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nz3Did not see expected warning of class 'UserWarning'r"   r   zCaused unexpected warning)r&   r'   r(   r)   r*   rT   
ValueErrorr   r   r   
IndexErrorSystemErrorr+   s    r   test_raises_during_exceptionrr      sk   
?C	~S	1	1	1  '44 	 		 	 	 	 	 	 	 	 	               
~S	1	1	1  '44 	 	M/=999	 	 	 	 	 	 	 	 	              
 &C	~S	1	1	1  '-- 	 	M/=999	 	 	 	 	 	 	 	 	                 s   AA  A	AA	AAA>C"B::B>	>CB>	CCC:E
"D11D5	5E
8D5	9E

EEc                     t          j        t          d          5  t          j        d           5  t          d          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   t          j        t
          d          5  t          j        t          d          5  t          j        dt                     t          d          # 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )NErrorr"   r   )	r&   r'   SyntaxErrorr)   r*   ro   r   r   r   r   r   r   test_passes_during_exceptionrv      s   	{'	2	2	2 ' ''-- 	' 	'g&&&	' 	' 	' 	' 	' 	' 	' 	' 	'' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 
z	1	1	1 & &'_MMM 	& 	&M/=999W%%%	& 	& 	& 	& 	& 	& 	& 	& 	&& & & & & & & & & & & & & & & & & &s^   AAA	AA		AA A?C*CC			CC		CC"%C")$__doc__r   r&   pandas.errorsr   r   pandas._testing_testingr)   fixturer   rB   rT   r   rY   r   r   r   markfilterwarningsr-   parametrizer6   r<   r@   rC   rH   rL   rN   rV   rZ   r\   r`   rc   rr   rv   r   r   r   <module>r      s            
       
 
 
 
 
 	%	m$	'	/0	]+	)*	,-	*+	 	#"    ( ( (
 566  76     ) )!  )
B B BB B BB B B> > >? ? ?G G G< < <. . .5 5 58 8 8 5$-88       98   $& & & & &r   