HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_deprecate.cpython-38.pyc
U


W[��@sNdZddlmZmZddlZddlZddlZddlZddlm	Z	ddlm
Z
mZzddlm
Z
Wnek
rxdZ
YnXddlmZddlmZdd	lmZdd
lmZmZmZmZmZmZmZmZmZddlmZm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,Gdd�de-�Z.Gdd�de,�Z/Gdd�de,�Z0Gdd�de*e,�Z1Gdd�de,�Z2dd�Z3dd�Z4Gd d!�d!e,�Z5ee"d"d#d$d%��Gd&d'�d'e-��Z6Gd(d)�d)e-�Z7Gd*d+�d+e,�Z8Gd,d-�d-e,�Z9Gd.d/�d/e,�Z:ej;d0k�r.e&e<��=��>d1�Z?iZ@e e?jAe@�e@d2ZBndd3l+mCZCGd4d2�d2eC�ZBdS)5zI
Tests for Twisted's deprecation framework, L{twisted.python.deprecate}.
�)�division�absolute_importN)�normcase)�simplefilter�catch_warnings)�invalidate_caches)�	deprecate)�_getDeprecationWarningString)�DEPRECATION_WARNING_FORMAT)	�getDeprecationWarningString�
deprecated�_appendToDocstring�_getDeprecationDocstring�_fullyQualifiedName�_mutuallyExclusiveArguments�deprecatedProperty�_passedArgSpec�_passedSignature)�_PY3�execfile)�Version)�platform)�FilePath)�deprecatedattributes)�TwistedModulesMixin)�SynchronousTestCasec@s eZdZdZdd�Zdd�ZdS)�_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    cCs
||_dS�N��value��selfr�r"�D/usr/lib/python3/dist-packages/twisted/python/test/test_deprecate.py�__init__3sz!_MockDeprecatedAttribute.__init__cCs|jS)z$
        Get a known value.
        r�r!r"r"r#�get7sz_MockDeprecatedAttribute.getN)�__name__�
__module__�__qualname__�__doc__r$r&r"r"r"r#r-src@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�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.
    cKs2t�d�}|��D]\}}t|||�qt�|�S)z�
        Create a temporary module proxy object.

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

        @rtype: L{twistd.python.deprecate._ModuleProxy}
        �foo)�types�
ModuleType�items�setattrrZ_ModuleProxy)r!Zattrs�mod�keyrr"r"r#�
_makeProxyEs
zModuleProxyTests._makeProxycCs.|jdd�}|�|jd�|�tt|d�dS)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.
        Zhello)�SOME_ATTRIBUTEZDOES_NOT_EXISTN)r3�assertIsr4�assertRaises�AttributeError�getattr�r!�proxyr"r"r#�test_getattrPassthroughSsz(ModuleProxyTests.test_getattrPassthroughcCs2|��}t�|d�}td�|d<|�|jd�dS)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)r3�object�__getattribute__r�assertEqualr,)r!r:r<r"r"r#�test_getattrIntercept^s�z&ModuleProxyTests.test_getattrInterceptcCs,|��}|�tt|d�|�tt|d�dS)z�
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        �_moduler<N)r3r6r7r8r9r"r"r#�test_privateAttributesks�z'ModuleProxyTests.test_privateAttributescCs4|��}d|_|�t�|d�d�|�|jd�dS)z�
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
        �rBN)r3rB�assertNotEqualr>r?r@r9r"r"r#�test_setattrvszModuleProxyTests.test_setattrcCs6|��}t�|d�}|�t|�dt|�j|f�dS)z�
        L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string
        containing the proxy type and a representation of the wrapped module
        object.
        rBz<%s module=%r>N)r3r>r?r@�repr�typer')r!r:Z
realModuler"r"r#�	test_repr�s�zModuleProxyTests.test_reprN)
r'r(r)r*r3r;rArCrFrIr"r"r"r#r+?s
r+c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�DeprecatedAttributeTestsz�
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    cCstj|_tj|_td|_dS)Nz.foo)r�version�messager'�_testModuleNamer%r"r"r#�setUp�szDeprecatedAttributeTests.setUpcCs"ttjd|tjtdtj�S)zJ
        Create the warning string used by deprecated attributes.
        �.z: )r	rr'rKr
rL)r!�attrr"r"r#�_getWarningString�s
�z*DeprecatedAttributeTests._getWarningStringcs�d}tt|d�t�t||j|j��|��j|��fdd�}|�|�|j	g�}|�
|ddt�|�|dd|�|��|�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.
        ZANOTHER_DEPRECATED_ATTRIBUTEr=cs���dSr)r&r"�rPr"r#�
addStackLevel�szNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevelr�categoryrLrDN)r0rrZ_DeprecatedAttributerKrLr@r'�
flushWarnings�test_deprecatedAttributeHelperr5�DeprecationWarningrQ�len)r!�namerS�
warningsShownr"rRr#rV�s(��
�z7DeprecatedAttributeTests.test_deprecatedAttributeHelpercCs�tj|�|jg�}|�t|�d�d}tt|�|�|jg�}|�t|�d�|�|ddt�|�|dd|�	|��dS)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.
        rZDEPRECATED_ATTRIBUTErDrTrLN)
rZANOTHER_ATTRIBUTErU�test_deprecatedAttributer@rXr8r5rWrQ)r!rZrYr"r"r#r[�s

�z1DeprecatedAttributeTests.test_deprecatedAttributecCs�t�d�tj|j<}|�tjj|j�t|dd�t|dd�t�	t
dddd�d	|jd�tj|j}|�||�t�	t
dddd�d	|jd�|�|tj|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,�firstrD�second��Twisted�rrLN)
r-r.�sys�modulesrM�
addCleanup�popr0rZdeprecatedModuleAttributerrEr5)r!r1r:r"r"r#�test_wrappedModule�s&��z+DeprecatedAttributeTests.test_wrappedModuleN)	r'r(r)r*rNrQrVr[rer"r"r"r#rJ�s
rJc@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�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')
cs^�fdd��t|���d��}|���||�}|�|j�d�gtj�|�tj	�
��|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.
        csli}|��D]Z\}}|�|�}t|t�r<|||<|�|�qt|t�r^|���||�||<qtd��q|S)Nz(only strings and dicts allowed as values)r/�child�
isinstance�bytes�
setContent�dictZcreateDirectory�
ValueError)ZpathobjZdirdictZpathdictr2rrg��
makeSomeFilesr"r#rns



zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFiles�utf-8)r�mktemp�encode�makedirsZreplaceSysPath�path�decoderaZreplaceSysModulesrb�copy)r!Ztree�base�resultr"rmr#�
pathEntryTree
s

z*ImportedModuleAttributeTests.pathEntryTreecCs(|�d|j�d�dd�i�}|ddS)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}.
        spackagero�)�__init__.py�	module.pyr{)rx�_packageInitrq)r!�pathsr"r"r#�simpleModuleEntry/s��z.ImportedModuleAttributeTests.simpleModuleEntrycCsnddlm}|�t|j�d��|�|�|jg�}|�t|�d�|�|ddd�|�|ddt	�dS)	zB
        Verification logic for L{test_deprecatedModule}.
        r��modulerorDrLz7package.module was deprecated in Package 1.2.3: messagerTN)
�packager�r@r�__file__rqrU�checkOneWarningrXrW)r!Z
modulePathr�Zemittedr"r"r#r�:s��z,ImportedModuleAttributeTests.checkOneWarningcCs|�|���dS)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_deprecatedModuleIsz2ImportedModuleAttributeTests.test_deprecatedModulecCs8|��}|�|�|�|�td�D]}|�|�q$dS)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.
        r^N)r~r��range)r!Zmp�xr"r"r#�"test_deprecatedModuleMultipleTimesRs


z?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesN)
r'r(r)r*r|rxr~r�r�r�r"r"r"r#rf�s	%	rfc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�WarnAboutFunctionTestsz�
    Tests for L{twisted.python.deprecate.warnAboutFunction} which allows the
    callers of a function to issue a C{DeprecationWarning} about that function.
    cs�t|���d���d�|_|j��|j�d��d�|j�d��d�|j��j�	d�}t
j�d|�|�t
jj
|�t
j���|��fdd	��t��r�tr�|��d
S)zY
        Create a file that will have known line numbers when emitting warnings.
        ro�twisted_private_helperrzryr{s
"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")
rcstj��tj���fSr)rarb�clear�updater"�rbr"r#�<lambda>�ryz.WarnAboutFunctionTests.setUp.<locals>.<lambda>N)rrprqrgr�rrrj�parentrsrtra�insertrc�removerbrurZ	isWindowsrrU)r!ZpackagePathr"r�r#rNms�


�zWarnAboutFunctionTests.setUpcCsndd�}t�|d�|��}t}|���d�r:|dd�}|�t|dd�t|��|�|dd	d�dS)
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.
        cSsdSrr"r"r"r"r#�aFunc�sz2WarnAboutFunctionTests.test_warning.<locals>.aFunczA Warning Messagez.pycN���r�filenamerL)	rZwarnAboutFunctionrUr��lower�endswith�assertSamePathrr@)r!r�rZr�r"r"r#�test_warning�s�z#WarnAboutFunctionTests.test_warningcCs�ddlm}|��|��}|�t|dd�d��|j�d��	d��|�
|ddd�|�
|dd	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.
        rrr�ror�r{�lineno�	rL�A Warning StringrDN)�twisted_private_helperr��callTestFunctionrUr�rrqr��siblingrgr@rX�r!r�rZr"r"r#�test_warningLineNumber�s�z-WarnAboutFunctionTests.test_warningLineNumbercCs(|�t|j�t|j�kd||f�dS)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%r != %rN)�
assertTruerrs)r!r\r]r"r"r#r��s

�z%WarnAboutFunctionTests.assertSamePathcCs�ddlm}tjd=tj|j=|j�|j�d��tr<t�ddl	m}|�
tjjd�|�
tjj|j�|��|�
|jg�}t|dd�d��}|j�d��d�}|�||�|�|dd	d
�|�|ddd�|�t|�d
�dS)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.
        rrr�stwisted_renamed_helper�twisted_renamed_helperr�ror{r�r�rLr�rDN)r�r�rarbr'r�ZmoveTor�rr�rcrdr�rUZtestFunctionrrqrgr�r@rX)r!r�rZZ
warnedPathZexpectedPathr"r"r#�test_renamedFile�s*
��z'WarnAboutFunctionTests.test_renamedFilecCsJtjdd�=tjddd�ddlm}|��|��}|�t|�d�dS)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�rr)	�warnings�filters�filterwarningsr�r�r�rUr@rXr�r"r"r#�test_filteredWarning�s	�z+WarnAboutFunctionTests.test_filteredWarningcCs�tjdd�=tjddd�ddlm}|��|��|��}|�t|�d�|dd}|dd	}|dd
}|dd}t�	||||�}|�
|�d�d
|f�dS)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�rrrDrLrTr�r�z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: %r)r�r�r�r�r�r�rUr@rX�
formatwarningr�r�)r!r�rZrLrTr�r��msgr"r"r#�test_filteredOnceWarnings&	��z/WarnAboutFunctionTests.test_filteredOnceWarningN)r'r(r)r*rNr�r�r�r�r�r�r"r"r"r#r�hs'$r�cCsdS)zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr"r"r"r"r#�
dummyCallable sr�cCsdS)z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr"r"r"r"r#�dummyReplacementMethod)sr�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�DeprecationWarningsTestscCs,tdddd�}|�t|j|�dtf�dS)z�
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        r_r`rz\%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)rr@r� test_getDeprecationWarningStringr'�r!rKr"r"r#r�3s���z9DeprecationWarningsTests.test_getDeprecationWarningStringcCs6tdddd�}td}|�t|j||�dtf�dS)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.
        r_r`rz: This is a messagezo%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)rr
r@rr�r')r!rK�formatr"r"r#�*test_getDeprecationWarningStringWithFormat@s���zCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormatc	s�tdddd�}t|�t���fdd�}tdd��`}td�|�|�|djt�|�t|dj	�t
t|��|�|dj�d	�t
�d	��W5QRXd
S)zK
        Decorating a callable with L{deprecated} emits a warning.
        r_r`rcs
��dSrr"r"��dummyr"r#rSUszJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelT)�record�always�coN)rrr�rrr@rTrW�strrLrr��rstripr�)r!rKrSZcaughtr"r�r#�test_deprecateEmitsWarningOsz3DeprecationWarningsTests.test_deprecateEmitsWarningcCsBtdddd�}t|�t�}|�tj|j�|�tt�t|��dS)zK
        The decorated function has the same name as the original.
        r_r`rN)rrr�r@r'�fullyQualifiedName�r!rKr�r"r"r#�test_deprecatedPreservesName`s
�z5DeprecationWarningsTests.test_deprecatedPreservesNamecCs$tdddd�}|�dt|d��dS)zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        r_r`rzDeprecated in Twisted 8.0.0.�N)rr@rr�r"r"r#�test_getDeprecationDocstringks
�z5DeprecationWarningsTests.test_getDeprecationDocstringcCsFdd�}tdddd�}t|�|�}t|t|d��|�|j|j�dS)zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        cSsdS)zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr"r"r"r"r#�localDummyCallable|szTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallabler_r`rr�N)rrr
rr@r*)r!r�rKr�r"r"r#�test_deprecatedUpdatesDocstringvs�z8DeprecationWarningsTests.test_deprecatedUpdatesDocstringcCs,tdddd�}t|�t�}|�||j�dS)zt
        Deprecating a function adds version information to the decorated
        version of that function.
        r_r`rN)rrr�r@�deprecatedVersionr�r"r"r#�test_versionMetadata�sz-DeprecationWarningsTests.test_versionMetadatacCs:tdddd�}t|j|dd�}|�|dt|j�f�dS)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.
        r_r`r�something.foobar�ZreplacementzG%s was deprecated in Twisted 8.0.0; please use something.foobar insteadN)rrr�r@r��r!rKZ
warningStringr"r"r#�+test_getDeprecationWarningStringReplacement�s����zDDeprecationWarningsTests.test_getDeprecationWarningStringReplacementcCs<tdddd�}t|j|td�}|�|dt|j�tf�dS)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.
        r_r`rr�zP%s was deprecated in Twisted 8.0.0; please use %s.dummyReplacementMethod insteadN)rrr�r�r@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�2s

r�r_rDr^�c@seZdZdZdS)�DeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r'r(r)r*r"r"r"r#r��sr�c@s<eZdZdZdZeedddd��dd��Zejd	d��ZdS)
�ClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    Nr_rDr^r�cCs|jS)zC
        Getter docstring.

        @return: The property.
        ��_someProtectedValuer%r"r"r#�someProperty�sz(ClassWithDeprecatedProperty.somePropertycCs
||_dS)z#
        Setter docstring.
        Nr�r r"r"r#r��s)	r'r(r)r*r�rrr��setterr"r"r"r#r��s
	r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�DeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    cCs |�|dd�|j��D��dS)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}
        cSsg|]}|��r|���qSr")�strip)�.0r�r"r"r#�
<listcomp>�sz<DeprecatedDecoratorTests.assertDocstring.<locals>.<listcomp>N)r@r*�
splitlines)r!�targetZexpectedr"r"r#�assertDocstring�s�z(DeprecatedDecoratorTests.assertDocstringcCs�t�}|j|�tjdddg�tdddd�tj_d}|�|jg�}|�dt|��|�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.
        zGetter docstring.z@return: The property.�Deprecated in Twisted 1.2.3.r_rDr^r��ktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3rrTrLN)
r�r�r�rr�rU�test_propertyGetterr@rXrW)r!�objrLr�r"r"r#r��s*����z,DeprecatedDecoratorTests.test_propertyGettercCsnt�}t�}||_|�||j�d}|�|jg�}|�dt|��|�t	|dd�|�||dd�dS)z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        r�rDrrTrLN)
r>r�r�r5r�rU�test_propertySetterr@rXrW)r!ZnewValuer�rLr�r"r"r#r�s�z,DeprecatedDecoratorTests.test_propertySettercCstt�|�tddg�tdddd�t_d}|�|jg�}|�dt|��|�t|dd	�|�||dd
�dS)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�r_rDr^r�zRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3rrTrLN)	r�r�rr�rU�
test_classr@rXrW)r!rLr�r"r"r#r�*s���z#DeprecatedDecoratorTests.test_classcCs.tdddd�}t|d�t�}|�|jd�dS)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.
        r_r`rr�z�
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use something.foobar instead.
    N)rrr�r@r*r�r"r"r#�test_deprecatedReplacementEs
�z3DeprecatedDecoratorTests.test_deprecatedReplacementcCs:tdddd�}t|td�}|t�}|�|jdtf�dS)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.
        r_r`rr�z�
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use %s.dummyReplacementMethod instead.
    N)rrr�r�r@r*r')r!rKZ	decoratorr�r"r"r#�&test_deprecatedReplacementWithCallableXs��z?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallableN)
r'r(r)r*r�r�r�r�r�r�r"r"r"r#r��s r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�AppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    cCs$dd�}t|d�|�d|j�dS)zP
        Appending to an empty docstring simply replaces the docstring.
        cSsdSrr"r"r"r"r#�noDocstringxszGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstring�Appended text.N�r
r@r*)r!r�r"r"r#�test_appendToEmptyDocstringss
z2AppendToDocstringTests.test_appendToEmptyDocstringcCs@dd�}t|d�|�dddg|j���|�|j�d��dS)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.
        cSsdS)�;This doesn't comply with standards, but is here for a test.Nr"r"r"r"r#�singleLineDocstring�szTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstringr�r�r��
N)r
r@r*r�r�r�)r!r�r"r"r#� test_appendToSingleLineDocstrings
��z7AppendToDocstringTests.test_appendToSingleLineDocstringcCs.dd�}dd�}t|d�|�|j|j�dS)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.
        cSsdS)z9
            This is a multi-line docstring.
            Nr"r"r"r"r#�multiLineDocstring�szRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstringcSsdS)zU
            This is a multi-line docstring.

            Appended text.
            Nr"r"r"r"r#�expectedDocstring�szQAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.expectedDocstringr�Nr�)r!r�r�r"r"r#�test_appendToMultilineDocstring�s	
�z6AppendToDocstringTests.test_appendToMultilineDocstringN)r'r(r)r*r�r�r�r"r"r"r#r�lsr�c@szeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zeedd�svde_dS)�MutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    cOs4ttdd�rtt�|�||�Stt�|�||�SdS)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)r8�inspectrr�rZ
getargspec)r!�func�args�kwr"r"r#�checkPassed�sz(MutualArgumentExclusionTests.checkPassedcCs*dd�}|�|�|dd�tddd��dS)z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        cSsdSrr"��a�br"r"r#r��szGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.funcrDr^r�N�r@r�rk�r!r�r"r"r#�test_passed_simplePositional�sz9MutualArgumentExclusionTests.test_passed_simplePositionalcCs"dd�}|�t|j|ddd�dS)z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        cSsdSrr"r�r"r"r#r��szBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.funcrDr^r�N�r6�	TypeErrorr�r�r"r"r#�test_passed_tooManyArgs�sz4MutualArgumentExclusionTests.test_passed_tooManyArgscCs"dd�}|jt|j|ddd�dS)zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        cSsdSrr"�r�r"r"r#r��szHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.funcrDr^r�Nr�r�r"r"r#�test_passed_doublePassKeyword�sz:MutualArgumentExclusionTests.test_passed_doublePassKeywordcCs"dd�}|jt|j|ddd�dS)z�
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        cSsdSrr"r�r"r"r#r��szIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.funcrDr^)�zNr�r�r"r"r#�test_passed_unspecifiedKeyword�sz;MutualArgumentExclusionTests.test_passed_unspecifiedKeywordcCs,dd�}|�|�|ddd�tddd��dS)	z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        cWsdSrr"r�r"r"r#r��sz;MutualArgumentExclusionTests.test_passed_star.<locals>.funcrDr^r�)r^r�r�Nr�r�r"r"r#�test_passed_star�s
�z-MutualArgumentExclusionTests.test_passed_starc
Cs:dd�}|�|j|ddddd�tdtdddd�d��d	S)
zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c[sdSrr"r�r"r"r#r�sz?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcrDr^r��)r��yr�r�Nr�r�r"r"r#�test_passed_starStars�z1MutualArgumentExclusionTests.test_passed_starStarcCs2d
dd�}|�|j|dddd�tdddd��d	S)zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rDr^r�cSsdSrr")r�r��c�d�er"r"r#r�szFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.func�)r)r�r�rN)rDr^r�r�r�r"r"r#�test_passed_noDefaultValuess
�z8MutualArgumentExclusionTests.test_passed_noDefaultValuescCsTtdg�ddd��}|�|dd�d�|�|ddd	�d
�|�|ddd	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�rcSs||||Srr")r�rr�r�r"r"r#r�szMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.funcrDr^�
r�)r��
N)r�r)rr@r�r"r"r#�"test_mutualExclusionPrimeDirectives
z?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectivecCs.tddgg�d	dd��}|jt|ddd�dS)
z�
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        r�r�r�rcSs||Srr"r�r"r"r#r�*szPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funcr�N)r�r)rr6r�r�r"r"r#�%test_mutualExclusionExcludesByKeyword%szBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordcCsnGdd�d�}Gdd�d�}dd�}|dd�t�|�j}|��}|d	d	�|d
<||�}|�tt|di�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@seZdZdd�ZdS)zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturecSs
||_dSr)�
parameters)r!rr"r"r#r$8szVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__N�r'r(r)r$r"r"r"r#�
FakeSignature7src@seZdZdd�ZdS)zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParametercSs||_||_dSr)rY�kind)r!rYrr"r"r#r$<szVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__Nrr"r"r"r#�
FakeParameter;srcSsdSrr"r�r"r"r#r�@szDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.funcrDr^Zfaker)rDr^N)r�r�rrur6r�r)r!rrr�rZdummyParametersZfakeSigr"r"r#�test_invalidParameterType1s
z6MutualArgumentExclusionTests.test_invalidParameterTyper�Nz!inspect.signature() not available)r'r(r)r*r�r�r�r�r�rrrrr
rr8r��skipr"r"r"r#r��s



r�)r�z_deprecatetests.py.3only�KeywordOnlyTests)�TestCasec@seZdZdZdZdd�ZdS)rz�
        A dummy class to show that this test file was discovered but the tests
        are unable to be ran in this version of Python.
        zAkeyword only arguments (PEP 3102) are only in Python 3 and highercCsdS)zq
            A skipped test to show that this was not ran because the Python is
            too old.
            Nr"r%r"r"r#�test_notAvailable`sz"KeywordOnlyTests.test_notAvailableN)r'r(r)r*rrr"r"r"r#rWs�)Dr*Z
__future__rrrar-r�r��os.pathrrr�	importlibr�ImportErrorZtwisted.pythonrZtwisted.python.deprecater	r
rrr
rrr�rrrrZtwisted.python.compatrrZincrementalrZtwisted.python.runtimerZtwisted.python.filepathrZtwisted.python.testrZ#twisted.python.test.modules_helpersrZtwisted.trial.unittestrr>rr+rJrfr�r�r�r�r�r�r�r�r��version_infor�r�rg�_pathZ_grsrrr"r"r"r#�<module>sX 
,	Omm9		E