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 