o
    Óó·i”_  ã                   @   s†  d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ G dd„ dƒZG d	d
„ d
eƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZG dd„ deƒZG dd„ dƒZG dd„ deeƒZedefdddœƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZG d&d'„ d'eƒZ G d(d)„ d)eƒZ!G d*d+„ d+eƒZ"G d,d-„ d-eƒZ#dS ).z6
Test cases for the L{twisted.python.reflect} module.
é    N)Údeque)Úreflect)ÚaccumulateMethodsÚaddMethodNamesToDictÚfullyQualifiedNameÚprefixedMethodNamesÚprefixedMethods)ÚSynchronousTestCasec                   @   ó   e Zd ZdZdd„ ZdS )ÚBasez`
    A no-op class which can be used to verify the behavior of
    method-discovering APIs.
    c                 C   ó   dS )z9
        A no-op method which can be discovered.
        N© ©Úselfr   r   ú_C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/test/test_reflect.pyÚmethod   ó    zBase.methodN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                   @   ó   e Zd ZdZdS )ÚSubzF
    A subclass of a class with a method which can be discovered.
    N)r   r   r   r   r   r   r   r   r   $   ó    r   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )ÚSeparatez=
    A no-op class with methods with differing prefixes.
    c                 C   r   )zJ
        A no-op method which a matching prefix to be discovered.
        Nr   r   r   r   r   Úgood_method/   r   zSeparate.good_methodc                 C   r   )zO
        A no-op method with a mismatched prefix to not be discovered.
        Nr   r   r   r   r   Ú
bad_method4   r   zSeparate.bad_methodN)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 )	ÚAccumulateMethodsTestszt
    Tests for L{accumulateMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 C   ó*   t ƒ }i }t||ƒ |  d|ji|¡ dS )zí
        If x is and instance of Base and Base defines a method named method,
        L{accumulateMethods} adds an item to the given dictionary with
        C{"method"} as the key and a bound method object for Base.method value.
        r   N)r   r   ÚassertEqualr   ©r   ÚxÚoutputr   r   r   Útest_ownClass@   s   
z$AccumulateMethodsTests.test_ownClassc                 C   r   )a  
        If x is an instance of Sub and Sub is a subclass of Base and Base
        defines a method named method, L{accumulateMethods} adds an item to the
        given dictionary with C{"method"} as the key and a bound method object
        for Base.method as the value.
        r   N)r   r   r    r   r!   r   r   r   Útest_baseClassK   s   
z%AccumulateMethodsTests.test_baseClassc                 C   s,   t ƒ }i }t||dƒ |  d|ji|¡ dS )zÐ
        If a prefix is given, L{accumulateMethods} limits its results to
        methods beginning with that prefix.  Keys in the resulting dictionary
        also have the prefix removed from them.
        Úgood_r   N)r   r   r    r   r!   r   r   r   Útest_prefixW   s   z"AccumulateMethodsTests.test_prefixN)r   r   r   r   r$   r%   r'   r   r   r   r   r   :   s
    r   c                   @   r   )ÚPrefixedMethodsTestszr
    Tests for L{prefixedMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 C   s"   t ƒ }t|ƒ}|  |jg|¡ dS )zc
        L{prefixedMethods} returns a list of the methods discovered on an
        object.
        N)r   r   r    r   r!   r   r   r   Útest_onlyObjecti   s   z$PrefixedMethodsTests.test_onlyObjectc                 C   s$   t ƒ }t|dƒ}|  |jg|¡ dS )zo
        If a prefix is given, L{prefixedMethods} returns only methods named
        with that prefix.
        r&   N)r   r   r    r   r!   r   r   r   r'   r   s   
z PrefixedMethodsTests.test_prefixN)r   r   r   r   r)   r'   r   r   r   r   r(   c   s    	r(   c                   @   r   )ÚPrefixedMethodNamesTestsz+
    Tests for L{prefixedMethodNames}.
    c                 C   s   |   dgttdƒ¡ dS )zŠ
        L{prefixedMethodNames} returns a list including methods with the given
        prefix defined on the class passed to it.
        r   r&   N)r    r   r   r   r   r   r   Útest_method�   s   z$PrefixedMethodNamesTests.test_methodc                 C   s(   G dd„ dt ƒ}|  dgt|dƒ¡ dS )z™
        L{prefixedMethodNames} returns a list included methods with the given
        prefix defined on base classes of the class passed to it.
        c                   @   ó   e Zd ZdS )z<PrefixedMethodNamesTests.test_inheritedMethod.<locals>.ChildN©r   r   r   r   r   r   r   ÚChildŽ   ó    r.   r   r&   N)r   r    r   )r   r.   r   r   r   Útest_inheritedMethodˆ   s   z-PrefixedMethodNamesTests.test_inheritedMethodN)r   r   r   r   r+   r0   r   r   r   r   r*   |   s    r*   c                   @   r
   )ÚAddMethodNamesToDictTestsz,
    Tests for L{addMethodNamesToDict}.
    c                 C   sF   G dd„ dƒ}G dd„ dt |ƒ}i }t||d|ƒ |  ddi|¡ dS )	z¥
        If C{baseClass} is passed to L{addMethodNamesToDict}, only methods which
        are a subclass of C{baseClass} are added to the result dictionary.
        c                   @   r,   )z;AddMethodNamesToDictTests.test_baseClass.<locals>.AlternateNr-   r   r   r   r   Ú	AlternateŸ   r/   r2   c                   @   ó   e Zd Zdd„ ZdS )z7AddMethodNamesToDictTests.test_baseClass.<locals>.Childc                 S   ó   d S ©Nr   r   r   r   r   Úgood_alternate£   ó   zFAddMethodNamesToDictTests.test_baseClass.<locals>.Child.good_alternateN)r   r   r   r6   r   r   r   r   r.   ¢   ó    r.   r&   Ú	alternateé   N)r   r   r    )r   r2   r.   Úresultr   r   r   r%   ™   s
   z(AddMethodNamesToDictTests.test_baseClassN)r   r   r   r   r%   r   r   r   r   r1   ”   ó    r1   c                   @   r
   )ÚSummerz9
    A class we look up as part of the LookupsTests.
    c                 C   r   )z
        Do something.
        Nr   r   r   r   r   Ú	reallySet°   r   zSummer.reallySetN)r   r   r   r   r>   r   r   r   r   r=   «   r<   r=   c                   @   sx   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d„ Zdd„ ZdS )ÚLookupsTestszC
    Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
    c                 C   ó   |   t d¡t¡ dS )zY
        L{namedClass} should return the class object for the name it is passed.
        ú twisted.test.test_reflect.SummerN)ÚassertIsr   Z
namedClassr=   r   r   r   r   Útest_namedClassLookup»   ó   z"LookupsTests.test_namedClassLookupc                 C   ó"   ddl m} |  t d¡|¡ dS )zc
        L{namedModule} should return the module object for the name it is
        passed.
        r   ©Úmonkeyútwisted.python.monkeyN)Útwisted.pythonrG   rB   r   ZnamedModule©r   rG   r   r   r   Útest_namedModuleLookupÁ   s   z#LookupsTests.test_namedModuleLookupc                 C   s    ddl }|  t d¡|j¡ dS )zY
        L{namedAny} should return the package object for the name it is passed.
        r   Nútwisted.python)rI   rB   r   ÚnamedAnyÚpython©r   Útwistedr   r   r   Útest_namedAnyPackageLookupÊ   s   z'LookupsTests.test_namedAnyPackageLookupc                 C   rE   )zX
        L{namedAny} should return the module object for the name it is passed.
        r   rF   rH   N)rI   rG   rB   r   rM   rJ   r   r   r   Útest_namedAnyModuleLookupÒ   s   z&LookupsTests.test_namedAnyModuleLookupc                 C   r@   )zW
        L{namedAny} should return the class object for the name it is passed.
        rA   N)rB   r   rM   r=   r   r   r   r   Útest_namedAnyClassLookupÚ   rD   z%LookupsTests.test_namedAnyClassLookupc                 C   s   |   t d¡tj¡ dS )z–
        L{namedAny} should return the object an attribute of a non-module,
        non-package object is bound to for the name it is passed.
        z*twisted.test.test_reflect.Summer.reallySetN)r    r   rM   r=   r>   r   r   r   r   Útest_namedAnyAttributeLookupà   s   þz)LookupsTests.test_namedAnyAttributeLookupc                 C   s   |   t d¡tjj¡ dS )zÉ
        L{namedAny} should return the object an attribute of an object which
        itself was an attribute of a non-module, non-package object is bound to
        for the name it is passed.
        z2twisted.test.test_reflect.Summer.reallySet.__doc__N)rB   r   rM   r=   r>   r   r   r   r   r   Ú"test_namedAnySecondAttributeLookupí   s   þz/LookupsTests.test_namedAnySecondAttributeLookupc                 C   sD   |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ dS )z�
        Exceptions raised by modules which L{namedAny} causes to be imported
        should pass through L{namedAny} to the caller.
        ztwisted.test.reflect_helper_ZDEztwisted.test.reflect_helper_VEztwisted.test.reflect_helper_IEN)ÚassertRaisesÚZeroDivisionErrorr   rM   Ú
ValueErrorÚImportErrorr   r   r   r   Útest_importExceptionsø   s   ÿÿÿÿz"LookupsTests.test_importExceptionsc                 C   s4   |   ttjd¡ |   ttjd¡ |   ttjd¡ dS )zï
        If segments on the end of a fully-qualified Python name represents
        attributes which aren't actually present on the object represented by
        the earlier segments, L{namedAny} should raise an L{AttributeError}.
        ztwisted.nosuchmoduleintheworldz twisted.nosuch.modulein.theworldz0twisted.test.test_reflect.Summer.nosuchattributeN)rV   ÚAttributeErrorr   rM   r   r   r   r   Útest_attributeExceptions  s   ÿÿýz%LookupsTests.test_attributeExceptionsc                 C   s¾   |   tjtjd¡}|  t|ƒd¡ |   tjtjd¡}|  t|ƒd¡ |   tjtjd¡}|  t|ƒd¡ |   tjtjd¡}|  t|ƒd¡ d	D ]}|   tjtj|¡}|  t|ƒd
|f ¡ qFdS )a•  
        Passing a name which isn't a fully-qualified Python name to L{namedAny}
        should result in one of the following exceptions:
         - L{InvalidName}: the name is not a dot-separated list of Python
           objects
         - L{ObjectNotFound}: the object doesn't exist
         - L{ModuleNotFound}: the object doesn't exist and there is only one
           component in the name
        Znosuchmoduleintheworldz(No module named 'nosuchmoduleintheworld'z@#$@(#.!@(#!@#z('@#$@(#.!@(#!@#' does not name an objectztcelfer.nohtyp.detsiwtz0'tcelfer.nohtyp.detsiwt' does not name an objectÚ zEmpty module name)z.twistedztwisted.ztwisted..pythonzOname must be a string giving a '.'-separated list of Python identifiers, not %rN)rV   r   ZModuleNotFoundrM   r    ÚstrZObjectNotFoundZInvalidName)r   ÚerrZinvalidNamer   r   r   Útest_invalidNames"  s.   

ÿ
ÿ
ÿÿþþzLookupsTests.test_invalidNamesc                 C   s.   dD ]}t ƒ }tj||d�}|  ||¡ qdS )zk
        When module import fails with ImportError it returns the specified
        default value.
        )Znosuchmtopoduleúno.such.module©ÚdefaultN)Úobjectr   ÚrequireModulerB   )r   Únamerc   r;   r   r   r   Útest_requireModuleImportErrorG  s
   ûz*LookupsTests.test_requireModuleImportErrorc                 C   s   t  d¡}|  |¡ dS )zI
        When module import fails it returns L{None} by default.
        ra   N)r   re   ZassertIsNone)r   r;   r   r   r   Útest_requireModuleDefaultNoneS  s   
z*LookupsTests.test_requireModuleDefaultNonec                 C   s,   ddl m} tƒ }|  tjd|d�|¡ dS )ze
        When module import succeed it returns the module and not the default
        value.
        r   rF   rH   rb   N)rI   rG   rd   rB   r   re   )r   rG   rc   r   r   r   Ú!test_requireModuleRequestedImport[  s   þz.LookupsTests.test_requireModuleRequestedImportN)r   r   r   r   rC   rK   rQ   rR   rS   rT   rU   rZ   r\   r`   rg   rh   ri   r   r   r   r   r?   ¶   s    	%r?   c                   @   s0   e Zd ZdZdZdefdd„Zdefdd„ZdS )Ú	BreakableFÚreturnc                 C   ó   | j rtdƒ‚dS )Nzstr!z<Breakable>)ÚbreakStrÚRuntimeErrorr   r   r   r   Ú__str__n  ó   zBreakable.__str__c                 C   rl   )Nzrepr!zBreakable())Ú	breakReprrn   r   r   r   r   Ú__repr__t  rp   zBreakable.__repr__N)r   r   r   rq   rm   r^   ro   rr   r   r   r   r   rj   j  s
    rj   c                   @   s   e Zd ZdZedd„ ƒZ dS )Ú
BrokenTypeFc                 C   rl   )Nzno namers   )Ú	breakNamern   r   r   r   r   r   ~  s   zBrokenType.__name__N)r   r   r   rt   Úpropertyr   r   r   r   rs   {  s    rs   ÚBTBaseT)rq   rm   c                   @   s   e Zd Zedd„ ƒZdS )ÚNoClassAttrc                 C   s   | j S r5   )Z	not_class)r"   r   r   r   Ú<lambda>‰  s    zNoClassAttr.<lambda>N)r   r   r   ru   Ú	__class__r   r   r   r   rw   ˆ  s    rw   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 )ÚSafeReprTestsz2
    Tests for L{reflect.safe_repr} function.
    c                 C   s2   g d¢df}|   tttj|ƒƒttt|ƒƒ¡ dS )zg
        L{reflect.safe_repr} produces the same output as C{repr} on a working
        object.
        ©r:   é   é   ó   aN)r    ÚlistÚmapr   Ú	safe_reprÚrepr)r   Úxsr   r   r   Útest_workingRepr‘  s   &zSafeReprTests.test_workingReprc                 C   óJ   t ƒ }d|_t |¡}|  d|¡ |  tj t¡d |¡ |  d|¡ dS )z‚
        L{reflect.safe_repr} returns a string with class name, address, and
        traceback when the repr call failed.
        TzBreakable instance at 0xr   úRuntimeError: repr!N)	rj   rq   r   r�   ÚassertInÚosÚpathÚsplitextÚ__file__©r   ÚbZbReprr   r   r   Útest_brokenRepr™  s   
zSafeReprTests.test_brokenReprc                 C   s&   t ƒ }d|_|  t |¡t|ƒ¡ dS )zT
        L{reflect.safe_repr} isn't affected by a broken C{__str__} method.
        TN)rj   rm   r    r   r�   r‚   ©r   r�   r   r   r   Útest_brokenStr§  s   zSafeReprTests.test_brokenStrc                 C   ó*   G dd„ dt ƒ}t |¡ t |ƒ ¡ d S )Nc                   @   r   )z-SafeReprTests.test_brokenClassRepr.<locals>.XTN©r   r   r   rq   r   r   r   r   ÚX°  r   r“   ©rv   r   r�   ©r   r“   r   r   r   Útest_brokenClassRepr¯  ó   
z"SafeReprTests.test_brokenClassReprc                 C   sF   G dd„ dt ƒ}t |¡}dt|ƒd›d�}|  || d¡d ¡ dS )	zË
        C{id} is used to print the ID of the object in case of an error.

        L{safe_repr} includes a traceback after a newline, so we only check
        against the first line of the repr.
        c                   @   r   )z2SafeReprTests.test_brokenReprIncludesID.<locals>.XTNr’   r   r   r   r   r“   ¾  r   r“   z<BrokenType instance at 0xr"   z with repr error:Ú
r   N)rv   r   r�   Úidr    Úsplit)r   r“   ÚxReprZxReprExpectedr   r   r   Útest_brokenReprIncludesID¶  s   
z'SafeReprTests.test_brokenReprIncludesIDc                 C   r‘   )Nc                   @   r   )z,SafeReprTests.test_brokenClassStr.<locals>.XTN©r   r   r   rm   r   r   r   r   r“   Æ  r   r“   r”   r•   r   r   r   Útest_brokenClassStrÅ  r—   z!SafeReprTests.test_brokenClassStrc                 C   r…   )z­
        If an object raises an exception when accessing its C{__class__}
        attribute, L{reflect.safe_repr} uses C{type} to retrieve the class
        object.
        TúNoClassAttr instance at 0xr   r†   N)	rw   rq   r   r�   r‡   rˆ   r‰   rŠ   r‹   rŒ   r   r   r   Útest_brokenClassAttributeÌ  ó   
z'SafeReprTests.test_brokenClassAttributec                 C   óP   G dd„ dt ƒ}t |ƒ ¡}|  d|¡ |  tj t¡d |¡ |  d|¡ dS )zã
        If a class raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{reflect.safe_repr}
        returns 'BROKEN CLASS' instead of the class name.
        c                   @   r   )z6SafeReprTests.test_brokenClassNameAttribute.<locals>.XTN©r   r   r   rt   r   r   r   r   r“   à  r   r“   ú<BROKEN CLASS AT 0xr   r†   N)rv   r   r�   r‡   rˆ   r‰   rŠ   r‹   )r   r“   r›   r   r   r   Útest_brokenClassNameAttributeÙ  ó
   z+SafeReprTests.test_brokenClassNameAttributeN)r   r   r   r   r„   rŽ   r�   r–   rœ   rž   r    r¥   r   r   r   r   rz   Œ  s    rz   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d„ Z
dd„ Zdd„ Zdd„ ZdS )ÚSafeStrTestsz1
    Tests for L{reflect.safe_str} function.
    c                 C   s"   g d¢}|   t |¡t|ƒ¡ d S )Nr{   )r    r   Úsafe_strr^   ©r   r"   r   r   r   Útest_workingStrî  s   zSafeStrTests.test_workingStrc                 C   ó   t ƒ }d|_t |¡ d S ©NT)rj   rm   r   r¨   r�   r   r   r   r�   ò  ó   zSafeStrTests.test_brokenStrc                 C   s   d}|   t |¡d¡ dS )zh
        L{safe_str} for C{str} with ascii-only data should return the
        value unchanged.
        ÚaN)r    r   r¨   r©   r   r   r   Útest_workingAscii÷  s   zSafeStrTests.test_workingAsciic                 C   s    d}|   t |¡| d¡¡ dS )zw
        L{safe_str} for C{bytes} with utf-8 encoded data should return
        the value decoded into C{str}.
        s   tÃ¼stúutf-8N)r    r   r¨   Údecoder©   r   r   r   Útest_workingUtf8_3ÿ  s   zSafeStrTests.test_workingUtf8_3c                 C   s"   d}t  |¡}|  |t|ƒ¡ dS )z=
        Use str() for non-utf8 bytes: "b'non-utf8'"
        ó   ÿN)r   r¨   r    r^   )r   r"   ÚxStrr   r   r   Útest_brokenUtf8  s   
zSafeStrTests.test_brokenUtf8c                 C   r«   r¬   )rj   rq   r   r¨   r�   r   r   r   rŽ     r­   zSafeStrTests.test_brokenReprc                 C   r‘   )Nc                   @   r   )z+SafeStrTests.test_brokenClassStr.<locals>.XTNr�   r   r   r   r   r“     r   r“   ©rv   r   r¨   r•   r   r   r   rž     r—   z SafeStrTests.test_brokenClassStrc                 C   r‘   )Nc                   @   r   )z,SafeStrTests.test_brokenClassRepr.<locals>.XTNr’   r   r   r   r   r“     r   r“   r¶   r•   r   r   r   r–     r—   z!SafeStrTests.test_brokenClassReprc                 C   r…   )z¬
        If an object raises an exception when accessing its C{__class__}
        attribute, L{reflect.safe_str} uses C{type} to retrieve the class
        object.
        TrŸ   r   úRuntimeError: str!N)	rw   rm   r   r¨   r‡   rˆ   r‰   rŠ   r‹   )r   r�   ZbStrr   r   r   r    "  r¡   z&SafeStrTests.test_brokenClassAttributec                 C   r¢   )zâ
        If a class raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{reflect.safe_str}
        returns 'BROKEN CLASS' instead of the class name.
        c                   @   r   )z5SafeStrTests.test_brokenClassNameAttribute.<locals>.XTNr£   r   r   r   r   r“   6  r   r“   r¤   r   r·   N)rv   r   r¨   r‡   rˆ   r‰   rŠ   r‹   )r   r“   r´   r   r   r   r¥   /  r¦   z*SafeStrTests.test_brokenClassNameAttributeN)r   r   r   r   rª   r�   r¯   r²   rµ   rŽ   rž   r–   r    r¥   r   r   r   r   r§   é  s    r§   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚFilenameToModuleTestsz1
    Test L{filenameToModuleName} detection.
    c                 C   s°   t j |  ¡ dd¡| _t  | j¡ tt j | jd¡dƒ�}| d¡ W d   ƒ n1 s,w   Y  tt j t j | j¡d¡dƒ�}| d¡ W d   ƒ d S 1 sQw   Y  d S )NZfakepackageÚtestz__init__.pyÚwr]   )rˆ   r‰   ÚjoinÚmktempÚmakedirsÚopenÚwriteÚdirname)r   Úfr   r   r   ÚsetUpD  s   ÿ "ÿzFilenameToModuleTests.setUpc                 C   s<   t  | j¡}|  |d¡ t  | jtjj ¡}|  |d¡ dS )zk
        L{filenameToModuleName} returns the correct module (a package) given a
        directory.
        zfakepackage.testN)r   ÚfilenameToModuleNamer‰   r    rˆ   Úsep©r   Úmoduler   r   r   Útest_directoryL  s   z$FilenameToModuleTests.test_directoryc                 C   s&   t  tj | jd¡¡}|  |d¡ dS )zh
        L{filenameToModuleName} returns the correct module given the path to
        its file.
        ztest_reflect.pyúfakepackage.test.test_reflectN)r   rÃ   rˆ   r‰   r»   r    rÅ   r   r   r   Ú	test_fileV  s   ÿzFilenameToModuleTests.test_filec                 C   s,   t  tj | j d¡d¡¡}|  |d¡ dS )zo
        L{filenameToModuleName} returns the correct module given a C{bytes}
        path to its file.
        r°   s   test_reflect.pyrÈ   N)r   rÃ   rˆ   r‰   r»   Úencoder    rÅ   r   r   r   Ú
test_bytes`  s   ÿz FilenameToModuleTests.test_bytesN)r   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S )ÚFullyQualifiedNameTestsz)
    Test for L{fullyQualifiedName}.
    c                 C   s   |   t|ƒ|¡ dS )ze
        Helper to check that fully qualified name of C{obj} results to
        C{expected}.
        N)r    r   )r   ÚobjÚexpectedr   r   r   Ú_checkFullyQualifiedNameq  s   z0FullyQualifiedNameTests._checkFullyQualifiedNamec                 C   s.   ddl }|  |d¡ ddl}|  |jd¡ dS )zd
        L{fullyQualifiedName} returns the full name of a package and a
        subpackage.
        r   NrP   rL   )rP   rÏ   rI   rN   rO   r   r   r   Útest_packagex  s   z$FullyQualifiedNameTests.test_packagec                 C   s   ddl }|  |jjd¡ dS )zV
        L{fullyQualifiedName} returns the name of a module inside a package.
        r   Nztwisted.python.compat)Ztwisted.python.compatrÏ   rN   ÚcompatrO   r   r   r   Útest_module„  s   z#FullyQualifiedNameTests.test_modulec                 C   s   |   tt› d�¡ dS )zS
        L{fullyQualifiedName} returns the name of a class and its module.
        z.FullyQualifiedNameTestsN)rÏ   rÌ   r   r   r   r   r   Ú
test_classŒ  s   
ÿz"FullyQualifiedNameTests.test_classc                 C   s   |   td¡ dS )zY
        L{fullyQualifiedName} returns the name of a function inside its module.
        z)twisted.python.reflect.fullyQualifiedNameN)rÏ   r   r   r   r   r   Útest_function”  s   ÿz%FullyQualifiedNameTests.test_functionc                 C   s"   |   | jt› d| jj› d�¡ dS )zs
        L{fullyQualifiedName} returns the name of a bound method inside its
        class and its module.
        Ú.z.test_boundMethodN)rÏ   Útest_boundMethodr   ry   r   r   r   r   rÖ   œ  s   þz(FullyQualifiedNameTests.test_boundMethodc                 C   s$   |   | jjt› d| jj› d�¡ dS )zv
        L{fullyQualifiedName} returns the name of an unbound method inside its
        class and its module.
        rÕ   z.test_unboundMethodN)rÏ   ry   Útest_unboundMethodr   r   r   r   r   r×   ¦  s   þz*FullyQualifiedNameTests.test_unboundMethodN)r   r   r   r   rÏ   rÐ   rÒ   rÓ   rÔ   rÖ   r×   r   r   r   r   rÌ   l  s    
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 )ÚObjectGrepTestsc                 C   sJ   t ƒ }d|i}|di}|  dt ||tj¡¡ |  dt ||tj¡¡ dS )zV
        Test references search through a dictionary, as a key or as a value.
        Nz[None]z{None}©rd   r‡   r   ÚobjgrepÚisSame)r   ÚoZd1Zd2r   r   r   Útest_dictionary²  s
   zObjectGrepTests.test_dictionaryc                 C   s*   t ƒ }d|g}|  dt ||tj¡¡ dS )z8
        Test references search through a list.
        Nú[1]rÙ   )r   rÜ   ÚLr   r   r   Ú	test_list½  ó   zObjectGrepTests.test_listc                 C   s*   t ƒ }|df}|  dt ||tj¡¡ dS )z9
        Test references search through a tuple.
        Nú[0]rÙ   )r   rÜ   ÚTr   r   r   Ú
test_tupleÆ  rá   zObjectGrepTests.test_tuplec                 C   s<   G dd„ dƒ}t ƒ }|ƒ }||_|  dt ||tj¡¡ dS )zE
        Test references search through an object attribute.
        c                   @   r,   )z,ObjectGrepTests.test_instance.<locals>.DummyNr-   r   r   r   r   ÚDummyÔ  r/   rå   z.oN)rd   rÜ   r‡   r   rÚ   rÛ   )r   rå   rÜ   Údr   r   r   Útest_instanceÏ  s
   zObjectGrepTests.test_instancec                 C   s:   G dd„ dƒ}|ƒ }t  |¡}|  dt ||tj¡¡ dS )zB
        Test references search through a weakref object.
        c                   @   r,   )z+ObjectGrepTests.test_weakref.<locals>.DummyNr-   r   r   r   r   rå   â  r/   rå   z()N)ÚweakrefÚrefr‡   r   rÚ   rÛ   )r   rå   rÜ   Zw1r   r   r   Útest_weakrefÝ  s   
zObjectGrepTests.test_weakrefc                 C   sn   G dd„ dƒ}|ƒ }|j }|  dt ||jtj¡¡ |  dt ||jjtj¡¡ |  dt ||jtj¡¡ dS )zK
        Test references search through method special attributes.
        c                   @   r3   )z/ObjectGrepTests.test_boundMethod.<locals>.Dummyc                 S   r4   r5   r   r   r   r   r   Údummyð  r7   z5ObjectGrepTests.test_boundMethod.<locals>.Dummy.dummyN)r   r   r   rë   r   r   r   r   rå   ï  r8   rå   z	.__self__z.__self__.__class__z	.__func__N)rë   r‡   r   rÚ   Ú__self__rÛ   ry   Ú__func__)r   rå   rÜ   Úmr   r   r   rÖ   ê  s   þz ObjectGrepTests.test_boundMethodc           
      C   s€   G dd„ dƒ}|ƒ }dddd|di}dd|dg}|i |ƒ f}d	d
|dœ}|ƒ }||_ |j}t |¡}	|  dt |	|tj¡¡ dS )zF
        Test references search using complex set of objects.
        c                   @   r3   )z.ObjectGrepTests.test_everything.<locals>.Dummyc                 S   r4   r5   r   r   r   r   r   r     r7   z5ObjectGrepTests.test_everything.<locals>.Dummy.methodN)r   r   r   r   r   r   r   r   rå     r8   rå   r   ZbazNZQuuxZFooshr}   ZfooÚbar)r   r:   r|   z"().__self__.attr[2][0][2]{'Foosh'})Úattrr   rè   ré   r‡   r   rÚ   rÛ   )
r   rå   rÜ   ZD1rß   rã   ZD2Úirî   rº   r   r   r   Útest_everythingý  s   
ÿzObjectGrepTests.test_everythingc              	   C   s|   g }|g}||g}||g}|   dgtj||tjdd�¡ |   ddgtj||tjdd�¡ |   g d¢tj||tjdd�¡ dS )	z6
        Test the depth of references search.
        râ   r:   )ZmaxDepthú[1][0]r|   )râ   ró   z	[1][1][0]r}   N)r    r   rÚ   rÛ   )r   r®   r�   Úcræ   r   r   r   Útest_depthLimit  s   ÿþzObjectGrepTests.test_depthLimitc                 C   s<   t ƒ }tƒ }| d¡ | |¡ |  dt ||tj¡¡ dS )z@
        Test references search through a deque object.
        NrÞ   )rd   r   Úappendr‡   r   rÚ   rÛ   )r   rÜ   ÚDr   r   r   Ú
test_deque&  s
   

zObjectGrepTests.test_dequeN)r   r   r   rÝ   rà   rä   rç   rê   rÖ   rò   rõ   rø   r   r   r   r   rØ   ±  s    		rØ   c                   @   r3   )ÚGetClassTestsc                 C   s@   G dd„ dƒ}|ƒ }|   t |¡jd¡ |   t |¡jd¡ d S )Nc                   @   r,   )z(GetClassTests.test_new.<locals>.NewClassNr-   r   r   r   r   ÚNewClass4  r/   rú   Útype)r    r   ZgetClassr   )r   rú   Únewr   r   r   Útest_new3  s   zGetClassTests.test_newN)r   r   r   rý   r   r   r   r   rù   2  r8   rù   )$r   rˆ   rè   Úcollectionsr   rI   r   Ztwisted.python.reflectr   r   r   r   r   Ztwisted.trial.unittestr	   ZTestCaser   r   r   r   r(   r*   r1   r=   r?   rj   rû   rs   rv   rw   rz   r§   r¸   rÌ   rØ   rù   r   r   r   r   Ú<module>   s8   ) 5
]V-E 