
    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$                  j'                  d
      d        Zej$                  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$                  j+                  dddg       G d d             Z!d Z"d Z#y)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/openai/venv/lib/python3.12/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                  l    t        j                  dt               t        j                  dt               y )Nf1f2)warningswarnFutureWarningRuntimeWarning r   r   fr   ;   s    MM$&MM$'r   zignore:f1:FutureWarningc                  L   d} t        j                  t        |       5  t        j                  t
              5  t                d d d        d d d        t        j                  t
        d      5  t                d d d        y # 1 sw Y   @xY w# 1 sw Y   DxY w# 1 sw Y   y xY w)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-   @   sp     ,C	~S	1''7C 8 
2 
	#	#NE	R	 
S	R 87 
2	1 
S	Rs.   BBB.BB	BBB#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        y # 1 sw Y   y xY w)Nr"   r)   r*   r   r   )r   messager#   s      r   %test_catch_warning_category_and_matchr6   L   s.    " 
	#	#HE	:gx( 
;	:	:s	   8Ac                  (   t         } d}d}t        j                  t        |      5  t	        j
                  | |      5  t        j                  d|        t        j                  d|        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 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   sq    H&E	<  
~Y	7''>MM0(;MM6A ? 
8	7>> 
8	7"   B-A<+B<B	BBc                  (   t         } d}d}t        j                  t        |      5  t	        j
                  | |      5  t        j                  d|        t        j                  d|        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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   sq    HE	;  
~Y	7''>MM0(;MM6A ? 
8	7>> 
8	7r=   c                  (   t         } d}d}t        j                  t        |      5  t	        j
                  | |      5  t        j                  d|        t        j                  d|        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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      sq    HE	=  
~Y	7''>MM0(;MM6A ? 
8	7>> 
8	7r=   c                     | \  }}d}t        j                  t        |      5  t        j                  |      5  t        j                  d|       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 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''(9:MM+_= ; 
4	3:: 
4	3s"   A-A!A-!A*	&A--A6c                     | \  }}t        j                  |d      5  t        j                  d|       t        j                  d|       d d d        y # 1 sw Y   y xY w)NFr$   Expected warningzUnexpected warning OKr4   )r   rF   extra_categorys      r   test_ignore_extra_warningrL      sJ    (?%~		#	#$5u	U(*;<-~> 
V	U	Us   -AAc                    | \  }}d}t        j                  t        |      5  t        j                  |      5  t        j                  d|       t        j                  d|       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr!   r"   rJ   zUnexpected warning NOT OKrE   )r   rF   rK   r#   s       r   test_raise_on_extra_warningrN      sk    (?%~-E	~U	3''(9:MM,.?@MM5~F ; 
4	3:: 
4	3s"   B-A7&B7B 	<BBc                      t         } t        j                  | d      5  t        j                  d|        t        j                  d|        t        j                  d|        d d d        y # 1 sw Y   y xY w)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      sP    H		#	#HN	ClH-)840(; 
D	C	C   AA**A3c                      t         } t        j                  | d      5  t        j                  d|        t        j                  d|        t        j                  d|        d d d        y # 1 sw Y   y xY w)NrP   r"   rR   rS   rQ   )DeprecationWarningr)   r*   r   r   rU   s    r   0test_same_category_different_messages_last_matchrZ      sP    !H		#	#HN	C)840(;lH- 
D	C	CrW   c                      t         t        f} t        j                  | d      5  t	        j
                  dt                t	        j
                  dt               d d d        y # 1 sw Y   y xY w)NrP   r"   rQ   zMatch this too)r   rT   r)   r*   r   r   rU   s    r   test_match_multiple_warningsr\      sF    {+H		#	#HN	ClM2&4 
D	C	Cs   5A""A+c                    | \  }}t        j                  t        d      5  t        j                  |d      5  t        j                  d|       t        j                  d|       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 see warning.*matchingr"   rP   zDo not match itrQ   rE   )r   target_categoryother_categorys      r   &test_right_category_wrong_match_raisesr`      sh    &=#O^	~-L	M''~NMM+_=MM,7 O 
N	MNN 
N	Ms"   B-A7&B7B 	<BBfalse_or_noneFc                       e Zd Zd Zd Zd Zy)TestFalseOrNoneExpectedWarningc                     d}t        j                  t        |      5  t        j                  |      5  t                d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr!   r"   )r&   r'   r(   r)   r*   r   )selfra   r,   s      r   test_raise_on_warningz4TestFalseOrNoneExpectedWarning.test_raise_on_warning   sE    /]]>5++M: ; 65:: 65s!   AAAA	AA%c                 Z    t        j                  |      5  	 d d d        y # 1 sw Y   y xY wr   )r)   r*   re   ra   s     r   test_no_raise_without_warningz<TestFalseOrNoneExpectedWarning.test_no_raise_without_warning   s    ''6 766s   !*c                 p    t        j                  |d      5  t                d d d        y # 1 sw Y   y xY w)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C VUUs   ,5N)r   
__module____qualname__rf   ri   rk   r   r   r   rc   rc      s    r   rc   c                     d} t        j                  t        |       5  t        j                  t
              5  t        # 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        j                  t
              5  t        j                  dt               t        # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wd} t        j                  t        |       5  t        j                  d       5  t        j                  dt               t        # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)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      s    
?C	~S	1''4 544 
2	1	1 
~S	1''4MM/=9 544 
2	1	1
 &C	~S	1''-MM/=9 .-- 
2	1	1sV   A?A	AA<C!B77C 	<CC6E!D--D6	2EEc                     t        j                  t        d      5  t        j                  d       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
        d      5  t        j                  t        d      5  t        j                  dt               t        d      # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)NErrorr"   r   )	r&   r'   SyntaxErrorr)   r*   ro   r   r   r   r   r   r   test_passes_during_exceptionrv      s    	{'	2''-g&& .-- 
3	2	2 
z	1''_MMM/=9W%% NMM 
2	1	1s8   A>A	AA;C&B==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 7  )! )
BBB>?G<.58 5$-8  9 $&r   