U
    g7                      @  s,  d dl mZ d dlZd dlZd dlZddlmZmZmZm	Z	 ddl
mZ ejdddd	d
ZddddZdddddZdddddZdddddZddddZddddZdddddZeddedd dd!d"Zdddd#d$ZG d%d& d&Zdddd'd(Zed)d*ddd+d dd,d-Zdddd.d/Zd0dd1d2Zed3ed4dd5Zdddd6d7ZG d8d9 d9Zdddd:d;Zed<dd=dddd>d?Z ed<dd=dddd@dAZ!ed<ddddddBdCZ"ed<ddddddDdEZ#dddFdGZ$ddddHdIZ%dddJdKZ&dS )L    )annotationsN   )TrioDeprecationWarning
deprecateddeprecated_aliaswarn_deprecated   )module_with_deprecationszpytest.WarningsRecorder)recwarnreturnc                 C  s   t d t dt | S )Nalwaysignore)warningssimplefilterResourceWarning)r
    r   >/tmp/pip-unpacked-wheel-ks04xdmi/trio/_tests/test_deprecate.pyrecwarn_always   s    
r   ztuple[str, int]r   c                  C  s:   t  } | d k	st| jd k	s"tt | j}|j|jfS N)inspectcurrentframeAssertionErrorf_backgetframeinfofilenamelineno)frameinfor   r   r   _here   s
    r   None)r   r   c                 C  s   dddd}|  t  \}}t| dks.t| t}t|jtsHtd|jjd ks\td|jjd ksptd	|jjd kstd
|jjd kst|j	|kst|j
|d kstd S )Nr    r   c                   S  s   t ddddd d S )NZice1.2r   waterissueinsteadr   r   r   r   r   deprecated_thing#   s    z.test_warn_deprecated.<locals>.deprecated_thingr   zice is deprecatedr   zTrio 1.2zwater instead	/issues/1)r   lenr   popDeprecationWarning
isinstancemessageWarningargsr   r   )r   r'   r   r   gotr   r   r   test_warn_deprecated"   s    

r1   c                 C  sz   t ddd d d t| dks t| t}t|jts:td|jjd ksNtd|jjd ksbtd|jjd ksvtd S )	Nr"   1.3r#   r   zwater is deprecatedr   zno replacementzTrio 1.3)	r   r)   r   r*   r+   r,   r-   r.   r/   r   r0   r   r   r   (test_warn_deprecated_no_instead_or_issue3   s    
r4   c                   s^   dd fdd}dddd t  \}}|  | t}|j|ksHt|j|d ksZtd S )Nr    r   c                     s
      d S r   r   r   nested2r   r   nested1A   s    z0test_warn_deprecated_stacklevel.<locals>.nested1c                   S  s   t dddddd d S )Nxr2      y   )r$   r%   
stacklevelr&   r   r   r   r   r6   D   s    z0test_warn_deprecated_stacklevel.<locals>.nested2r   )r   r*   r+   r   r   r   )r   r7   r   r   r0   r   r5   r   test_warn_deprecated_stacklevel@   s    

r=   c                   C  s   d S r   r   r   r   r   r   oldN   s    r>   c                   C  s   d S r   r   r   r   r   r   newR   s    r?   c                 C  sV   t tddtd | t}t|jts*td|jj	d ks>td|jj	d ksRtd S )N1.0r   r#   z test_deprecate.old is deprecatedr   ztest_deprecate.new instead)
r   r>   r?   r*   r+   r,   r-   r.   r   r/   r3   r   r   r   test_warn_deprecated_formattingV   s
    
rA   1.5{   r#   intc                   C  s   dS )Nr;   r   r   r   r   r   deprecated_old^   s    rE   c                 C  s|   t  dkst| t}t|jts(td|jjd ks<td|jjd ksPtd|jjd ksdtd|jjd ksxtd S )Nr;   z+test_deprecate.deprecated_old is deprecatedr   rB   ztest_deprecate.newz
issues/123)rE   r   r*   r+   r,   r-   r.   r/   r3   r   r   r   test_deprecated_decoratorc   s    
rF   c                   @  s(   e Zd ZeddddddddZd	S )
Foor@   rC   Zcryingr#   rD   r   c                 C  s   dS )Nr9   r   selfr   r   r   methodn   s    z
Foo.methodN)__name__
__module____qualname__r   rJ   r   r   r   r   rG   m   s   rG   c                 C  sH   t  }| dkst| t}t|jts0td|jjd ksDtd S )Nr9   z'test_deprecate.Foo.method is deprecatedr   )	rG   rJ   r   r*   r+   r,   r-   r.   r/   )r   fr0   r   r   r    test_deprecated_decorator_methods   s
    
rO   r!   z	the thing)thingr$   r%   c                   C  s   dS )NH   r   r   r   r   r   deprecated_with_thing{   s    rR   c                 C  s@   t  dkst| t}t|jts(td|jjd ks<td S )NrQ   zthe thing is deprecatedr   )rR   r   r*   r+   r,   r-   r.   r/   r3   r   r   r   -test_deprecated_decorator_with_explicit_thing   s    
rS   strc                   C  s   dS )Nnew hotnessr   r   r   r   r   new_hotness   s    rV   old_hotness1.23r$   c                 C  s   t  dkst| t}t|jts(td|jjd ks<td|jjd ksPtd|jjd ksdtd|jjd ksxttt jt	stdt jkstdt jkstdt jkstd S )	NrU   z(test_deprecate.old_hotness is deprecatedr   rX   z"test_deprecate.new_hotness insteadzissues/1z.. deprecated:: 1.23zissues/1>`__)
rW   r   r*   r+   r,   r-   r.   r/   __doc__rT   r3   r   r   r   test_deprecated_alias   s    
r[   c                   @  s*   e Zd ZddddZededddZd	S )
AliasrT   r   c                 C  s   dS )Nnew hotness methodr   rH   r   r   r   new_hotness_method   s    zAlias.new_hotness_methodzAlias.old_hotness_methodz3.21r   rY   N)rK   rL   rM   r^   r   old_hotness_methodr   r   r   r   r\      s   r\   c                 C  sX   t  }| dkst| t}t|jts0t|jjd }d|ksHtd|ksTtd S )Nr]   r   z5test_deprecate.Alias.old_hotness_method is deprecatedz/test_deprecate.Alias.new_hotness_method instead)	r\   r_   r   r*   r+   r,   r-   r.   r/   )r   objr0   msgr   r   r   test_deprecated_alias_method   s    
rb   z2.1hic                   C  s   dS zHello!Nr   r   r   r   r   docstring_test1   s    re   c                   C  s   dS rd   r   r   r   r   r   docstring_test2   s    rf   c                   C  s   dS rd   r   r   r   r   r   docstring_test3   s    rg   c                   C  s   dS rd   r   r   r   r   r   docstring_test4   s    rh   c                   C  s<   t jdksttjdksttjdks*ttjdks8td S )NzHello!

.. deprecated:: 2.1
   Use hi instead.
   For details, see `issue #1 <https://github.com/python-trio/trio/issues/1>`__.

z0Hello!

.. deprecated:: 2.1
   Use hi instead.

znHello!

.. deprecated:: 2.1
   For details, see `issue #1 <https://github.com/python-trio/trio/issues/1>`__.

zHello!

.. deprecated:: 2.1

)re   rZ   r   rf   rg   rh   r   r   r   r   !test_deprecated_docstring_munging   s     ri   c              	   C  s  t jdkstt| dkstt \}}t jdks6t| t}t|j	t
sPt|j|ks^t|j|d ksptd|j	jd kstd|j	jd kstd|j	jd kstd|j	jd kstt jd	kst| t}t|j	t
std
|j	jd ksttt t j W 5 Q R X d S )Nrc   r   Zvalue1r   zmodule_with_deprecations.dep1zTrio 1.1r(   zvalue1 insteadZvalue2zinstead-string instead)r	   Zregularr   r)   r   Zdep1r*   r+   r,   r-   r.   r   r   r/   Zdep2pytestZraisesAttributeErrorZasdf)r   r   r   r0   r   r   r   test_module_with_deprecations   s$    


rl   c                	   C  sv   t   tddd d d W 5 Q R X t t tddd d d W 5 Q R X t t tddd d dd W 5 Q R X d S )NZfoobarr#   T)r$   r%   Zuse_triodeprecationwarning)rj   Zdeprecated_callr   Zwarnsr+   r   r   r   r   r   test_warning_class  s    
rn   )'
__future__r   r   r   rj   Z
_deprecater   r   r   r    r	   Zfixturer   r   r1   r4   r=   r>   r?   rA   rE   rF   rG   rO   rR   rS   rV   rW   r[   r\   rb   re   rf   rg   rh   ri   rl   rn   r   r   r   r   <module>   sL   
	
*