a
    Pf                   
   @   sV  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d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 d	d
d Zdd Zejddd Zejdg 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#d$ Zd%d& Zd'd( Z ejd)d*dgG d+d, d,Z!d-d. Z"d/d0 Z#dS )1zG"
Test module for testing ``pandas._testing.assert_produces_warning``.
    N)DtypeWarningPerformanceWarning)paramsc                 C   s   | j S )zx
    Return unique warning.

    Useful for testing behavior of tm.assert_produces_warning with various categories.
    paramrequest r	   g/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/util/test_assert_produces_warning.pycategory   s    r   c                 C   s
   t | jS N)type__name__)xr	   r	   r
   <lambda>/       r   )r   Zidsc                 C   s   | j S )z
    Return pair or different warnings.

    Useful for testing how several different warnings are handled
    in tm.assert_produces_warning.
    r   r   r	   r	   r
   pair_different_warnings$   s    r   c                   C   s   t dt t dt d S )Nf1f2)warningswarnFutureWarningRuntimeWarningr	   r	   r	   r
   f;   s    r   zignore:f1:FutureWarningc               	   C   s   d} t jt| d@ tt t  W d    n1 s:0    Y  W d    n1 sX0    Y  tjtdd t  W d    n1 s0    Y  d S )NCaused unexpected warning\(s\)matchFZraise_on_extra_warnings)pytestraisesAssertionErrortmassert_produces_warningr   r   msgr	   r	   r
   *test_assert_produces_warning_honors_filter@   s    Br%   zmessage, match)) N)r&   r&   )Warning messagez.*)r'   ZWar)r'   z
[Ww]arning)r'   Zage)r'   zage$)Message 12-234 with numbersz\d{2}-\d{3})r(   z^Mes.*\d{2}-\d{3})r(   z\d{2}-\d{3}\s\S+)zMessage, which we do not matchNc                 C   s>   t j| |d t||  W d    n1 s00    Y  d S )Nr   r!   r"   r   r   )r   messager   r	   r	   r
   %test_catch_warning_category_and_matchL   s    r+   c               	   C   s   t } d}d}tjt|dV tj| |d( td|  td|  W d    n1 sX0    Y  W d    n1 sv0    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   	unmatchedr	   r	   r
   "test_fail_to_match_runtime_warninga   s    r0   c               	   C   s   t } d}d}tjt|dV tj| |d( td|  td|  W d    n1 sX0    Y  W d    n1 sv0    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   r,   r-   )r   r   r   r    r!   r"   r   r   r.   r	   r	   r
   !test_fail_to_match_future_warningp   s    r2   c               	   C   s   t } d}d}tjt|dV tj| |d( td|  td|  W d    n1 sX0    Y  W d    n1 sv0    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   r,   r-   )ResourceWarningr   r   r    r!   r"   r   r   r.   r	   r	   r
   #test_fail_to_match_resource_warning   s    r4   c              	   C   st   | \}}d}t jt|dF t| td| W d    n1 sH0    Y  W d    n1 sf0    Y  d S )Nz%Did not see expected warning of classr   zwarning messager   r   r    r!   r"   r   r   )r   expected_categoryZactual_categoryr   r	   r	   r
   !test_fail_to_catch_actual_warning   s
    r7   c                 C   sR   | \}}t j|dd( td| td| W d    n1 sD0    Y  d S )NFr   Expected warningzUnexpected warning OKr)   )r   r6   extra_categoryr	   r	   r
   test_ignore_extra_warning   s    r:   c              	   C   s   | \}}d}t jt|dR t|( td| td| W d    n1 sT0    Y  W d    n1 sr0    Y  d S )Nr   r   r8   zUnexpected warning NOT OKr5   )r   r6   r9   r   r	   r	   r
   test_raise_on_extra_warning   s    r;   c                  C   sZ   t } tj| dd4 td|  td|  td|  W d    n1 sL0    Y  d S )N^Match thisr   
Match thisDo not match thatDo not match that either)UserWarningr!   r"   r   r   r   r	   r	   r
   1test_same_category_different_messages_first_match   s
    rB   c                  C   sZ   t } tj| dd4 td|  td|  td|  W d    n1 sL0    Y  d S )Nr<   r   r>   r?   r=   )DeprecationWarningr!   r"   r   r   rA   r	   r	   r
   0test_same_category_different_messages_last_match   s
    rD   c                  C   sR   t tf} tj| dd( tdt  tdt W d    n1 sD0    Y  d S )Nr<   r   r=   zMatch this too)r   r@   r!   r"   r   r   rA   r	   r	   r
   test_match_multiple_warnings   s    rE   c              	   C   s   | \}}t jtddV tj|dd( td| td| W d    n1 sT0    Y  W d    n1 sr0    Y  d S )NzDid not see warning.*matchingr   r<   zDo not match itr=   r5   )r   Ztarget_categoryZother_categoryr	   r	   r
   &test_right_category_wrong_match_raises   s
    rF   false_or_noneFc                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestFalseOrNoneExpectedWarningc              	   C   sf   d}t jt|d@ t| t  W d    n1 s:0    Y  W d    n1 sX0    Y  d S )Nr   r   )r   r   r    r!   r"   r   )selfrG   r$   r	   r	   r
   test_raise_on_warning   s    z4TestFalseOrNoneExpectedWarning.test_raise_on_warningc                 C   s.   t | W d    n1 s 0    Y  d S r   )r!   r"   rI   rG   r	   r	   r
   test_no_raise_without_warning   s    z<TestFalseOrNoneExpectedWarning.test_no_raise_without_warningc                 C   s8   t j|dd t  W d    n1 s*0    Y  d S )NFr   )r!   r"   r   rK   r	   r	   r
   'test_no_raise_with_false_raise_on_extra   s    zFTestFalseOrNoneExpectedWarning.test_no_raise_with_false_raise_on_extraN)r   
__module____qualname__rJ   rL   rM   r	   r	   r	   r
   rH      s   rH   c               	   C   s<  d} t jt| d> tt tW d    n1 s80    Y  W d    n1 sV0    Y  t jt| dJ tt  tdt	 t
W d    n1 s0    Y  W d    n1 s0    Y  d} t jt| dL td   tdt	 tW d    n1 s0    Y  W d    n1 s.0    Y  d S )Nz3Did not see expected warning of class 'UserWarning'r   r   zCaused unexpected warning)r   r   r    r!   r"   r@   
ValueErrorr   r   r   
IndexErrorSystemErrorr#   r	   r	   r
   test_raises_during_exception   s    @@rS   c                	   C   s   t jtddB td  tdW d    n1 s80    Y  W d    n1 sV0    Y  t jtddR tjtdd$ tdt tdW d    n1 s0    Y  W d    n1 s0    Y  d S )NErrorr   r   )	r   r   SyntaxErrorr!   r"   rP   r   r   r   r	   r	   r	   r
   test_passes_during_exception   s    DrV   )$__doc__r   r   Zpandas.errorsr   r   Zpandas._testingZ_testingr!   Zfixturer   r3   r@   r   rC   r   r   r   markfilterwarningsr%   Zparametrizer+   r0   r2   r4   r7   r:   r;   rB   rD   rE   rF   rH   rS   rV   r	   r	   r	   r
   <module>   sd   
	





	