o
    Óó·ié£  ã                   @   sô  d Z ddlZddlZddlZddlZddlmZ ddlmZmZ zddl	m
Z
 W n ey3   dZ
Y nw ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ dd	lmZ dd
l m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' G dd„ dƒZ(G dd„ de'ƒZ)G dd„ de'ƒZ*G dd„ de%e'ƒZ+G dd„ de'ƒZ,dd„ Z-dd„ Z.G dd„ de'ƒZ/eeddd d!ƒƒG d"d#„ d#ƒƒZ0G d$d%„ d%ƒZ1eedd&d dƒd'ƒd2d(d)„ƒZ2G d*d+„ d+e'ƒZ3G d,d-„ d-e'ƒZ4G d.d/„ d/e'ƒZ5G d0d1„ d1e'ƒZ6dS )3zI
Tests for Twisted's deprecation framework, L{twisted.python.deprecate}.
é    N)Únormcase)Úcatch_warningsÚsimplefilter)Úinvalidate_caches)ÚVersion)Ú	deprecate)ÚDEPRECATION_WARNING_FORMATÚ_appendToDocstringÚ_fullyQualifiedNameÚ_getDeprecationDocstringÚ_getDeprecationWarningStringÚ_mutuallyExclusiveArgumentsÚ_passedArgSpecÚ_passedSignatureÚ
deprecatedÚdeprecatedKeywordParameterÚdeprecatedPropertyÚgetDeprecationWarningString)ÚFilePath)Úplatform)Údeprecatedattributes)ÚTwistedModulesMixin)ÚSynchronousTestCasec                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )Ú_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    c                 C   ó
   || _ d S ©N©Úvalue©Úselfr   © r!   úhC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/python/test/test_deprecate.pyÚ__init__8   ó   
z!_MockDeprecatedAttribute.__init__c                 C   ó   | j S )z$
        Get a known value.
        Nr   ©r    r!   r!   r"   Úget;   s   z_MockDeprecatedAttribute.getN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r'   r!   r!   r!   r"   r   1   s    r   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚModuleProxyTestszÔ
    Tests for L{twisted.python.deprecate._ModuleProxy}, which proxies
    access to module-level attributes, intercepting access to deprecated
    attributes and passing through access to normal attributes.
    c                 K   s2   t  d¡}| ¡ D ]
\}}t|||ƒ q	t |¡S )zÀ
        Create a temporary module proxy object.

        @param **kw: Attributes to initialise on the temporary module object

        @rtype: L{twistd.python.deprecate._ModuleProxy}
        ÚfooN)ÚtypesÚ
ModuleTypeÚitemsÚsetattrr   Z_ModuleProxy)r    ÚattrsÚmodÚkeyr   r!   r!   r"   Ú
_makeProxyI   s   

zModuleProxyTests._makeProxyc                 C   s.   | j dd�}|  |jd¡ |  tt|d¡ dS )zÜ
        Getting a normal attribute on a L{twisted.python.deprecate._ModuleProxy}
        retrieves the underlying attribute's value, and raises C{AttributeError}
        if a non-existent attribute is accessed.
        Zhello)ÚSOME_ATTRIBUTEZDOES_NOT_EXISTN)r5   ÚassertIsr6   ÚassertRaisesÚAttributeErrorÚgetattr©r    Úproxyr!   r!   r"   Útest_getattrPassthroughV   s   z(ModuleProxyTests.test_getattrPassthroughc                 C   s2   |   ¡ }t |d¡}tdƒ|d< |  |jd¡ dS )z¸
        Getting an attribute marked as being deprecated on
        L{twisted.python.deprecate._ModuleProxy} results in calling the
        deprecated wrapper's C{get} method.
        Ú_deprecatedAttributesé*   r-   N)r5   ÚobjectÚ__getattribute__r   ÚassertEqualr-   )r    r<   r>   r!   r!   r"   Útest_getattrIntercept`   s   z&ModuleProxyTests.test_getattrInterceptc                 C   s,   |   ¡ }|  tt|d¡ |  tt|d¡ dS )z�
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        Ú_moduler>   N)r5   r8   r9   r:   r;   r!   r!   r"   Útest_privateAttributesk   s   z'ModuleProxyTests.test_privateAttributesc                 C   s4   |   ¡ }d|_|  t |d¡d¡ |  |jd¡ dS )z„
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
        é   rD   N)r5   rD   ÚassertNotEqualr@   rA   rB   r;   r!   r!   r"   Útest_setattrt   s   zModuleProxyTests.test_setattrc                 C   s<   |   ¡ }t |d¡}|  t|ƒdt|ƒj› d|›d�¡ dS )z³
        L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string
        containing the proxy type and a representation of the wrapped module
        object.
        rD   ú<z module=ú>N)r5   r@   rA   rB   ÚreprÚtyper(   )r    r<   Z
realModuler!   r!   r"   Ú	test_repr~   s   (zModuleProxyTests.test_reprN)
r(   r)   r*   r+   r5   r=   rC   rE   rH   rM   r!   r!   r!   r"   r,   B   s    
	
r,   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚDeprecatedAttributeTestszÄ
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    c                 C   s   t j| _t j| _td | _d S )Nz.foo)r   ÚversionÚmessager(   Ú_testModuleNamer&   r!   r!   r"   ÚsetUp�   s   zDeprecatedAttributeTests.setUpc                 C   s"   t tjd | tjtd tj ƒS )zJ
        Create the warning string used by deprecated attributes.
        Ú.z: N)r   r   r(   rO   r   rP   )r    Úattrr!   r!   r"   Ú_getWarningString•   s
   ýz*DeprecatedAttributeTests._getWarningStringc                    s”   d}t t|dƒ t t|| j| j¡‰ |  ˆ j|¡ ‡ fdd„}|ƒ  |  | j	g¡}|  
|d d t¡ |  |d d |  |¡¡ |  t|ƒd¡ d	S )
zÛ
        L{twisted.python.deprecate._DeprecatedAttribute} correctly sets its
        __name__ to match that of the deprecated attribute and emits a warning
        when the original attribute value is accessed.
        ZANOTHER_DEPRECATED_ATTRIBUTEr?   c                      s   ˆ   ¡  d S r   )r'   r!   ©rT   r!   r"   ÚaddStackLevel¯   s   zNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevelr   ÚcategoryrP   rF   N)r1   r   r   Z_DeprecatedAttributerO   rP   rB   r(   ÚflushWarningsÚtest_deprecatedAttributeHelperr7   ÚDeprecationWarningrU   Úlen)r    ÚnamerW   ÚwarningsShownr!   rV   r"   rZ   Ÿ   s   ÿz7DeprecatedAttributeTests.test_deprecatedAttributeHelperc                 C   s‚   t j |  | jg¡}|  t|ƒd¡ d}tt |ƒ |  | jg¡}|  t|ƒd¡ |  |d d t¡ |  |d d |  	|¡¡ dS )a  
        L{twisted.python.deprecate.deprecatedModuleAttribute} wraps a
        module-level attribute in an object that emits a deprecation warning
        when it is accessed the first time only, while leaving other unrelated
        attributes alone.
        r   ZDEPRECATED_ATTRIBUTErF   rX   rP   N)
r   ZANOTHER_ATTRIBUTErY   Útest_deprecatedAttributerB   r\   r:   r7   r[   rU   )r    r^   r]   r!   r!   r"   r_   ¹   s   
z1DeprecatedAttributeTests.test_deprecatedAttributec                 C   s¨   t  d¡ tj| j< }|  tjj| j¡ t|ddƒ t|ddƒ t 	t
ddddƒd	| jd¡ tj| j }|  ||¡ t 	t
ddddƒd	| jd¡ |  |tj| j ¡ d
S )zï
        Deprecating an attribute in a module replaces and wraps that module
        instance, in C{sys.modules}, with a
        L{twisted.python.deprecate._ModuleProxy} instance but only if it hasn't
        already been wrapped.
        r-   ÚfirstrF   Úsecondé   ÚTwistedé   r   rP   N)r.   r/   ÚsysÚmodulesrQ   Ú
addCleanupÚpopr1   r   ZdeprecatedModuleAttributer   rG   r7   )r    r3   r<   r!   r!   r"   Útest_wrappedModuleÐ   s   ÿÿz+DeprecatedAttributeTests.test_wrappedModuleN)	r(   r)   r*   r+   rR   rU   rZ   r_   ri   r!   r!   r!   r"   rN   ‰   s    
rN   c                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚImportedModuleAttributeTestsza
    Tests for L{deprecatedModuleAttribute} which involve loading a module via
    'import'.
    z»from twisted.python.deprecate import deprecatedModuleAttribute
from incremental import Version

deprecatedModuleAttribute(
    Version('Package', 1, 2, 3), 'message', __name__, 'module')
c                    s^   ‡ fdd„‰ t |  ¡  d¡ƒ}| ¡  ˆ ||ƒ}|  |j d¡gtj ¡ |  tj	 
¡ ¡ |S )a_  
        Create some files in a hierarchy, based on a dictionary describing those
        files.  The resulting hierarchy will be placed onto sys.path for the
        duration of the test.

        @param tree: A dictionary representing a directory structure.  Keys are
            strings, representing filenames, dictionary values represent
            directories, string values represent file contents.

        @return: another dictionary similar to the input, with file content
            strings replaced with L{FilePath} objects pointing at where those
            contents are now stored.
        c                    sj   i }|  ¡ D ],\}}|  |¡}t|tƒr|||< | |¡ qt|tƒr/| ¡  ˆ ||ƒ||< qtdƒ‚|S )Nz(only strings and dicts allowed as values)r0   ÚchildÚ
isinstanceÚbytesÚ
setContentÚdictZcreateDirectoryÚ
ValueError)ZpathobjZdirdictZpathdictr4   r   rk   ©ÚmakeSomeFilesr!   r"   rr     s   


zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFilesúutf-8N)r   ÚmktempÚencodeÚmakedirsZreplaceSysPathÚpathÚdecodere   ZreplaceSysModulesrf   Úcopy)r    ÚtreeÚbaseÚresultr!   rq   r"   ÚpathEntryTreeù   s   
z*ImportedModuleAttributeTests.pathEntryTreec                 C   s(   |   d| j d¡ddœi¡}|d d S )z¢
        Add a sample module and package to the path, returning a L{FilePath}
        pointing at the module which will be loadable as C{package.module}.
        s   packagers   ó    )s   __init__.pyó	   module.pyr   N)r}   Ú_packageInitru   )r    Úpathsr!   r!   r"   ÚsimpleModuleEntry  s   
þÿÿz.ImportedModuleAttributeTests.simpleModuleEntryc                 C   sn   ddl m} |  t|j d¡ƒ|¡ |  | jg¡}|  t|ƒd¡ |  |d d d¡ |  |d d t	¡ dS )	zB
        Verification logic for L{test_deprecatedModule}.
        r   ©Úmodulers   rF   rP   z7package.module was deprecated in Package 1.2.3: messagerX   N)
Úpackager„   rB   r   Ú__file__ru   rY   ÚcheckOneWarningr\   r[   )r    Z
modulePathr„   Zemittedr!   r!   r"   r‡   .  s   
þz,ImportedModuleAttributeTests.checkOneWarningc                 C   s   |   |  ¡ ¡ dS )zÇ
        If L{deprecatedModuleAttribute} is used to deprecate a module attribute
        of a package, only one deprecation warning is emitted when the
        deprecated module is imported.
        N)r‡   r‚   r&   r!   r!   r"   Útest_deprecatedModule=  s   z2ImportedModuleAttributeTests.test_deprecatedModulec                 C   s8   |   ¡ }|  |¡ |  |¡ tdƒD ]}|  |¡ qdS )zÔ
        If L{deprecatedModuleAttribute} is used to deprecate a module attribute
        of a package, only one deprecation warning is emitted when the
        deprecated module is subsequently imported.
        rb   N)r‚   r‡   Úrange)r    ÚmpÚxr!   r!   r"   Ú"test_deprecatedModuleMultipleTimesE  s   

ÿz?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesN)
r(   r)   r*   r+   r€   r}   r‚   r‡   rˆ   rŒ   r!   r!   r!   r"   rj   ë   s    &rj   c                   @   sP   e Zd Z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S )ÚWarnAboutFunctionTestsz¢
    Tests for L{twisted.python.deprecate.warnAboutFunction} which allows the
    callers of a function to issue a C{DeprecationWarning} about that function.
    c                    s²   t |  ¡ ƒ d¡| _| j ¡  | j d¡ d¡ | j d¡ d¡ | j d¡ d¡ | j ¡ j}tj 	d|¡ |  
tjj|¡ tj ¡ ‰ |  
‡ fd	d
„¡ t ¡ rW|  ¡  dS dS )zY
        Create a file that will have known line numbers when emitting warnings.
        Útwisted_private_helperz__init__.pyr~   z	module.pys  
"A module string"

from twisted.python import deprecate

def testFunction():
    "A doc string"
    a = 1 + 2
    return a

def callTestFunction():
    b = testFunction()
    if b == 3:
        deprecate.warnAboutFunction(testFunction, "A Warning String")
z	pep626.pysQ  
"A module string"

from twisted.python import deprecate

def noop():
    pass

def testFunction(a=1, b=1):
    "A doc string"
    if a:
        if b:
            noop()
        else:
            pass

def callTestFunction():
    b = testFunction()
    if b is None:
        deprecate.warnAboutFunction(testFunction, "A Warning String")
r   c                      s   t j ¡ t j ˆ ¡fS r   )re   rf   ÚclearÚupdater!   ©rf   r!   r"   Ú<lambda>•  s    z.WarnAboutFunctionTests.setUp.<locals>.<lambda>N)r   rt   rk   r…   rv   rn   Úparentrw   re   Úinsertrg   Úremoverf   ry   r   Z	isWindowsrY   )r    ZpackagePathr!   r‘   r"   rR   `  s"   
ÿÿ
ÿzWarnAboutFunctionTests.setUpc                 C   sn   dd„ }t  |d¡ |  ¡ }t}| ¡  d¡r|dd… }|  t|d d ƒt|ƒ¡ |  |d d	 d¡ dS )
z½
        L{deprecate.warnAboutFunction} emits a warning the file and line number
        of which point to the beginning of the implementation of the function
        passed to it.
        c                   S   ó   d S r   r!   r!   r!   r!   r"   ÚaFunc¤  ó   z2WarnAboutFunctionTests.test_warning.<locals>.aFunczA Warning Messagez.pycNéÿÿÿÿr   ÚfilenamerP   )	r   ZwarnAboutFunctionrY   r†   ÚlowerÚendswithÚassertSamePathr   rB   )r    r—   r^   rš   r!   r!   r"   Útest_warning�  s   z#WarnAboutFunctionTests.test_warningc                 C   ó„   ddl m} | ¡  |  ¡ }|  t|d d  d¡ƒ| j d¡ 	d¡¡ |  
|d d d¡ |  
|d d	 d
¡ |  
t|ƒd¡ dS )z¨
        L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the
        number of a line within the implementation of the function passed to it.
        r   rƒ   rš   rs   ó   twisted_private_helperr   Úlinenoé	   rP   úA Warning StringrF   N)rŽ   r„   ÚcallTestFunctionrY   r�   r   ru   r…   Úsiblingrk   rB   r\   ©r    r„   r^   r!   r!   r"   Útest_warningLineNumber¯  s   þz-WarnAboutFunctionTests.test_warningLineNumberc                 C   rŸ   )zã
        L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the
        number of a line within the implementation handling the case in which
        dis.findlinestarts returns the lines in random order.
        r   )Úpep626rš   rs   r    s	   pep626.pyr¡   é   rP   r£   rF   N)rŽ   r¨   r¤   rY   r�   r   ru   r…   r¥   rk   rB   r\   )r    r¨   r^   r!   r!   r"   Ú'test_warningLineNumberDisFindlinestartsÂ  s   þz>WarnAboutFunctionTests.test_warningLineNumberDisFindlinestartsc                 C   s*   |   t|jƒt|jƒk|›d|›�¡ dS )a  
        Assert that the two paths are the same, considering case normalization
        appropriate for the current platform.

        @type first: L{FilePath}
        @type second: L{FilePath}

        @raise C{self.failureType}: If the paths are not the same.
        z != N)Ú
assertTruer   rw   )r    r`   ra   r!   r!   r"   r�   Ö  s   
þz%WarnAboutFunctionTests.assertSamePathc                 C   sð   ddl m} tjd= tj|j= | j | j d¡¡ trtƒ  ddl	m} |  
tjjd¡ |  
tjj|j¡ | ¡  |  |jg¡}t|d d  d¡ƒ}| j d¡ d¡}|  ||¡ |  |d d	 d
¡ |  |d d d¡ |  t|ƒd¡ dS )a  
        Even if the implementation of a deprecated function is moved around on
        the filesystem, the line number in the warning emitted by
        L{deprecate.warnAboutFunction} points to a line in the implementation of
        the deprecated function.
        r   rƒ   rŽ   s   twisted_renamed_helperÚtwisted_renamed_helperrš   rs   r   r¡   r¢   rP   r£   rF   N)rŽ   r„   re   rf   r(   r…   ZmoveTor¥   r   r¬   rg   rh   r¤   rY   ZtestFunctionr   ru   rk   r�   rB   r\   )r    r„   r^   Z
warnedPathZexpectedPathr!   r!   r"   Útest_renamedFileå  s&   
ÿz'WarnAboutFunctionTests.test_renamedFilec                 C   sJ   t jdd…= t jddd� ddlm} | ¡  |  ¡ }|  t|ƒd¡ dS )z¾
        L{deprecate.warnAboutFunction} emits a warning that will be filtered if
        L{warnings.filterwarning} is called with the module name of the
        deprecated function.
        NÚignorerŽ   ©Úactionr„   r   rƒ   )	ÚwarningsÚfiltersÚfilterwarningsrŽ   r„   r¤   rY   rB   r\   r¦   r!   r!   r"   Útest_filteredWarning  s   	z+WarnAboutFunctionTests.test_filteredWarningc                 C   sª   t jdd…= t jddd� ddlm} | ¡  | ¡  |  ¡ }|  t|ƒd¡ |d d }|d d	 }|d d
 }|d d }t  	||||¡}|  
| d¡d|›�¡ dS )zÙ
        L{deprecate.warnAboutFunction} emits a warning that will be filtered
        once if L{warnings.filterwarning} is called with the module name of the
        deprecated function and an action of once.
        Nr„   rŽ   r¯   r   rƒ   rF   rP   rX   rš   r¡   z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: )r±   r²   r³   rŽ   r„   r¤   rY   rB   r\   Úformatwarningr«   rœ   )r    r„   r^   rP   rX   rš   r¡   Úmsgr!   r!   r"   Útest_filteredOnceWarning  s$   	ÿüz/WarnAboutFunctionTests.test_filteredOnceWarningN)r(   r)   r*   r+   rR   rž   r§   rª   r�   r­   r´   r·   r!   r!   r!   r"   r�   Z  s    =&r�   c                   C   ó   dS )zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr!   r!   r!   r!   r"   ÚdummyCallable@  ó    r¹   c                   C   r¸   )z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr!   r!   r!   r!   r"   ÚdummyReplacementMethodH  rº   r»   c                   @   sT   e Z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S )ÚDeprecationWarningsTestsc                 C   s,   t ddddƒ}|  t| j|ƒdtf ¡ dS )z 
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        rc   rd   r   z\%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)r   rB   r   Ú test_getDeprecationWarningStringr(   ©r    rO   r!   r!   r"   r½   Q  s   
ÿþz9DeprecationWarningsTests.test_getDeprecationWarningStringc                 C   s6   t ddddƒ}td }|  t| j||ƒdtf ¡ dS )zð
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted, with
        a message containing additional information about the deprecation.
        rc   rd   r   z: This is a messagezo%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)r   r   rB   r   r½   r(   )r    rO   Úformatr!   r!   r"   Ú*test_getDeprecationWarningStringWithFormat]  s   ÿÿüzCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormatc                    s°   t ddddƒ}t|ƒtƒ‰ ‡ fdd„}tdd��6}tdƒ |ƒ  |  |d jt¡ |  t|d j	ƒt
t|ƒ¡ |  |d j d	¡t d	¡¡ W d
  ƒ d
S 1 sQw   Y  d
S )zK
        Decorating a callable with L{deprecated} emits a warning.
        rc   rd   r   c                      s
   ˆ ƒ  d S r   r!   r!   ©Údummyr!   r"   rW   t  r$   zJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelT©ÚrecordÚalwaysÚcoN)r   r   r¹   r   r   rB   rX   r[   ÚstrrP   r   rš   Úrstripr†   )r    rO   rW   Zcaughtr!   rÁ   r"   Útest_deprecateEmitsWarningm  s   þ "÷z3DeprecationWarningsTests.test_deprecateEmitsWarningc                 C   sB   t ddddƒ}t|ƒtƒ}|  tj|j¡ |  ttƒt|ƒ¡ dS )zK
        The decorated function has the same name as the original.
        rc   rd   r   N)r   r   r¹   rB   r(   ÚfullyQualifiedName©r    rO   rÂ   r!   r!   r"   Útest_deprecatedPreservesName‚  s   z5DeprecationWarningsTests.test_deprecatedPreservesNamec                 C   s$   t ddddƒ}|  dt|dƒ¡ dS )zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        rc   rd   r   zDeprecated in Twisted 8.0.0.Ú N)r   rB   r   r¾   r!   r!   r"   Útest_getDeprecationDocstring‹  s   
ÿz5DeprecationWarningsTests.test_getDeprecationDocstringc                 C   sF   dd„ }t ddddƒ}t|ƒ|ƒ}t|t|dƒƒ |  |j|j¡ dS )zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        c                   S   r¸   )zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr!   r!   r!   r!   r"   ÚlocalDummyCallable›  rº   zTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallablerc   rd   r   rÍ   N)r   r   r	   r   rB   r+   )r    rÏ   rO   rÂ   r!   r!   r"   Útest_deprecatedUpdatesDocstring•  s
   z8DeprecationWarningsTests.test_deprecatedUpdatesDocstringc                 C   s,   t ddddƒ}t|ƒtƒ}|  ||j¡ dS )zt
        Deprecating a function adds version information to the decorated
        version of that function.
        rc   rd   r   N)r   r   r¹   rB   ÚdeprecatedVersionrË   r!   r!   r"   Útest_versionMetadata©  s   z-DeprecationWarningsTests.test_versionMetadatac                 C   s:   t ddddƒ}t| j|dd�}|  |dt| jƒf ¡ dS )a  
        L{getDeprecationWarningString} takes an additional replacement parameter
        that can be used to add information to the deprecation.  If the
        replacement parameter is a string, it will be interpolated directly into
        the result.
        rc   rd   r   úsomething.foobar©ÚreplacementzG%s was deprecated in Twisted 8.0.0; please use something.foobar insteadN)r   r   r½   rB   rÊ   ©r    rO   ZwarningStringr!   r!   r"   Ú+test_getDeprecationWarningStringReplacement²  s   ý
ÿþzDDeprecationWarningsTests.test_getDeprecationWarningStringReplacementc                 C   s<   t ddddƒ}t| j|td�}|  |dt| jƒtf ¡ dS )a  
        L{getDeprecationWarningString} takes an additional replacement parameter
        that can be used to add information to the deprecation. If the
        replacement parameter is a callable, its fully qualified name will be
        interpolated into the result.
        rc   rd   r   rÔ   zP%s was deprecated in Twisted 8.0.0; please use %s.dummyReplacementMethod insteadN)r   r   r½   r»   rB   rÊ   r(   rÖ   r!   r!   r"   Ú7test_getDeprecationWarningStringReplacementWithCallableÅ  s   ýþþzPDeprecationWarningsTests.test_getDeprecationWarningStringReplacementWithCallableN)r(   r)   r*   r½   rÀ   rÉ   rÌ   rÎ   rÐ   rÒ   r×   rØ   r!   r!   r!   r"   r¼   P  s    	
	r¼   rc   rF   rb   é   c                   @   s   e Zd ZdZdS )ÚDeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r(   r)   r*   r+   r!   r!   r!   r"   rÚ   Ú  s    rÚ   c                   @   s<   e Zd ZdZdZeeddddƒƒdd„ ƒZejd	d„ ƒZdS )
ÚClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    Nrc   rF   rb   rÙ   c                 C   r%   )zC
        Getter docstring.

        @return: The property.
        N©Ú_someProtectedValuer&   r!   r!   r"   ÚsomePropertyè  s   z(ClassWithDeprecatedProperty.somePropertyc                 C   s
   || _ dS )z#
        Setter docstring.
        NrÜ   r   r!   r!   r"   rÞ   ñ  s   
)	r(   r)   r*   r+   rÝ   r   r   rÞ   Úsetterr!   r!   r!   r"   rÛ   á  s    
rÛ   é   r-   c                 C   r¸   )z7
    Function with a deprecated keyword parameter.
    Nr!   )ÚaÚbÚcr-   Úbarr!   r!   r"   ÚfunctionWithDeprecatedParameterù  rº   rå   c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚDeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    c                 C   s    |   |dd„ |j ¡ D ƒ¡ dS )a8  
        Check that C{target} object has the C{expected} docstring lines.

        @param target: Object which is checked.
        @type target: C{anything}

        @param expected: List of lines, ignoring empty lines or leading or
            trailing spaces.
        @type expected: L{list} or L{str}
        c                 S   s   g | ]
}|  ¡ r|  ¡ ‘qS r!   )Ústrip)Ú.0r‹   r!   r!   r"   Ú
<listcomp>  s    z<DeprecatedDecoratorTests.assertDocstring.<locals>.<listcomp>N)rB   r+   Ú
splitlines)r    ÚtargetÚexpectedr!   r!   r"   ÚassertDocstring  s   ÿz(DeprecatedDecoratorTests.assertDocstringc                 C   s~   t ƒ }|j |  t jg d¢¡ tddddƒt j_d}|  | jg¡}|  dt|ƒ¡ |  t	|d d ¡ |  ||d d	 ¡ d
S )a%  
        When L{deprecatedProperty} is used on a C{property}, accesses raise a
        L{DeprecationWarning} and getter docstring is updated to inform the
        version in which it was deprecated. C{deprecatedVersion} attribute is
        also set to inform the deprecation version.
        )zGetter docstring.z@return: The property.úDeprecated in Twisted 1.2.3.rc   rF   rb   rÙ   úktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3r   rX   rP   N)
rÛ   rÞ   rí   r   rÑ   rY   Útest_propertyGetterrB   r\   r[   )r    ÚobjrP   r±   r!   r!   r"   rð     s   þÿÿz,DeprecatedDecoratorTests.test_propertyGetterc                 C   sn   t ƒ }tƒ }||_|  ||j¡ d}|  | jg¡}|  dt|ƒ¡ |  t	|d d ¡ |  ||d d ¡ dS )z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        rï   rF   r   rX   rP   N)
r@   rÛ   rÞ   r7   rÝ   rY   Útest_propertySetterrB   r\   r[   )r    ZnewValuerñ   rP   r±   r!   r!   r"   rò   4  s   ÿz,DeprecatedDecoratorTests.test_propertySetterc                 C   st   t ƒ  |  t ddg¡ tddddƒt _d}|  | jg¡}|  dt|ƒ¡ |  t|d d	 ¡ |  ||d d
 ¡ dS )a  
        When L{deprecated} is used on a class, instantiations raise a
        L{DeprecationWarning} and class's docstring is updated to inform the
        version in which it was deprecated. C{deprecatedVersion} attribute is
        also set to inform the deprecation version.
        z@Class which is entirely deprecated without having a replacement.rî   rc   rF   rb   rÙ   zRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3r   rX   rP   N)	rÚ   rí   r   rÑ   rY   Ú
test_classrB   r\   r[   )r    rP   r±   r!   r!   r"   ró   H  s   þþÿz#DeprecatedDecoratorTests.test_classc                 C   s.   t ddddƒ}t|dƒtƒ}|  |jd¡ dS )a  
        L{deprecated} takes an additional replacement parameter that can be used
        to indicate the new, non-deprecated method developers should use.  If
        the replacement parameter is a string, it will be interpolated directly
        into the warning message.
        rc   rd   r   rÓ   z‚
Do nothing.

This is used to test the deprecation decorators.

Deprecated in Twisted 8.0.0; please use something.foobar instead.
N)r   r   r¹   rB   r+   rË   r!   r!   r"   Útest_deprecatedReplacementc  s   þz3DeprecatedDecoratorTests.test_deprecatedReplacementc                 C   s:   t ddddƒ}t|td�}|tƒ}|  |jd t¡¡ dS )a)  
        L{deprecated} takes an additional replacement parameter that can be used
        to indicate the new, non-deprecated method developers should use.  If
        the replacement parameter is a callable, its fully qualified name will
        be interpolated into the warning message.
        rc   rd   r   rÔ   z‹
Do nothing.

This is used to test the deprecation decorators.

Deprecated in Twisted 8.0.0; please use {}.dummyReplacementMethod instead.
N)r   r   r»   r¹   rB   r+   r¿   r(   )r    rO   Ú	decoratorrÂ   r!   r!   r"   Ú&test_deprecatedReplacementWithCallablev  s   úz?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallablec                 C   s  d}t dd��{}tdƒ tddƒ |  |g ¡ tdddƒ |  |g ¡ tdddd	� |  t|ƒd
¡ |  |d jt¡ |  t|d jƒ|¡ | 	¡  tdddd� |  |g ¡ tddddƒ |  t|ƒd
¡ |  |d jt¡ |  t|d jƒ|¡ W d   ƒ d S 1 s…w   Y  d S )NzzThe 'foo' parameter to twisted.python.test.test_deprecate.functionWithDeprecatedParameter was deprecated in Twisted 19.2.0TrÃ   rÅ   é
   é   é   é(   )r-   rF   r   é2   )rä   )
r   r   rå   rB   r\   rX   r[   rÇ   rP   r�   )r    rP   Úwsr!   r!   r"   Útest_deprecatedKeywordParameter‰  s(   ÿ
"ëz8DeprecatedDecoratorTests.test_deprecatedKeywordParameterN)r(   r)   r*   r+   rí   rð   rò   ró   rô   rö   rý   r!   r!   r!   r"   ræ      s     ræ   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚAppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    c                 C   s$   dd„ }t |dƒ |  d|j¡ dS )zP
        Appending to an empty docstring simply replaces the docstring.
        c                   S   r–   r   r!   r!   r!   r!   r"   ÚnoDocstringµ  r˜   zGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstringúAppended text.N©r	   rB   r+   )r    rÿ   r!   r!   r"   Útest_appendToEmptyDocstring°  s   
z2AppendToDocstringTests.test_appendToEmptyDocstringc                 C   s>   dd„ }t |dƒ |  g d¢|j ¡ ¡ |  |j d¡¡ dS )aŽ  
        Appending to a single line docstring places the message on a new line,
        with a blank line separating it from the rest of the docstring.

        The docstring ends with a newline, conforming to Twisted and PEP 8
        standards. Unfortunately, the indentation is incorrect, since the
        existing docstring doesn't have enough info to help us indent
        properly.
        c                   S   r¸   )ú;This doesn't comply with standards, but is here for a test.Nr!   r!   r!   r!   r"   ÚsingleLineDocstringÆ  rº   zTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstringr   )r  rÍ   r   Ú
N)r	   rB   r+   rê   r«   rœ   )r    r  r!   r!   r"   Ú test_appendToSingleLineDocstring»  s   
úz7AppendToDocstringTests.test_appendToSingleLineDocstringc                 C   s$   dd„ }t |dƒ |  d|j¡ dS )zþ
        Appending to a multi-line docstring places the messade on a new line,
        with a blank line separating it from the rest of the docstring.

        Because we have multiple lines, we have enough information to do
        indentation.
        c                   S   r¸   )z9
            This is a multi-line docstring.
            Nr!   r!   r!   r!   r"   ÚmultiLineDocstringÝ  rº   zRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstringr   z1
This is a multi-line docstring.

Appended text.
Nr  )r    r  r!   r!   r"   Útest_appendToMultilineDocstringÔ  s   	
þz6AppendToDocstringTests.test_appendToMultilineDocstringN)r(   r)   r*   r+   r  r  r  r!   r!   r!   r"   rþ   ©  s
    rþ   c                   @   sh   e Zd Z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dd„ ZdS )ÚMutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    c                 O   s0   t tddƒrtt |¡||ƒS tt |¡||ƒS )aÊ  
        Test an invocation of L{passed} with the given function, arguments, and
        keyword arguments.

        @param func: A function whose argspec will be inspected.
        @type func: A callable.

        @param args: The arguments which could be passed to C{func}.

        @param kw: The keyword arguments which could be passed to C{func}.

        @return: L{_passedSignature} or L{_passedArgSpec}'s return value
        @rtype: L{dict}
        Ú	signatureN)r:   Úinspectr   r
  r   Ú
getargspec©r    ÚfuncÚargsÚkwr!   r!   r"   ÚcheckPassedî  s   z(MutualArgumentExclusionTests.checkPassedc                 C   s*   dd„ }|   |  |dd¡tddd�¡ dS )z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        c                 S   r–   r   r!   ©rá   râ   r!   r!   r"   r  
  r˜   zGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.funcrF   rb   r  N©rB   r  ro   ©r    r  r!   r!   r"   Útest_passed_simplePositional  s   "z9MutualArgumentExclusionTests.test_passed_simplePositionalc                 C   s"   dd„ }|   t| j|ddd¡ dS )z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        c                 S   r–   r   r!   r  r!   r!   r"   r    r˜   zBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.funcrF   rb   rÙ   N©r8   Ú	TypeErrorr  r  r!   r!   r"   Útest_passed_tooManyArgs  ó   z4MutualArgumentExclusionTests.test_passed_tooManyArgsc                 C   ó"   dd„ }| j t| j|ddd� dS )zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        c                 S   r–   r   r!   ©rá   r!   r!   r"   r     r˜   zHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.funcrF   rb   r  Nr  r  r!   r!   r"   Útest_passed_doublePassKeyword  r  z:MutualArgumentExclusionTests.test_passed_doublePassKeywordc                 C   r  )z„
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        c                 S   r–   r   r!   r  r!   r!   r"   r  +  r˜   zIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.funcrF   rb   )ÚzNr  r  r!   r!   r"   Útest_passed_unspecifiedKeyword%  r  z;MutualArgumentExclusionTests.test_passed_unspecifiedKeywordc                 C   s,   dd„ }|   |  |ddd¡tddd�¡ dS )	z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        c                 W   r–   r   r!   r  r!   r!   r"   r  6  r˜   z;MutualArgumentExclusionTests.test_passed_star.<locals>.funcrF   rb   rÙ   )rb   rÙ   r  Nr  r  r!   r!   r"   Útest_passed_star0  s   $z-MutualArgumentExclusionTests.test_passed_starc              
   C   s:   dd„ }|   | j|ddddd�tdtdddd�d�¡ d	S )
zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c                 [   r–   r   r!   r  r!   r!   r"   r  A  r˜   z?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcrF   rb   rÙ   é   )r‹   Úyr  r  Nr  r  r!   r!   r"   Útest_passed_starStar;  s   &ÿz1MutualArgumentExclusionTests.test_passed_starStarc                 C   s2   d
dd„}|   | j|dddd�tdddd�¡ d	S )zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rF   rb   rÙ   c                 S   r–   r   r!   ©rá   râ   rã   ÚdÚer!   r!   r"   r  N  r˜   zFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.funcé   )r%  )rá   râ   r%  N©rF   rb   rÙ   r  r  r!   r!   r"   Útest_passed_noDefaultValuesH  s   
(z8MutualArgumentExclusionTests.test_passed_noDefaultValuesc                 C   sT   t dgƒddd„ƒ}|  |ddƒd¡ |  |ddd	ƒd
¡ |  |ddd	d�d¡ dS )z¥
        L{mutuallyExclusiveArguments} does not interfere in its
        decoratee's operation, either its receipt of arguments or its return
        value.
        r  rÙ   r   c                 S   s   | | | | S r   r!   )r‹   r!  rá   râ   r!   r!   r"   r  Z  s   zMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.funcrF   rb   r÷   r&  é   ©râ   é   N©rÙ   r   )r   rB   r  r!   r!   r"   Ú"test_mutualExclusionPrimeDirectiveS  s
   z?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectivec                 C   s.   t ddggƒd	dd„ƒ}| jt|ddd� dS )
z‘
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        rá   râ   rÙ   r   c                 S   s   | | S r   r!   r  r!   r!   r"   r  h  s   zPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funcr  Nr,  )r   r8   r  r  r!   r!   r"   Ú%test_mutualExclusionExcludesByKeywordb  s   zBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordc                 C   sn   G dd„ dƒ}G dd„ dƒ}dd„ }|ddƒ t  |¡j}| ¡ }|d	d	ƒ|d
< ||ƒ}|  tt|di ¡ dS )z²
        Create a fake signature with an invalid parameter
        type to test error handling.  The valid parameter
        types are specified in L{inspect.Parameter}.
        c                   @   ó   e Zd Zdd„ ZdS )zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturec                 S   r   r   )Ú
parameters)r    r0  r!   r!   r"   r#   v  r$   zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__N©r(   r)   r*   r#   r!   r!   r!   r"   ÚFakeSignatureu  ó    r2  c                   @   r/  )zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameterc                 S   s   || _ || _d S r   )r]   Úkind)r    r]   r4  r!   r!   r"   r#   z  s   
zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__Nr1  r!   r!   r!   r"   ÚFakeParametery  r3  r5  c                 S   r–   r   r!   r  r!   r!   r"   r  ~  r˜   zDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.funcrF   rb   Zfakerã   ©rF   rb   N)r  r
  r0  ry   r8   r  r   )r    r2  r5  r  r0  ZdummyParametersZfakeSigr!   r!   r"   Útest_invalidParameterTypen  s   
z6MutualArgumentExclusionTests.test_invalidParameterTypeN)r(   r)   r*   r+   r  r  r  r  r  r  r"  r(  r-  r.  r7  r!   r!   r!   r"   r	  é  s    r	  c                   @   r   )ÚKeywordOnlyTestsz,
    Keyword only arguments (PEP 3102).
    c                 O   s   t t |¡||ƒS )a°  
        Test an invocation of L{passed} with the given function, arguments, and
        keyword arguments.

        @param func: A function whose argspec to pass to L{_passed}.
        @type func: A callable.

        @param args: The arguments which could be passed to L{func}.

        @param kw: The keyword arguments which could be passed to L{func}.

        @return: L{_passed}'s return value
        @rtype: L{dict}
        N)r   r  r
  r  r!   r!   r"   r  Ž  s   zKeywordOnlyTests.checkPassedc                 C   s®   ddœdd„}ddœdd„}|   |  |ddd	¡td
dd�¡ |   | j|ddd	dd�td
dd�¡ |   | j|dddddd	d�tddddd	d�¡ | jt| j|dddddd� dS )z`
        Keyword only arguments follow varargs.
        They are specified in PEP 3102.
        Tr*  c                 W   r¸   )zM
            b is a keyword-only argument, with a default value.
            Nr!   )râ   rá   r!   r!   r"   Úfunc1¥  rº   z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func1c                 W   r¸   )zd
            b, c, d, e  are keyword-only arguments.
            b has a default value.
            Nr!   )râ   rã   r$  r%  rá   r!   r!   r"   Úfunc2ª  rº   z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func2rF   rb   rÙ   r'  r  F)râ   rã   r$  r%  r6  r#  )râ   rã   r$  N)rB   r  ro   r8   r  )r    r9  r:  r!   r!   r"   Útest_passedKeywordOnlyŸ  s    ÿþ z'KeywordOnlyTests.test_passedKeywordOnlyN)r(   r)   r*   r+   r  r;  r!   r!   r!   r"   r8  ‰  s    r8  r'  )7r+   r  re   r.   r±   Úos.pathr   r   r   Ú	importlibr   ÚImportErrorÚincrementalr   Ztwisted.pythonr   Ztwisted.python.deprecater   r	   r
   rÊ   r   r   r   r   r   r   r   r   r   Ztwisted.python.filepathr   Ztwisted.python.runtimer   Ztwisted.python.testr   Z#twisted.python.test.modules_helpersr   Ztwisted.trial.unittestr   r   r,   rN   rj   r�   r¹   r»   r¼   rÚ   rÛ   rå   ræ   rþ   r	  r8  r!   r!   r!   r"   Ú<module>   sR   ÿ8Gbo g  *@ !