o
    ¯b•_  ã                   @   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   ú;/usr/lib/python3/dist-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   Ú
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.pythonrH   rB   r   ÚnamedModule©r   rH   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)rJ   rB   r   ÚnamedAnyÚpython©r   Útwistedr   r   r   Útest_namedAnyPackageLookupÊ   s   z'LookupsTests.test_namedAnyPackageLookupc                 C   rF   )zX
        L{namedAny} should return the module object for the name it is passed.
        r   rG   rI   N)rJ   rH   rB   r   rO   rL   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   rO   r=   r   r   r   r   Útest_namedAnyClassLookupÚ   rE   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   rO   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   rO   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   rO   Ú
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)rX   ÚAttributeErrorr   rO   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
        Ú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)rX   r   ÚModuleNotFoundrO   r    ÚstrÚObjectNotFoundÚInvalidName)r   ÚerrÚ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.
        )Únosuchmtopoduleúno.such.module©ÚdefaultN)Úobjectr   ÚrequireModulerB   )r   Únamerk   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.
        ri   N)r   rm   Ú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   rG   rI   rj   N)rJ   rH   rl   rB   r   rm   )r   rH   rk   r   r   r   Ú!test_requireModuleRequestedImport[  s   þz.LookupsTests.test_requireModuleRequestedImportN)r   r   r   r   rD   rM   rS   rT   rU   rV   rW   r\   r^   rg   ro   rq   rr   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__o  ó   zBreakable.__str__c                 C   ru   )Nzrepr!zBreakable())Ú	breakReprrw   r   r   r   r   Ú__repr__u  ry   zBreakable.__repr__N)r   r   r   rz   rv   rb   rx   r{   r   r   r   r   rs   j  s
    rs   c                   @   s   e Zd ZdZedd„ ƒZ dS )Ú
BrokenTypeFc                 C   ru   )Nzno namer|   )Ú	breakNamerw   r   r   r   r   r     s   zBrokenType.__name__N)r   r   r   r}   Úpropertyr   r   r   r   r|   |  s    r|   ÚBTBaseT)rz   rv   c                   @   s   e Zd Zedd„ ƒZdS )ÚNoClassAttrc                 C   s   | j S r5   )Ú	not_class)r"   r   r   r   Ú<lambda>Š  s    zNoClassAttr.<lambda>N)r   r   r   r~   Ú	__class__r   r   r   r   r€   ‰  s    r€   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)	rs   rz   r   r‹   ÚassertInÚosÚpathÚsplitextÚ__file__©r   ÚbÚ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)rs   rv   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   rz   r   r   r   r   ÚX±  r   rž   ©r   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)r   r   r‹   Úidr    Úsplit)r   rž   ÚxReprÚxReprExpectedr   r   r   Útest_brokenReprIncludesID·  s   
z'SafeReprTests.test_brokenReprIncludesIDc                 C   rœ   )Nc                   @   r   )z,SafeReprTests.test_brokenClassStr.<locals>.XTN©r   r   r   rv   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)	r€   rz   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   r}   r   r   r   r   rž   á  r   rž   ú<BROKEN CLASS AT 0xr   r�   N)r   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   r„   �  s    r„   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	d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_strrb   ©r   r"   r   r   r   Útest_workingStrï  s   zSafeStrTests.test_workingStrc                 C   ó   t ƒ }d|_t |¡ d S ©NT)rs   rv   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    rb   )r   r"   ÚxStrr   r   r   Útest_brokenUtf8  s   
zSafeStrTests.test_brokenUtf8c                 C   r·   r¸   )rs   rz   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ž   ©r   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)	r€   rv   r   r´   r‘   r’   r“   r”   r•   )r   r—   Ú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ž   7  r   rž   r°   r   rÃ   N)r   r   r´   r‘   r’   r“   r”   r•   )r   rž   rÀ   r   r   r   r±   0  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 )NÚfakepackageÚtestz__init__.pyÚwr`   )r’   r“   ÚjoinÚmktempÚmakedirsÚopenÚwriteÚdirname)r   Úfr   r   r   ÚsetUpE  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_directoryM  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_fileW  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_bytesa  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   Ú_checkFullyQualifiedNamer  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   NrR   rN   )rR   rÝ   rJ   rP   rQ   r   r   r   Útest_packagey  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)Útwisted.python.compatrÝ   rP   ÚcompatrQ   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   rƒ   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Ý   rƒ   Ú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Ú   m  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}©rl   r‘   r   ÚobjgrepÚisSame)r   ÚoÚd1Ú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)rl   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ë   Ú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ê   rƒ   Ú__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   ÚbazNÚQuuxÚFooshr‡   ÚfooÚbar)r   r:   r†   z"().__self__.attr[2][0][2]{'Foosh'})Úattrr   rù   rú   r‘   r   ré   rê   )
r   rö   rë   ÚD1rð   rô   Ú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:   )Ú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ï   )rl   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   ÚNewClass5  r/   r  Útype)r    r   ÚgetClassr   )r   r  Únewr   r   r   Útest_new4  s   zGetClassTests.test_newN)r   r   r   r  r   r   r   r   r  3  r8   r  )$r   r’   rù   Úcollectionsr   rJ   r   Útwisted.python.reflectr   r   r   r   r   Útwisted.trial.unittestr	   ÚTestCaser   r   r   r   r(   r*   r1   r=   r?   rs   r  r|   r   r€   r„   r³   rÅ   rÚ   rç   r  r   r   r   r   Ú<module>   s8   ) 5
]V-E 