o
    US`ca                     @   sx  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 Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zeddeddd Zdd ZG dd dZdd  Zed!d"ddd#d$d% Zd&d' Zd(d) Zed*ed+dd,Zd-d. ZG d/d0 d0Zd1d2 Zed3dd4dd5d6 Zed3dd4dd7d8 Zed3dddd9d: Z ed3dddd;d< Z!d=d> Z"d?d@ Z#dS )A    N   )TrioDeprecationWarningwarn_deprecated
deprecateddeprecated_alias   )module_with_deprecationsc                 C   s   t d t dt | S )Nalwaysignore)warningssimplefilterResourceWarning)Zrecwarn r   D/usr/local/lib/python3.10/dist-packages/trio/tests/test_deprecate.pyrecwarn_always   s   
r   c                  C   s   t t  j} | j| jfS N)inspectgetframeinfocurrentframef_backfilenamelineno)infor   r   r   _here   s   r   c                 C   s   dd }|  t  \}}t| dksJ | t}d|jjd v s#J d|jjd v s-J d|jjd v s7J d|jjd v sAJ |j|ksHJ |j|d ksQJ d S )	Nc                   S   s   t ddddd d S )N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   lenpopr   messageargsr   r   )r   r!   r   r   gotr   r   r   test_warn_deprecated   s   

r(   c                 C   sj   t ddd d d t| dksJ | t}d|jjd v sJ d|jjd v s)J d|jjd v s3J 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   r   (test_warn_deprecated_no_instead_or_issue.   s   
r+   c                    sR    fdd}dd  t  \}}|  | t}|j|ksJ |j|d ks'J d S )Nc                      s
      d S r   r   r   nested2r   r   nested19   s   
z0test_warn_deprecated_stacklevel.<locals>.nested1c                   S   s   t dddddd d S )Nxr)      y   )r   r   
stacklevelr    r   r   r   r   r-   <   s   z0test_warn_deprecated_stacklevel.<locals>.nested2r   )r   r$   r   r   r   )r   r.   r   r   r'   r   r,   r   test_warn_deprecated_stacklevel8   s   

r4   c                   C      d S r   r   r   r   r   r   oldF      r6   c                   C   r5   r   r   r   r   r   r   newJ   r7   r8   c                 C   sF   t tddtd | t}d|jjd v sJ d|jjd v s!J d S )N1.0r   r   z test_deprecate.old is deprecatedr   ztest_deprecate.new instead)r   r6   r8   r$   r   r%   r&   r*   r   r   r   test_warn_deprecated_formattingN   s   
r:   1.5{   r   c                   C      dS )Nr2   r   r   r   r   r   deprecated_oldU      r>   c                 C   sl   t  dksJ | t}d|jjd v sJ d|jjd v s J d|jjd v s*J d|jjd v s4J d S )Nr2   z+test_deprecate.deprecated_old is deprecatedr   r;   ztest_deprecate.newz
issues/123)r>   r$   r   r%   r&   r*   r   r   r   test_deprecated_decoratorZ   s   
r@   c                   @   s"   e Zd Zedddddd ZdS )Foor9   r<   Zcryingr   c                 C   r=   )Nr0   r   selfr   r   r   methodd   r?   z
Foo.methodN)__name__
__module____qualname__r   rD   r   r   r   r   rA   c   s    rA   c                 C   s8   t  }| dksJ | t}d|jjd v sJ d S )Nr0   z'test_deprecate.Foo.method is deprecatedr   )rA   rD   r$   r   r%   r&   )r   fr'   r   r   r    test_deprecated_decorator_methodi   s   
rI   r   z	the thing)thingr   r   c                   C   r=   )NH   r   r   r   r   r   deprecated_with_thingp   r?   rL   c                 C   s0   t  dksJ | t}d|jjd v sJ d S )NrK   zthe thing is deprecatedr   )rL   r$   r   r%   r&   r*   r   r   r   -test_deprecated_decorator_with_explicit_thingu   s   
rM   c                   C   r=   )Nnew hotnessr   r   r   r   r   new_hotness{   r7   rO   old_hotness1.23r   c                 C   s   t  dksJ | t}d|jjd v sJ d|jjd v s J d|jjd v s*J d|jjd v s4J dt jv s;J dt jv sBJ dt jv sIJ d S )	NrN   z(test_deprecate.old_hotness is deprecatedr   rQ   z"test_deprecate.new_hotness insteadzissues/1z.. deprecated:: 1.23zissues/1>`__)rP   r$   r   r%   r&   __doc__r*   r   r   r   test_deprecated_alias   s   
rT   c                   @   s$   e Zd Zdd ZededddZdS )Aliasc                 C   r=   )Nnew hotness methodr   rB   r   r   r   new_hotness_method   r7   zAlias.new_hotness_methodzAlias.old_hotness_methodz3.21r   rR   N)rE   rF   rG   rW   r   old_hotness_methodr   r   r   r   rU      s
    
rU   c                 C   sH   t  }| dksJ | t}|jjd }d|v sJ d|v s"J d S )NrV   r   z5test_deprecate.Alias.old_hotness_method is deprecatedz/test_deprecate.Alias.new_hotness_method instead)rU   rX   r$   r   r%   r&   )r   objr'   msgr   r   r   test_deprecated_alias_method   s   
r[   z2.1hic                   C   r=   zHello!Nr   r   r   r   r   docstring_test1       r^   c                   C   r=   r]   r   r   r   r   r   docstring_test2   r_   r`   c                   C   r=   r]   r   r   r   r   r   docstring_test3   r_   ra   c                   C   r=   r]   r   r   r   r   r   docstring_test4   r_   rb   c                   C   s<   t jdksJ tjdksJ tjdksJ tjdksJ 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

)r^   rS   r`   ra   rb   r   r   r   r   !test_deprecated_docstring_munging   s    
rc   c                 C   s  t jdksJ t| dksJ t \}}t jdksJ | t}|j|ks'J |j|d ks0J d|j	j
d v s:J d|j	j
d v sDJ d|j	j
d v sNJ d|j	j
d v sXJ t jd	ks_J | t}d
|j	j
d v snJ tt t j W d    d S 1 sw   Y  d S )Nr\   r   Zvalue1r   zmodule_with_deprecations.dep1zTrio 1.1r"   zvalue1 insteadZvalue2zinstead-string instead)r   Zregularr#   r   Zdep1r$   r   r   r   r%   r&   Zdep2pytestZraisesAttributeErrorZasdf)r   r   r   r'   r   r   r   test_module_with_deprecations   s"   


"rf   )$rd   r   r   Z
_deprecater   r   r   r    r   Zfixturer   r   r(   r+   r4   r6   r8   r:   r>   r@   rA   rI   rL   rM   rO   rP   rT   rU   r[   r^   r`   ra   rb   rc   rf   r   r   r   r   <module>   sJ    


	
		



*