
    Vh                     d   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 	 ddl	m
Z
 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      Z( G d de'      Z) G d de'      Z* G d de%e'      Z+ G d de'      Z,d Z-d Z. G d de'      Z/ e edddd             G d  d!             Z0 G d" d#      Z1 e edd$dd      d%      d/d&       Z2 G d' d(e'      Z3 G d) d*e'      Z4 G d+ d,e'      Z5 G d- d.e'      Z6y# e$ r dZ
Y w xY w)0zI
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 Zd Zy)_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    c                     || _         y Nvalueselfr   s     R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_deprecate.py__init__z!_MockDeprecatedAttribute.__init__8   s	    
    c                     | j                   S )z$
        Get a known value.
        r   r!   s    r"   getz_MockDeprecatedAttribute.get;   s     zzr$   N)__name__
__module____qualname____doc__r#   r'    r$   r"   r   r   1   s    r$   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                     t        j                  d      }|j                         D ]  \  }}t        |||        t	        j
                  |      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setattrr   _ModuleProxy)r!   attrsmodkeyr   s        r"   
_makeProxyzModuleProxyTests._makeProxyI   sJ     u%++- 	%JCCe$	%%%c**r$   c                     | j                  d      }| j                  |j                  d       | j                  t        t
        |d       y)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.
        hello)SOME_ATTRIBUTEDOES_NOT_EXISTN)r9   assertIsr<   assertRaisesAttributeErrorgetattrr!   proxys     r"   test_getattrPassthroughz(ModuleProxyTests.test_getattrPassthroughV   s=     w7e**G4.'5:JKr$   c                     | j                         }t        j                  |d      }t        d      |d<   | j	                  |j
                  d       y)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*   r0   N)r9   object__getattribute__r   assertEqualr0   )r!   rC   rF   s      r"   test_getattrInterceptz&ModuleProxyTests.test_getattrIntercept`   sH     ! & 7 7?V W'?'Ce$B'r$   c                     | j                         }| j                  t        t        |d       | j                  t        t        |d       y)z
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        _modulerF   N)r9   r?   r@   rA   rB   s     r"   test_privateAttributesz'ModuleProxyTests.test_privateAttributesk   s9    
 !.'5)D.'5:QRr$   c                     | j                         }d|_        | j                  t        j	                  |d      d       | j                  |j                  d       y)z
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
           rM   N)r9   rM   assertNotEqualrH   rI   rJ   rB   s     r"   test_setattrzModuleProxyTests.test_setattrt   sH    
 !F33E9EqI*r$   c                     | j                         }t        j                  |d      }| j                  t	        |      dt        |      j                   d|d       y)z
        L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string
        containing the proxy type and a representation of the wrapped module
        object.
        rM   <z module=>N)r9   rH   rI   rJ   reprtyper(   )r!   rC   
realModules      r"   	test_reprzModuleProxyTests.test_repr~   sQ     !,,UI>
e$u+*>*>)?x
~UV&WXr$   N)
r(   r)   r*   r+   r9   rD   rK   rN   rR   rY   r,   r$   r"   r.   r.   B   s(    +L	(S+Yr$   r.   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)DeprecatedAttributeTestsz
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    c                 t    t         j                  | _        t         j                  | _        t        dz   | _        y )Nz.foo)r   versionmessager(   _testModuleNamer&   s    r"   setUpzDeprecatedAttributeTests.setUp   s)    +33+33'&0r$   c                     t        t        j                  dz   |z   t        j                  t        dz   t        j
                  z         S )zJ
        Create the warning string used by deprecated attributes.
        .z: )r   r   r(   r]   r	   r^   )r!   attrs     r"   _getWarningStringz*DeprecatedAttributeTests._getWarningString   sA     , ))C/$6 ((&-0D0L0LL
 	
r$   c                    d}t        t        |d       t        j                  t        || j                  | j
                        | j                  j                  |       fd} |        | j                  | j                  g      }| j                  |d   d   t               | j                  |d   d   | j                  |             | j                  t        |      d       y)	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.
        ANOTHER_DEPRECATED_ATTRIBUTErG   c                  &     j                          y r   )r'   )rc   s   r"   addStackLevelzNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevel   s    HHJr$   r   categoryr^   rP   N)r4   r   r   _DeprecatedAttributer]   r^   rJ   r(   flushWarningstest_deprecatedAttributeHelperr>   DeprecationWarningrd   len)r!   namerh   warningsShownrc   s       @r"   rl   z7DeprecatedAttributeTests.test_deprecatedAttributeHelper   s     .$dB/-- $dll
 	-	 	**D,O,O+PQmA&z24FGq))4d6L6LT6RS]+Q/r$   c                    t         j                   | j                  | j                  g      }| j	                  t        |      d       d}t        t         |       | j                  | j                  g      }| j	                  t        |      d       | j                  |d   d   t               | j	                  |d   d   | j                  |             y)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   DEPRECATED_ATTRIBUTErP   ri   r^   N)
r   ANOTHER_ATTRIBUTErk   test_deprecatedAttributerJ   rn   rA   r>   rm   rd   )r!   rp   ro   s      r"   rt   z1DeprecatedAttributeTests.test_deprecatedAttribute   s     	..**D,I,I+JK]+Q/% 	$d+**D,I,I+JK]+Q/mA&z24FGq))4d6L6LT6RSr$   c                 t   t        j                  d      xt        j                  | j                  <   }| j                  t        j                  j                  | j                         t        |dd       t        |dd       t        j                  t        dddd      d	| j                  d       t        j                  | j                     }| j                  ||       t        j                  t        dddd      d	| j                  d       | j                  |t        j                  | j                            y
)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.
        r0   firstrP   second   Twisted   r   r^   N)r1   r2   sysmodulesr_   
addCleanuppopr4   r   deprecatedModuleAttributer   rQ   r>   )r!   r7   rC   s      r"   test_wrappedModulez+DeprecatedAttributeTests.test_wrappedModule   s     382B2B52IID(()C)=)=>Wa Xq!++Iq!Q'D4H4H'	
 D001E3'++Iq!Q'D4H4H(	
 	eS[[)=)=>?r$   N)	r(   r)   r*   r+   r`   rd   rl   rt   r   r,   r$   r"   r[   r[      s"    1

04T.@r$   r[   c                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)	ImportedModuleAttributeTestsza
    Tests for L{deprecatedModuleAttribute} which involve loading a module via
    'import'.
    zfrom twisted.python.deprecate import deprecatedModuleAttribute
from incremental import Version

deprecatedModuleAttribute(
    Version('Package', 1, 2, 3), 'message', __name__, 'module')
c                 f   fdt        | j                         j                  d            }|j                           ||      }| j	                  |j
                  j                  d      gt        j
                  z          | j                  t        j                  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                    i }|j                         D ]t  \  }}| j                  |      }t        |t              r|||<   |j	                  |       >t        |t
              r|j                           ||      ||<   kt        d       |S )Nz(only strings and dicts allowed as values)r3   child
isinstancebytes
setContentdictcreateDirectory
ValueError)pathobjdirdictpathdictr8   r   r   makeSomeFiless         r"   r   zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFiles  s    H%mmo 	Q
Uc*eU+$)HSM$$U+t,))+$1%$?HSM$%OPP	Q Or$   utf-8)r   mktempencodemakedirsreplaceSysPathpathdecoder{   replaceSysModulesr|   copy)r!   treebaseresultr   s       @r"   pathEntryTreez*ImportedModuleAttributeTests.pathEntryTree   s    	 ,,W56tT*TYY--g67#((BCs{{//12r$   c                 p    | j                  d| j                  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   packager   r$   )s   __init__.py	   module.pyr   )r   _packageInitr   )r!   pathss     r"   simpleModuleEntryz.ImportedModuleAttributeTests.simpleModuleEntry  sJ    
 ""$($5$5$<$<W$E"%
 Z ..r$   c                 N   ddl m} | j                  t        |j                  j                  d            |       | j                  | j                  g      }| j                  t        |      d       | j                  |d   d   d       | j                  |d   d   t               y)	zB
        Verification logic for L{test_deprecatedModule}.
        r   moduler   rP   r^   z7package.module was deprecated in Package 1.2.3: messageri   N)
packager   rJ   r   __file__r   rk   checkOneWarningrn   rm   )r!   
modulePathr   emitteds       r"   r   z,ImportedModuleAttributeTests.checkOneWarning.  s     	#&//"8"8"ABJO$$d&:&:%;<Wq)AJy!H	
 	J/1CDr$   c                 B    | j                  | j                                y)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&   s    r"   test_deprecatedModulez2ImportedModuleAttributeTests.test_deprecatedModule=  s     	T3356r$   c                     | j                         }| j                  |       | j                  |       t        d      D ]  }| j                  |        y)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.
        rx   N)r   r   range)r!   mpxs      r"   "test_deprecatedModuleMultipleTimesz?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesE  sS     ##%R  	R  q 	%A  $	%r$   N)
r(   r)   r*   r+   r   r   r   r   r   r   r,   r$   r"   r   r      s)    
L$L/E7%r$   r   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)WarnAboutFunctionTestsz
    Tests for L{twisted.python.deprecate.warnAboutFunction} which allows the
    callers of a function to issue a C{DeprecationWarning} about that function.
    c                    t        | j                               j                  d      | _        | j                  j	                          | j                  j                  d      j                  d       | j                  j                  d      j                  d       | j                  j                  d      j                  d       | j                  j                         j                  }t        j                  j                  d|       | j                  t        j                  j                  |       t        j                  j                         | j                  fd	       t        j                         r| j!                          y
y
)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                  ~    t         j                  j                         t         j                  j                         fS r   )r{   r|   clearupdate)r|   s   r"   <lambda>z.WarnAboutFunctionTests.setUp.<locals>.<lambda>  s(    !2!2!4ckk6H6H6Q R r$   N)r   r   r   r   r   r   parentr   r{   insertr}   remover|   r   r   	isWindowsrk   )r!   packagePathr|   s     @r"   r`   zWarnAboutFunctionTests.setUp`  s     .445MN=)44S9;'22	
" 	;'22	
0 ll))+00;'5++""$RS
    r$   c                 .   d }t        j                  |d       | j                         }t        }|j	                         j                  d      r|dd }| j                  t        |d   d         t        |             | j                  |d   d   d       y)	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                       y r   r,   r,   r$   r"   aFuncz2WarnAboutFunctionTests.test_warning.<locals>.aFunc      r$   zA Warning Messagez.pycNr   filenamer^   )	r   warnAboutFunctionrk   r   lowerendswithassertSamePathr   rJ   )r!   r   rp   r   s       r"   test_warningz#WarnAboutFunctionTests.test_warning  s    	 	##E+>?**,>>$$V,}HH]1%5j%ABHXDVWq))46IJr$   c                    ddl m} |j                          | j                         }| j	                  t        |d   d   j                  d            | j                  j                  d      j                  d             | j                  |d   d   d       | j                  |d   d	   d
       | j                  t        |      d       y)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   r      twisted_private_helperr   lineno	   r^   A Warning StringrP   N)r   r   callTestFunctionrk   r   r   r   r   siblingr   rJ   rn   r!   r   rp   s      r"   test_warningLineNumberz-WarnAboutFunctionTests.test_warningLineNumber  s    
 	2!**,]1%j188ABLL  !:;AA,O	
 	q)(3Q7q))46HI]+Q/r$   c                    ddl m} |j                          | j                         }| j	                  t        |d   d   j                  d            | j                  j                  d      j                  d             | j                  |d   d   d       | j                  |d   d	   d
       | j                  t        |      d       y)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   r   r   s	   pep626.pyr      r^   r   rP   N)r   r   r   rk   r   r   r   r   r   r   rJ   rn   )r!   r   rp   s      r"   'test_warningLineNumberDisFindlinestartsz>WarnAboutFunctionTests.test_warningLineNumberDisFindlinestarts  s     	2!**,]1%j188ABLL  !:;AA,O	
 	q)(3R8q))46HI]+Q/r$   c                     | j                  t        |j                        t        |j                        k(  |d|       y)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   r   )r!   rv   rw   s      r"   r   z%WarnAboutFunctionTests.assertSamePath  s8     	UZZ HV[[$99itF:&	
r$   c                 ^   ddl m} t        j                  d= t        j                  |j                  = | j
                  j                  | j
                  j                  d             t        r
t                ddl	m} | j                  t        j                  j                  d       | j                  t        j                  j                  |j                         |j                          | j                  |j                  g      }t        |d   d   j!                  d            }| j
                  j                  d      j#                  d      }| j%                  ||       | j'                  |d   d	   d
       | j'                  |d   d   d       | j'                  t)        |      d       y)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   r   r   r   r   r^   r   rP   N)r   r   r{   r|   r(   r   moveTor   r   r   r}   r~   r   rk   testFunctionr   r   r   r   rJ   rn   )r!   r   rp   
warnedPathexpectedPaths        r"   test_renamedFilez'WarnAboutFunctionTests.test_renamedFile  sN    	2 KK01KK( 	DLL001JKL  	2)AB9!**F,?,?+@AmA.z:AA'JK
||++,EFLL
 	J5q)(3Q7q))46HI]+Q/r$   c                     t         j                  dd= t        j                  dd       ddlm} |j                          | j                         }| j                  t        |      d       y)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   rk   rJ   rn   r   s      r"   test_filteredWarningz+WarnAboutFunctionTests.test_filteredWarning  sU     Qx8PQ1!**,]+Q/r$   c                    t         j                  dd= t        j                  dd       ddlm} |j                          |j                          | j                         }| j                  t        |      d       |d   d   }|d   d	   }|d   d
   }|d   d   }t        j                  ||||      }| j                  |j                  d      d|       y)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   rP   r^   ri   r   r   z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: )r   r   r   r   r   r   rk   rJ   rn   formatwarningr   r   )r!   r   rp   r^   ri   r   r   msgs           r"   test_filteredOnceWarningz/WarnAboutFunctionTests.test_filteredOnceWarning  s     Qx8PQ1!!**,]+Q/"9- #J/ #J/q!(+$$Wh&ILLT *#1		
r$   N)r(   r)   r*   r+   r`   r   r   r   r   r   r   r   r,   r$   r"   r   r   Z  s2    
;!zK$0&0(
$0L0(
r$   r   c                       y)zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr,   r,   r$   r"   dummyCallabler   @      r$   c                       y)z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr,   r,   r$   r"   dummyReplacementMethodr   H  r   r$   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)DeprecationWarningsTestsc                 z    t        dddd      }| j                  t        | j                  |      t        d       y)z
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        ry   rz   r   zZ.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)r   rJ   r    test_getDeprecationWarningStringr(   r!   r]   s     r"   r   z9DeprecationWarningsTests.test_getDeprecationWarningStringQ  s:    
 )Q1-'(M(MwW19<	
r$   c                     t        dddd      }t        dz   }| j                  t        | j                  ||      t
        d       y)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.
        ry   rz   r   z: This is a messagezm.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)r   r	   rJ   r   r   r(   )r!   r]   formats      r"   *test_getDeprecationWarningStringWithFormatzCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormat]  sO     )Q1-+.CC'55w AIK		
r$   c                    t        dddd      } t        |      t              fd}t        d      5 }t	        d        |        | j                  |d   j                  t               | j                  t        |d   j                        t        t        |             | j                  |d   j                  j                  d      t        j                  d             d	d	d	       y	# 1 sw Y   y	xY w)
zK
        Decorating a callable with L{deprecated} emits a warning.
        ry   rz   r   c                                y r   r,   )dummys   r"   rh   zJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelt  s    Gr$   TrecordalwayscoN)r   r   r   r   r   rJ   ri   rm   strr^   r   r   rstripr   )r!   r]   rh   caughtr   s       @r"   test_deprecateEmitsWarningz3DeprecationWarningsTests.test_deprecateEmitsWarningm  s     )Q1-#
7#M2	 4( 		UF"OVAY//1CDF1I%%&+M7C
 VAY//66t<hood>ST		U 		U 		Us   B-C,,C5c                     t        dddd      } t        |      t              }| j                  t        j                  |j                         | j                  t        t              t        |             y)zK
        The decorated function has the same name as the original.
        ry   rz   r   N)r   r   r   rJ   r(   fullyQualifiedNamer!   r]   r   s      r"   test_deprecatedPreservesNamez5DeprecationWarningsTests.test_deprecatedPreservesName  s[     )Q1-#
7#M2//@+M:<Nu<UVr$   c                 X    t        dddd      }| j                  dt        |d             y)zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        ry   rz   r   zDeprecated in Twisted 8.0.0. N)r   rJ   r   r   s     r"   test_getDeprecationDocstringz5DeprecationWarningsTests.test_getDeprecationDocstring  s/    
 )Q1-*,DWb,Q	
r$   c                     d }t        dddd      } t        |      |      }t        |t        |d             | j	                  |j
                  |j
                         y)zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        c                       y)zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr,   r,   r$   r"   localDummyCallablezTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallable  r   r$   ry   rz   r   r  N)r   r   r
   r   rJ   r+   )r!   r  r]   r   s       r"   test_deprecatedUpdatesDocstringz8DeprecationWarningsTests.test_deprecatedUpdatesDocstring  sZ    	 )Q1-#
7#$67-/GQS/TU+33U]]Cr$   c                     t        dddd      } t        |      t              }| j                  ||j                         y)zt
        Deprecating a function adds version information to the decorated
        version of that function.
        ry   rz   r   N)r   r   r   rJ   deprecatedVersionr  s      r"   test_versionMetadataz-DeprecationWarningsTests.test_versionMetadata  s;    
 )Q1-#
7#M2%"9"9:r$   c                     t        dddd      }t        | j                  |d      }| j                  |t	        | j                        d       y)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.
        ry   rz   r   something.foobarreplacementzE was deprecated in Twisted 8.0.0; please use something.foobar insteadN)r   r   r   rJ   r  r!   r]   warningStrings      r"   +test_getDeprecationWarningStringReplacementzDDeprecationWarningsTests.test_getDeprecationWarningStringReplacement  sT     )Q1-311*

 	+D,Q,QRU	
r$   c                     t        dddd      }t        | j                  |t              }| j	                  |t        | j                        dt        d       y)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.
        ry   rz   r   r  z- was deprecated in Twisted 8.0.0; please use z.dummyReplacementMethod insteadN)r   r   r   r   rJ   r  r(   r  s      r"   7test_getDeprecationWarningStringReplacementWithCallablezPDeprecationWarningsTests.test_getDeprecationWarningStringReplacementWithCallable  sX     )Q1-311.

 	 "$"G"GH(T	
r$   N)r(   r)   r*   r   r   r  r  r	  r  r  r  r  r,   r$   r"   r   r   P  s2    


 U*W
D(;
&
r$   r   ry   rP   rx      c                       e Zd ZdZy)DeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r(   r)   r*   r+   r,   r$   r"   r  r    s    r$   r  c                   f    e Zd ZdZdZ e edddd            d        Zej                  d        Zy)	ClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    Nry   rP   rx   r  c                     | j                   S )zC
        Getter docstring.

        @return: The property.
        _someProtectedValuer&   s    r"   somePropertyz(ClassWithDeprecatedProperty.someProperty  s     '''r$   c                     || _         y)z#
        Setter docstring.
        Nr   r    s     r"   r"  z(ClassWithDeprecatedProperty.someProperty  s    
 $) r$   )	r(   r)   r*   r+   r!  r   r   r"  setterr,   r$   r"   r  r    sK     	1a34( 5( ) )r$   r     r0   c                      y)z7
    Function with a deprecated keyword parameter.
    Nr,   )abcr0   bars        r"   functionWithDeprecatedParameterr+    r   r$   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
DeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    c                     | j                  ||j                  j                         D cg c]#  }|j                         s|j                         % c}       yc c}w )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}
        N)rJ   r+   
splitlinesstrip)r!   targetexpectedr   s       r"   assertDocstringz(DeprecatedDecoratorTests.assertDocstring  s@     	&..*C*C*ESQqwwyS	
Ss
   A
A
c                    t               }|j                   | j                  t         j                  g d       t        dddd      t         j                  _        d}| j                  | j                  g      }| j                  dt        |             | j                  t        |d   d          | j                  ||d   d	          y
)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.ry   rP   rx   r  ktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3r   ri   r^   N)
r  r"  r3  r   r  rk   test_propertyGetterrJ   rn   rm   )r!   objr^   r   s       r"   r7  z,DeprecatedDecoratorTests.test_propertyGetter  s     *+'44	
 FMq!QF
#00B
; 	 %%t'?'?&@ACM*+Xa[-DE(1+i"89r$   c                 L   t               }t               }||_        | j                  ||j                         d}| j                  | j                  g      }| j                  dt        |             | j                  t        |d   d          | j                  ||d   d          y)z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        r6  rP   r   ri   r^   N)
rH   r  r"  r>   r!  rk   test_propertySetterrJ   rn   rm   )r!   newValuer8  r^   r   s        r"   r:  z,DeprecatedDecoratorTests.test_propertySetter4  s    
 8)+#h 7 78; 	 %%t'?'?&@ACM*+Xa[-DE(1+i"89r$   c                 P   t                | j                  t         ddg       t        dddd      t         _        d}| j	                  | j
                  g      }| j                  dt        |             | j                  t        |d   d	          | j                  ||d   d
          y)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.r5  ry   rP   rx   r  zRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3r   ri   r^   N)	r  r3  r   r  rk   
test_classrJ   rn   rm   )r!   r^   r   s      r"   r=  z#DeprecatedDecoratorTests.test_classH  s     	V.	
 -4Iq!Q,G). 	 %%t&78CM*+Xa[-DE(1+i"89r$   c                     t        dddd      } t        |d      t              }| j                  |j                  d       y)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.
        ry   rz   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   rJ   r+   r  s      r"   test_deprecatedReplacementz3DeprecatedDecoratorTests.test_deprecatedReplacementc  sB     )Q1-7
7$67FMM	
r$   c                     t        dddd      }t        |t              } |t              }| j	                  |j
                  dj                  t                     y)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.
        ry   rz   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   rJ   r+   r   r(   )r!   r]   	decoratorr   s       r"   &test_deprecatedReplacementWithCallablez?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallablev  sQ     )Q1-w4JK	-(MM3 4:6(3C	
r$   c                 
   d}t        d      5 }t        d       t        dd       | j                  |g        t        ddd       | j                  |g        t        ddd	       | j                  t	        |      d
       | j                  |d   j
                  t               | j                  t        |d   j                        |       |j                          t        ddd       | j                  |g        t        dddd       | j                  t	        |      d
       | j                  |d   j
                  t               | j                  t        |d   j                        |       d d d        y # 1 sw Y   y xY w)NzzThe 'foo' parameter to twisted.python.test.test_deprecate.functionWithDeprecatedParameter was deprecated in Twisted 19.2.0Tr   r   
         (   )r0   rP   r   2   )r*  )
r   r   r+  rJ   rn   ri   rm   r   r^   r   )r!   r^   wss      r"   test_deprecatedKeywordParameterz8DeprecatedDecoratorTests.test_deprecatedKeywordParameter  s>   / 	 4( 	:B"+B3R$+BB7R$+B;SWa(RU^^-?@SA/9HHJ+B;R$+BB;SWa(RU^^-?@SA/9+	: 	: 	:s   E!E99FN)r(   r)   r*   r+   r3  r7  r:  r=  r?  rB  rJ  r,   r$   r"   r-  r-     s+    
:@:(:6
&
&:r$   r-  c                   "    e Zd ZdZd Zd Zd Zy)AppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    c                 Z    d }t        |d       | j                  d|j                         y)zP
        Appending to an empty docstring simply replaces the docstring.
        c                       y r   r,   r,   r$   r"   noDocstringzGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstring  r   r$   Appended text.Nr
   rJ   r+   )r!   rO  s     r"   test_appendToEmptyDocstringz2AppendToDocstringTests.test_appendToEmptyDocstring  s+    
	 	;(89);+>+>?r$   c                     d }t        |d       | j                  g d|j                  j                                | j	                  |j                  j                  d             y)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                       y);This doesn't comply with standards, but is here for a test.Nr,   r,   r$   r"   singleLineDocstringzTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstring  r   r$   rP  )rU  r  rP  
N)r
   rJ   r+   r/  r   r   )r!   rV  s     r"    test_appendToSingleLineDocstringz7AppendToDocstringTests.test_appendToSingleLineDocstring  s]    	N 	.0@A
  ''224	
 	+33<<TBCr$   c                 Z    d }t        |d       | j                  d|j                         y)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                       y)z9
            This is a multi-line docstring.
            Nr,   r,   r$   r"   multiLineDocstringzRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstring  r   r$   rP  z1
This is a multi-line docstring.

Appended text.
NrQ  )r!   r[  s     r"   test_appendToMultilineDocstringz6AppendToDocstringTests.test_appendToMultilineDocstring  s/    	
 	-/?@L&&	
r$   N)r(   r)   r*   r+   rR  rX  r\  r,   r$   r"   rL  rL    s    	@D2
r$   rL  c                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)MutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    c                     t        t        dd      r t        t        j                  |      ||      S t	        t        j
                  |      ||      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)rA   inspectr   r`  r   
getargspecr!   funcargskws       r"   checkPassedz(MutualArgumentExclusionTests.checkPassed  sF     7K.#G$5$5d$;T2FF "'"4"4T":D"EEr$   c                 f    d }| j                  | j                  |dd      t        dd             y)z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        c                      y r   r,   r'  r(  s     r"   rd  zGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.func
  r   r$   rP   rx   rj  NrJ   rg  r   r!   rd  s     r"   test_passed_simplePositionalz9MutualArgumentExclusionTests.test_passed_simplePositional  s.    	 	))$15ta1~Fr$   c                 R    d }| j                  t        | j                  |ddd       y)z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        c                      y r   r,   rj  s     r"   rd  zBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.func  r   r$   rP   rx   r  Nr?   	TypeErrorrg  rl  s     r"   test_passed_tooManyArgsz4MutualArgumentExclusionTests.test_passed_tooManyArgs  s'    	 	)T%5%5tQ1Er$   c                 R    d }| j                  t        | j                  |dd       y)zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        c                      y r   r,   r'  s    r"   rd  zHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.func   r   r$   rP   rx   ru  Nrp  rl  s     r"   test_passed_doublePassKeywordz:MutualArgumentExclusionTests.test_passed_doublePassKeyword  (    	 	)T%5%5tQ!Dr$   c                 R    d }| j                  t        | j                  |dd       y)z
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        c                      y r   r,   ru  s    r"   rd  zIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.func+  r   r$   rP   rx   )zNrp  rl  s     r"   test_passed_unspecifiedKeywordz;MutualArgumentExclusionTests.test_passed_unspecifiedKeyword%  rw  r$   c                 h    d }| j                  | j                  |ddd      t        dd             y)z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        c                      y r   r,   rj  s     r"   rd  z;MutualArgumentExclusionTests.test_passed_star.<locals>.func6  r   r$   rP   rx   r  )rx   r  rj  Nrk  rl  s     r"   test_passed_starz-MutualArgumentExclusionTests.test_passed_star0  s1    	 	))$1a8$f:MNr$   c                     d }| j                  | j                  |dddd      t        dt        ddd                   y)	zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c                      y r   r,   rj  s     r"   rd  z?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcA  r   r$   rP   rx   r     )r   yrz  rj  Nrk  rl  s     r"   test_passed_starStarz1MutualArgumentExclusionTests.test_passed_starStar;  sC    	 	T1Q!4dQ$aSTBU6V	
r$   c                 n    dd}| j                  | j                  |ddd      t        ddd             y)	zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rP   rx   c                      y r   r,   r'  r(  r)  des        r"   rd  zFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.funcN  r   r$      )r  )r'  r(  r  NrP   rx   r  rk  rl  s     r"   test_passed_noDefaultValuesz8MutualArgumentExclusionTests.test_passed_noDefaultValuesH  s6    	 	))$1):D1Q<OPr$   c                     t        dg      dd       }| j                   |dd      d       | j                   |ddd      d       | j                   |ddd      d	       y
)z
        L{mutuallyExclusiveArguments} does not interfere in its
        decoratee's operation, either its receipt of arguments or its return
        value.
        rj  c                     | |z   |z   |z   S r   r,   )r   r  r'  r(  s       r"   rd  zMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.funcZ  s    q519q= r$   rP   rx   rD  r     r(     Nr  r  )r   rJ   rl  s     r"   "test_mutualExclusionPrimeDirectivez?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectiveS  se     
%j\	2	! 
3	! 	aR(aA+aa"-r$   c                 `    t        ddgg      dd       }| j                  t        |dd       y)	z
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        r'  r(  r  r  c                     | |z   S r   r,   rj  s     r"   rd  zPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funch  s    q5Lr$   rj  Nr  )r   r?   rq  rl  s     r"   %test_mutualExclusionExcludesByKeywordzBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordb  s:     
%sCj\	2	 
3	 	)TQ!4r$   c                     G d d      } G d d      }d } |dd       t        j                  |      j                  }|j                         } |dd      |d	<    ||      }| j	                  t
        t        |d
i        y)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 Zy)MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturec                     || _         y r   )
parameters)r!   r  s     r"   r#   zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__v  s	    ",r$   Nr(   r)   r*   r#   r,   r$   r"   FakeSignaturer  u  s    -r$   r  c                       e Zd Zd Zy)MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameterc                      || _         || _        y r   )ro   kind)r!   ro   r  s      r"   r#   zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__z  s     	 	r$   Nr  r,   r$   r"   FakeParameterr  y  s    !r$   r  c                      y r   r,   rj  s     r"   rd  zDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.func~  r   r$   rP   rx   faker)  rP   rx   N)ra  r`  r  r   r?   rq  r   )r!   r  r  rd  r  dummyParametersfakeSigs          r"   test_invalidParameterTypez6MutualArgumentExclusionTests.test_invalidParameterTypen  sz    	- 	-	! 	!
	 	Q
&&t,77
$//+,VV<0)%5wKr$   N)r(   r)   r*   r+   rg  rm  rr  rv  r{  r~  r  r  r  r  r  r,   r$   r"   r^  r^    sF    F,	G	F	E	E	O
	Q.
5Lr$   r^  c                       e Zd ZdZd Zd Zy)KeywordOnlyTestsz,
    Keyword only arguments (PEP 3102).
    c                 B    t        t        j                  |      ||      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}
        )r   ra  r`  rc  s       r"   rg  zKeywordOnlyTests.checkPassed  s       1 1$ 7rBBr$   c                    ddd}ddd}| j                  | j                  |ddd      t        dd	             | j                  | j                  |dddd
      t        dd
	             | j                  | j                  |ddd
ddd      t        dd
ddd             | j                  t        | j                  |ddd
dd       y)z`
        Keyword only arguments follow varargs.
        They are specified in PEP 3102.
        Tr  c                      y)zM
            b is a keyword-only argument, with a default value.
            Nr,   )r(  r'  s     r"   func1z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func1  r   r$   c                      y)zd
            b, c, d, e  are keyword-only arguments.
            b has a default value.
            Nr,   )r(  r)  r  r  r'  s        r"   func2z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func2  r   r$   rP   rx   r  r  rj  F)r(  r)  r  r  r  r  )r(  r)  r  N)rJ   rg  r   r?   rq  )r!   r  r  s      r"   test_passedKeywordOnlyz'KeywordOnlyTests.test_passedKeywordOnly  s      	
  	 	))%Aq94)t;TUUAq!u5ti57Q	
 	UAqEQ!qA6Ua12	
 	)T%5%5uaeqTUVr$   N)r(   r)   r*   r+   rg  r  r,   r$   r"   r  r    s    C"Wr$   r  r  )7r+   ra  r{   r1   r   os.pathr   r   r   	importlibr   ImportErrorincrementalr   twisted.pythonr   twisted.python.deprecater	   r
   r   r  r   r   r   r   r   r   r   r   r   twisted.python.filepathr   twisted.python.runtimer   twisted.python.testr   #twisted.python.test.modules_helpersr   twisted.trial.unittestr   r   r.   r[   r   r   r   r   r   r  r  r+  r-  rL  r^  r  r,   r$   r"   <module>r     so  
  
    1+   $    - + 4 C 6 "DY* DYN_@2 _@Dl%#68K l%^c
0 c
LG
2 G
T GIq!Q'(  )) )0 GIr1a8%@ Af:2 f:R=
0 =
@]L#6 ]L@/W* /Wo#  s   D$ $D/.D/