U
    f/e=                     @   sT  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dddddddddddgdd Zejddd d!gd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zejd0d1dgG d2d3 d3ZdS )4zG"
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	   R/tmp/pip-unpacked-wheel-tiezk1ph/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   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 5 Q R X W 5 Q R X tjtdd t  W 5 Q R X 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    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 5 Q R X d S )Nr   r"   r#   r   r   )r   messager   r	   r	   r
   %test_catch_warning_category_and_matchL   s    r+   )r'   zNot this message)r'   warning)r'   z\d+c              
   C   sV   dt | j d}tjt|d, tj| |d t||  W 5 Q R X W 5 Q R X d S )NzDid not see warning z	 matchingr   )	reprr   r   r    r!   r"   r#   r   r   )r   r*   r   r$   r	   r	   r
   test_fail_to_matcha   s    	r.   c              
   C   sL   | \}}d}t jt|d( t| td| W 5 Q R X W 5 Q R X 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_warningp   s
    r1   c              	   C   s>   | \}}t j|dd td| td| W 5 Q R X d S )NFr   Expected warningzUnexpected warning OKr)   )r   r0   extra_categoryr	   r	   r
   test_ignore_extra_warningx   s    r4   c              
   C   sX   | \}}d}t jt|d4 t| td| td| W 5 Q R X W 5 Q R X d S )Nr   r   r2   zUnexpected warning NOT OKr/   )r   r0   r3   r   r	   r	   r
   test_raise_on_extra_warning   s    r5   c               	   C   sF   t } tj| dd* td|  td|  td|  W 5 Q R X 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
    r<   c               	   C   sF   t } tj| dd* td|  td|  td|  W 5 Q R X d S )Nr6   r   r8   r9   r7   )DeprecationWarningr"   r#   r   r   r;   r	   r	   r
   0test_same_category_different_messages_last_match   s
    r>   c              
   C   sX   | \}}t jtdd8 tj|dd td| td| W 5 Q R X W 5 Q R X d S )NzDid not see warning.*matchingr   r6   zDo not match itr7   r/   )r   Ztarget_categoryZother_categoryr	   r	   r
   &test_right_category_wrong_match_raises   s
    r?   false_or_noneFc                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestFalseOrNoneExpectedWarningc              
   C   s>   d}t jt|d" t| t  W 5 Q R X W 5 Q R X d S )Nr   r   )r   r    r!   r"   r#   r   )selfr@   r$   r	   r	   r
   test_raise_on_warning   s    z4TestFalseOrNoneExpectedWarning.test_raise_on_warningc              	   C   s   t | W 5 Q R X d S r   )r"   r#   rB   r@   r	   r	   r
   test_no_raise_without_warning   s    z<TestFalseOrNoneExpectedWarning.test_no_raise_without_warningc              	   C   s$   t j|dd t  W 5 Q R X d S )NFr   )r"   r#   r   rD   r	   r	   r
   'test_no_raise_with_false_raise_on_extra   s    zFTestFalseOrNoneExpectedWarning.test_no_raise_with_false_raise_on_extraN)r   
__module____qualname__rC   rE   rF   r	   r	   r	   r
   rA      s   rA   )__doc__r   r   Zpandas.errorsr   r   Zpandas._testingZ_testingr"   Zfixturer   ResourceWarningr:   r   r=   r   r   r   markfilterwarningsr%   Zparametrizer+   r.   r1   r4   r5   r<   r>   r?   rA   r	   r	   r	   r
   <module>   s~   
	






	