
    \d_                     n   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          Z G d	 d
e          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d          Z G d de          Z G d d          Z G d dee          Z edefddd          Z G d  d!e          Z G d" d#e          Z G d$ d%e          Z G d& d'e          Z  G d( d)e          Z! G d* d+e          Z" G 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 ZdS )Basez`
    A no-op class which can be used to verify the behavior of
    method-discovering APIs.
    c                     dS )z9
        A no-op method which can be discovered.
        N selfs    9lib/python3.11/site-packages/twisted/test/test_reflect.pymethodzBase.method             N)__name__
__module____qualname____doc__r   r   r   r   r   r      s-         
    r   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   $   s           r   r   c                       e Zd ZdZd Zd ZdS )Separatez=
    A no-op class with methods with differing prefixes.
    c                     dS )zJ
        A no-op method which a matching prefix to be discovered.
        Nr   r   s    r   good_methodzSeparate.good_method/   r   r   c                     dS )zO
        A no-op method with a mismatched prefix to not be discovered.
        Nr   r   s    r   
bad_methodzSeparate.bad_method4   r   r   N)r   r   r   r   r   r    r   r   r   r   r   *   s<           
    r   r   c                   $    e Zd ZdZd Zd Zd ZdS )AccumulateMethodsTestszt
    Tests for L{accumulateMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    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outputs      r   test_ownClassz$AccumulateMethodsTests.test_ownClass@   sE     FF!V$$$(AH-v66666r   c                     t                      }i }t          ||           |                     d|j        i|           dS )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%   s      r   test_baseClassz%AccumulateMethodsTests.test_baseClassK   sE     EE!V$$$(AH-v66666r   c                     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%   s      r   test_prefixz"AccumulateMethodsTests.test_prefixW   sG     JJ!VW---(AM2F;;;;;r   N)r   r   r   r   r(   r*   r-   r   r   r   r"   r"   :   sK         
	7 	7 	7
7 
7 
7	< 	< 	< 	< 	<r   r"   c                       e Zd ZdZd Zd ZdS )PrefixedMethodsTestszr
    Tests for L{prefixedMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 x    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%   s      r   test_onlyObjectz$PrefixedMethodsTests.test_onlyObjecti   s:    
 FF ##!(V,,,,,r   c                 z    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%   s      r   r-   z PrefixedMethodsTests.test_prefixr   s<    
 JJ G,,!-&11111r   N)r   r   r   r   r1   r-   r   r   r   r/   r/   c   s<         
- - -2 2 2 2 2r   r/   c                       e Zd ZdZd Zd ZdS )PrefixedMethodNamesTestsz+
    Tests for L{prefixedMethodNames}.
    c                 Z    |                      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   s    r   test_methodz$PrefixedMethodNamesTests.test_method   s-    
 	(%87%K%KLLLLLr   c                 v     G 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 )<PrefixedMethodNamesTests.test_inheritedMethod.<locals>.ChildNr   r   r   r   r   r   Childr9              Dr   r;   r   r,   N)r   r$   r   )r   r;   s     r   test_inheritedMethodz-PrefixedMethodNamesTests.test_inheritedMethod   sW    	 	 	 	 	H 	 	 	 	(%8%H%HIIIIIr   N)r   r   r   r   r6   r=   r   r   r   r4   r4   |   sD         M M M	J 	J 	J 	J 	Jr   r4   c                       e Zd ZdZd ZdS )AddMethodNamesToDictTestsz,
    Tests for L{addMethodNamesToDict}.
    c                      G d d          } G 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                       e Zd ZdS );AddMethodNamesToDictTests.test_baseClass.<locals>.AlternateNr:   r   r   r   	AlternaterB      r<   r   rC   c                       e Zd Zd ZdS )7AddMethodNamesToDictTests.test_baseClass.<locals>.Childc                     d S Nr   r   s    r   good_alternatezFAddMethodNamesToDictTests.test_baseClass.<locals>.Child.good_alternate       r   N)r   r   r   rH   r   r   r   r;   rE      #            r   r;   r,   	alternate   N)r   r   r$   )r   rC   r;   results       r   r*   z(AddMethodNamesToDictTests.test_baseClass   s    	 	 	 	 	 	 	 		 	 	 	 	Hi 	 	 	 UFGY???+q)622222r   N)r   r   r   r   r*   r   r   r   r?   r?      s-         3 3 3 3 3r   r?   c                       e Zd ZdZd ZdS )Summerz9
    A class we look up as part of the LookupsTests.
    c                     dS )z
        Do something.
        Nr   r   s    r   	reallySetzSummer.reallySet   r   r   N)r   r   r   r   rQ   r   r   r   rO   rO      s-             r   rO   c                   `    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d Zd ZdS )LookupsTestszC
    Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
    c                 `    |                      t          j        d          t                     dS )zY
        L{namedClass} should return the class object for the name it is passed.
         twisted.test.test_reflect.SummerN)assertIsr   
namedClassrO   r   s    r   test_namedClassLookupz"LookupsTests.test_namedClassLookup   s*     	g()KLLfUUUUUr   c                 b    ddl m} |                     t          j        d          |           dS )zc
        L{namedModule} should return the module object for the name it is
        passed.
        r   monkeytwisted.python.monkeyN)twisted.pythonr[   rV   r   namedModuler   r[   s     r   test_namedModuleLookupz#LookupsTests.test_namedModuleLookup   s<    
 	*)))))g)*ABBFKKKKKr   c                 h    ddl }|                     t          j        d          |j                   dS )zY
        L{namedAny} should return the package object for the name it is passed.
        r   Ntwisted.python)r]   rV   r   namedAnypythonr   twisteds     r   test_namedAnyPackageLookupz'LookupsTests.test_namedAnyPackageLookup   s8     	g&'788'.IIIIIr   c                 b    ddl m} |                     t          j        d          |           dS )zX
        L{namedAny} should return the module object for the name it is passed.
        r   rZ   r\   N)r]   r[   rV   r   rc   r_   s     r   test_namedAnyModuleLookupz&LookupsTests.test_namedAnyModuleLookup   s<     	*)))))g&'>??HHHHHr   c                 `    |                      t          j        d          t                     dS )zW
        L{namedAny} should return the class object for the name it is passed.
        rU   N)rV   r   rc   rO   r   s    r   test_namedAnyClassLookupz%LookupsTests.test_namedAnyClassLookup   s*     	g&'IJJFSSSSSr   c                 j    |                      t          j        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   rc   rO   rQ   r   s    r   test_namedAnyAttributeLookupz)LookupsTests.test_namedAnyAttributeLookup   s;     	IJJ	
 	
 	
 	
 	
r   c                 t    |                      t          j        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)rV   r   rc   rO   rQ   r   r   s    r   "test_namedAnySecondAttributeLookupz/LookupsTests.test_namedAnySecondAttributeLookup   s<     	TUU$	
 	
 	
 	
 	
r   c                 6   |                      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   rc   
ValueErrorImportErrorr   s    r   test_importExceptionsz"LookupsTests.test_importExceptions   s    
 	w/1R	
 	
 	
 	w/1R	
 	
 	
 	(*J	
 	
 	

 	)+K	
 	
 	
 	
 	
r   c                     |                      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)rq   AttributeErrorr   rc   r   s    r   test_attributeExceptionsz%LookupsTests.test_attributeExceptions  s|     	G,.N	
 	
 	
 	G,.P	
 	
 	
 	>	
 	
 	
 	
 	
r   c                 "   |                      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 ]S}|                      t          j        t          j        |          }|                     t          |          d
|           Td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..pythonzMname must be a string giving a '.'-separated list of Python identifiers, not N)rq   r   ModuleNotFoundrc   r$   strObjectNotFoundInvalidName)r   errinvalidNames      r   test_invalidNameszLookupsTests.test_invalidNames"  sn    "G$46N
 
 	S#MNNN "G$46F
 
 	S#MNNN"G$46N
 
 	S#UVVV 3W5ErJJS#6777F 	 	K##G$79I;WWCC)47   	 	r   c                     dD ]<}t                      }t          j        ||          }|                     ||           =dS )zk
        When module import fails with ImportError it returns the specified
        default value.
        )nosuchmtopoduleno.such.moduledefaultN)objectr   requireModulerV   )r   namer   rM   s       r   test_requireModuleImportErrorz*LookupsTests.test_requireModuleImportErrorG  sR    
 : 	+ 	+DhhG*4AAAFMM&'****	+ 	+r   c                 X    t          j        d          }|                     |           dS )zI
        When module import fails it returns L{None} by default.
        r   N)r   r   assertIsNone)r   rM   s     r   test_requireModuleDefaultNonez*LookupsTests.test_requireModuleDefaultNoneS  s/     &'788&!!!!!r   c                     ddl m} t                      }|                     t	          j        d|          |           dS )ze
        When module import succeed it returns the module and not the default
        value.
        r   rZ   r\   r   N)r]   r[   r   rV   r   r   )r   r[   r   s      r   !test_requireModuleRequestedImportz.LookupsTests.test_requireModuleRequestedImport[  sV    
 	*)))))((!"97KKK	
 	
 	
 	
 	
r   N)r   r   r   r   rX   r`   rg   ri   rk   rm   ro   ru   rx   r   r   r   r   r   r   r   rS   rS      s         V V VL L LJ J JI I IT T T
 
 
	
 	
 	

 
 
*
 
 
*# # #J
+ 
+ 
+" " "
 
 
 
 
r   rS   c                   .    e Zd ZdZdZdefdZdefdZdS )	BreakableFreturnc                 2    | j         rt          d          dS )Nzstr!z<Breakable>)breakStrRuntimeErrorr   s    r   __str__zBreakable.__str__o  s    = 	!v&&& =r   c                 2    | j         rt          d          dS )Nzrepr!zBreakable())	breakReprr   r   s    r   __repr__zBreakable.__repr__u  s    > 	!w''' =r   N)r   r   r   r   r   r}   r   r   r   r   r   r   r   j  sT        IH! ! ! ! !!# ! ! ! ! ! !r   r   c                   (    e Zd ZdZed             Z dS )
BrokenTypeFc                 2    | j         rt          d          dS )Nzno namer   )	breakNamer   r   s    r   r   zBrokenType.__name__  s    > 	*y)))|r   N)r   r   r   r   propertyr   r   r   r   r   |  s2        I  X  r   r   BTBaseT)r   r   c                   &    e Zd Z ed           ZdS )NoClassAttrc                     | j         S rG   )	not_class)r&   s    r   <lambda>zNoClassAttr.<lambda>  s    1; r   N)r   r   r   r   	__class__r   r   r   r   r     s!        ..//IIIr   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d
S )SafeReprTestsz2
    Tests for L{reflect.safe_repr} function.
    c           	          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.
        rL            aN)r$   listmapr   	safe_reprrepr)r   xss     r   test_workingReprzSafeReprTests.test_workingRepr  sS    
 iic'"3R88994D";N;NOOOOOr   c                 ,   t                      }d|_        t          j        |          }|                     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)	r   r   r   r   assertInospathsplitext__file__r   bbReprs      r   test_brokenReprzSafeReprTests.test_brokenRepr  s    
 KK!!$$0%888 	bg&&x003U;;;+U33333r   c                     t                      }d|_        |                     t          j        |          t          |                     dS )zT
        L{reflect.safe_repr} isn't affected by a broken C{__str__} method.
        TN)r   r   r$   r   r   r   r   r   s     r   test_brokenStrzSafeReprTests.test_brokenStr  sA     KK
*1--tAww77777r   c                      G d dt                     }t          j        |           t          j         |                       d S )Nc                       e Zd ZdZdS )-SafeReprTests.test_brokenClassRepr.<locals>.XTNr   r   r   r   r   r   r   Xr             IIIr   r   r   r   r   r   r   s     r   test_brokenClassReprz"SafeReprTests.test_brokenClassRepr  s\    	 	 	 	 	 	 	 	 	!!!##r   c                      G d dt                     }t          j        |          }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                       e Zd ZdZdS )2SafeReprTests.test_brokenReprIncludesID.<locals>.XTNr   r   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xReprExpecteds       r   test_brokenReprIncludesIDz'SafeReprTests.test_brokenReprIncludesID  s    	 	 	 	 	 	 	 	 !!$$ORUUOOOOD(9(9!(<=====r   c                      G d dt                     }t          j        |           t          j         |                       d S )Nc                       e Zd ZdZdS ),SafeReprTests.test_brokenClassStr.<locals>.XTNr   r   r   r   r   r   r   r   r             HHHr   r   r   r   s     r   test_brokenClassStrz!SafeReprTests.test_brokenClassStr  s\    	 	 	 	 	 	 	 	 	!!!##r   c                 ,   t                      }d|_        t          j        |          }|                     d|           |                     t
          j                            t                    d         |           |                     d|           dS )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   r   r   r   r   r   r   r   r   r   s      r   test_brokenClassAttributez'SafeReprTests.test_brokenClassAttribute  s}     MM!!$$2E:::bg&&x003U;;;+U33333r   c                 8    G d dt                     }t          j         |                      }|                     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                       e Zd ZdZdS )6SafeReprTests.test_brokenClassNameAttribute.<locals>.XTNr   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   s      r   test_brokenClassNameAttributez+SafeReprTests.test_brokenClassNameAttribute  s    	 	 	 	 	 	 	 	 !!!##&&+U333bg&&x003U;;;+U33333r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s         P P P4 4 48 8 8  > > >  4 4 44 4 4 4 4r   r   c                   N    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S )SafeStrTestsz1
    Tests for L{reflect.safe_str} function.
    c                 x    g d}|                      t          j        |          t          |                     d S )Nr   )r$   r   safe_strr}   r   r&   s     r   test_workingStrzSafeStrTests.test_workingStr  s8    II)!,,c!ff55555r   c                 X    t                      }d|_        t          j        |           d S NT)r   r   r   r   r   s     r   r   zSafeStrTests.test_brokenStr  s)    KK
r   c                 Z    d}|                      t          j        |          d           dS )zh
        L{safe_str} for C{str} with ascii-only data should return the
        value unchanged.
        aN)r$   r   r   r   s     r   test_workingAsciizSafeStrTests.test_workingAscii  s0    
 )!,,c22222r   c                     d}|                      t          j        |          |                    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   s     r   test_workingUtf8_3zSafeStrTests.test_workingUtf8_3   s<    
 )!,,ahhw.?.?@@@@@r   c                 x    d}t          j        |          }|                     |t          |                     dS )z=
        Use str() for non-utf8 bytes: "b'non-utf8'"
           N)r   r   r$   r}   )r   r&   xStrs      r   test_brokenUtf8zSafeStrTests.test_brokenUtf8  s;     ""s1vv&&&&&r   c                 X    t                      }d|_        t          j        |           d S r   )r   r   r   r   r   s     r   r   zSafeStrTests.test_brokenRepr  s)    KKr   c                      G d dt                     }t          j        |           t          j         |                       d S )Nc                       e Zd ZdZdS )+SafeStrTests.test_brokenClassStr.<locals>.XTNr   r   r   r   r   r     r   r   r   r   r   r   r   s     r   r   z SafeStrTests.test_brokenClassStr  s\    	 	 	 	 	 	 	 	 	r   c                      G d dt                     }t          j        |           t          j         |                       d S )Nc                       e Zd ZdZdS ),SafeStrTests.test_brokenClassRepr.<locals>.XTNr   r   r   r   r   r     r   r   r   r   r   s     r   r   z!SafeStrTests.test_brokenClassRepr  s\    	 	 	 	 	 	 	 	 	r   c                 ,   t                      }d|_        t          j        |          }|                     d|           |                     t
          j                            t                    d         |           |                     d|           dS )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   r   r   r   r   r   r   r   r   )r   r   bStrs      r   r   z&SafeStrTests.test_brokenClassAttribute#  s}     MM
""2D999bg&&x003T:::*D11111r   c                 8    G d dt                     }t          j         |                      }|                     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_str}
        returns 'BROKEN CLASS' instead of the class name.
        c                       e Zd ZdZdS )5SafeStrTests.test_brokenClassNameAttribute.<locals>.XTNr   r   r   r   r   r  7  r   r   r   r   r   r   N)r   r   r   r   r   r   r   r   )r   r   r   s      r   r   z*SafeStrTests.test_brokenClassNameAttribute0  s    	 	 	 	 	 	 	 	 $$+T222bg&&x003T:::*D11111r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s         6 6 6  
3 3 3A A A' ' '  
    2 2 22 2 2 2 2r   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )FilenameToModuleTestsz1
    Test L{filenameToModuleName} detection.
    c                 d   t           j                            |                                 dd          | _        t          j        | j                   t          t           j                            | j        d          d          5 }|                    d           d d d            n# 1 swxY w Y   t          t           j                            t           j                            | j                  d          d          5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nfakepackagetestz__init__.pywr{   )r   r   joinmktempmakedirsopenwritedirname)r   fs     r   setUpzFilenameToModuleTests.setUpE  sY   GLLvFF	
DI"',,ty-88#>> 	!GGBKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"',,rwty99=II3OO 	STGGBKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   B''B+.B+D%%D),D)c                     t          j        | j                  }|                     |d           t          j        | j        t          j        j        z             }|                     |d           dS )zk
        L{filenameToModuleName} returns the correct module (a package) given a
        directory.
        zfakepackage.testN)r   filenameToModuleNamer   r$   r   sepr   modules     r   test_directoryz$FilenameToModuleTests.test_directoryM  se    
 -di88!3444-di"'+.EFF!344444r   c                     t          j        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  s     r   	test_filezFilenameToModuleTests.test_fileW  sK    
 -GLL$566
 
 	!@AAAAAr   c                     t          j        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  s     r   
test_bytesz FilenameToModuleTests.test_bytesa  sY    
 -GLL))'224FGG
 
 	!@AAAAAr   N)r   r   r   r   r  r  r  r  r   r   r   r  r  @  sb           5 5 5B B B	B 	B 	B 	B 	Br   r  c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
FullyQualifiedNameTestsz)
    Test for L{fullyQualifiedName}.
    c                 L    |                      t          |          |           dS )ze
        Helper to check that fully qualified name of C{obj} results to
        C{expected}.
        N)r$   r   )r   objexpecteds      r   _checkFullyQualifiedNamez0FullyQualifiedNameTests._checkFullyQualifiedNamer  s)    
 	+C00(;;;;;r   c                 x    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   Nrf   rb   )rf   r#  r]   rd   re   s     r   test_packagez$FullyQualifiedNameTests.test_packagey  sN    
 	%%gy999%%gn6FGGGGGr   c                 N    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#  rd   compatre   s     r   test_modulez#FullyQualifiedNameTests.test_module  s2     	%$$$%%gn&;=TUUUUUr   c                 L    |                      t          t           d           dS )zS
        L{fullyQualifiedName} returns the name of a class and its module.
        z.FullyQualifiedNameTestsN)r#  r  r   r   s    r   
test_classz"FullyQualifiedNameTests.test_class  s4     	%%#%J%J%J	
 	
 	
 	
 	
r   c                 <    |                      t          d           dS )zY
        L{fullyQualifiedName} returns the name of a function inside its module.
        z)twisted.python.reflect.fullyQualifiedNameN)r#  r   r   s    r   test_functionz%FullyQualifiedNameTests.test_function  s,     	%% K	
 	
 	
 	
 	
r   c                 f    |                      | 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   s    r   r0  z(FullyQualifiedNameTests.test_boundMethod  sE    
 	%%!DD$.1DDD	
 	
 	
 	
 	
r   c                 p    |                      | 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   s    r   r2  z*FullyQualifiedNameTests.test_unboundMethod  sG    
 	%%N-FF$.1FFF	
 	
 	
 	
 	
r   N)r   r   r   r   r#  r%  r)  r+  r-  r0  r2  r   r   r   r  r  m  s         < < <
H 
H 
HV V V
 
 

 
 

 
 

 
 
 
 
r   r  c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )ObjectGrepTestsc                    t                      }d|i}|di}|                     dt          j        ||t          j                             |                     dt          j        ||t          j                             dS )zV
        Test references search through a dictionary, as a key or as a value.
        Nz[None]z{None}r   r   r   objgrepisSame)r   od1d2s       r   test_dictionaryzObjectGrepTests.test_dictionary  sm     HHAYYhAw~ F FGGGhAw~ F FGGGGGr   c                     t                      }d|g}|                     dt          j        ||t          j                             dS )z8
        Test references search through a list.
        N[1]r6  )r   r9  Ls      r   	test_listzObjectGrepTests.test_list  s@     HH1IeW_Q7>BBCCCCCr   c                     t                      }|df}|                     dt          j        ||t          j                             dS )z9
        Test references search through a tuple.
        N[0]r6  )r   r9  Ts      r   
test_tuplezObjectGrepTests.test_tuple  s@     HHIeW_Q7>BBCCCCCr   c                      G d d          }t                      } |            }||_        |                     dt          j        ||t          j                             dS )zE
        Test references search through an object attribute.
        c                       e Zd ZdS ),ObjectGrepTests.test_instance.<locals>.DummyNr:   r   r   r   DummyrG    r<   r   rH  z.oN)r   r9  r   r   r7  r8  )r   rH  r9  ds       r   test_instancezObjectGrepTests.test_instance  sq    
	 	 	 	 	 	 	 	 HHEGGdGOAq'.AABBBBBr   c                      G d d          } |            }t          j        |          }|                     dt          j        ||t          j                             dS )zB
        Test references search through a weakref object.
        c                       e Zd ZdS )+ObjectGrepTests.test_weakref.<locals>.DummyNr:   r   r   r   rH  rM    r<   r   rH  z()N)weakrefrefr   r   r7  r8  )r   rH  r9  w1s       r   test_weakrefzObjectGrepTests.test_weakref  sn    
	 	 	 	 	 	 	 	 EGG[^^dGOB7>BBCCCCCr   c                     G d d          } |            }|j         }|                     dt          j        ||j        t          j                             |                     dt          j        ||j        j        t          j                             |                     dt          j        ||j        t          j                             dS )zK
        Test references search through method special attributes.
        c                       e Zd Zd ZdS )/ObjectGrepTests.test_boundMethod.<locals>.Dummyc                     d S rG   r   r   s    r   dummyz5ObjectGrepTests.test_boundMethod.<locals>.Dummy.dummy  rI   r   N)r   r   r   rV  r   r   r   rH  rT    rJ   r   rH  z	.__self__z.__self__.__class__z	.__func__N)rV  r   r   r7  __self__r8  r   __func__)r   rH  r9  ms       r   r0  z ObjectGrepTests.test_boundMethod  s    
	 	 	 	 	 	 	 	 EGGGk7?1aj'.#Q#QRRR!OAqz3W^DD	
 	
 	
 	k7?1aj'.#Q#QRRRRRr   c                 6    G d d          } |            }dddd|di}dd|dg}|i  |            f}d	d
|d} |            }||_         |j        }t          j        |          }	|                     dt          j        |	|t
          j                             dS )zF
        Test references search using complex set of objects.
        c                       e Zd Zd ZdS ).ObjectGrepTests.test_everything.<locals>.Dummyc                     d S rG   r   r   s    r   r   z5ObjectGrepTests.test_everything.<locals>.Dummy.method  rI   r   N)r   r   r   r   r   r   r   rH  r\    rJ   r   rH  r   bazNQuuxFooshr   foobar)r   rL   r   z"().__self__.attr[2][0][2]{'Foosh'})attrr   rN  rO  r   r   r7  r8  )
r   rH  r9  D1r?  rC  D2irY  r	  s
             r   test_everythingzObjectGrepTests.test_everything  s    
	 	 	 	 	 	 	 	 EGG%vq'22r1EEGG5Q''EGGHKNN0'/!Q2W2W	
 	
 	
 	
 	
r   c           	      n   g }|g}||g}||g}|                      dgt          j        ||t          j        d                     |                      ddgt          j        ||t          j        d                     |                      g dt          j        ||t          j        d                     dS )	z6
        Test the depth of references search.
        rB  rL   )maxDepth[1][0]r   )rB  rj  z	[1][1][0]r   N)r$   r   r7  r8  )r   r   r   crI  s        r   test_depthLimitzObjectGrepTests.test_depthLimit  s     CFF%'/!QQR"S"S"STTTHwq!W^aPPP	
 	
 	
 	***OAq'.1===	
 	
 	
 	
 	
r   c                     t                      }t                      }|                    d           |                    |           |                     dt	          j        ||t          j                             dS )z@
        Test references search through a deque object.
        Nr>  )r   r   appendr   r   r7  r8  )r   r9  Ds      r   
test_dequezObjectGrepTests.test_deque'  s^     HHGG		eW_Q7>BBCCCCCr   N)r   r   r   r<  r@  rD  rJ  rQ  r0  rg  rl  rp  r   r   r   r4  r4    s        	H 	H 	HD D DD D DC C CD D DS S S&
 
 
.
 
 
$	D 	D 	D 	D 	Dr   r4  c                       e Zd Zd ZdS )GetClassTestsc                      G d d          } |            }|                      t          j        |          j        d           |                      t          j        |          j        d           d S )Nc                       e Zd ZdS )(GetClassTests.test_new.<locals>.NewClassNr:   r   r   r   NewClassru  5  r<   r   rv  type)r$   r   getClassr   )r   rv  news      r   test_newzGetClassTests.test_new4  s    	 	 	 	 	 	 	 	 hjj)(33<fEEE)#..7DDDDDr   N)r   r   r   rz  r   r   r   rr  rr  3  s(        E E E E Er   rr  )$r   r   rN  collectionsr   r]   r   twisted.python.reflectr   r   r   r   r	   twisted.trial.unittestr
   TestCaser   r   r   r"   r/   r4   r?   rO   rS   r   rw  r   r   r   r   r   r  r  r4  rr  r   r   r   <module>r     s
   
 
			        " " " " " "              C B B B B B	 	 	 	 	 	 	 	    $           &< &< &< &< &<X &< &< &<R2 2 2 2 28 2 2 22J J J J Jx J J J03 3 3 3 3 3 3 3.       q
 q
 q
 q
 q
8 q
 q
 q
h! ! ! ! ! ! ! !$    D    
Hyl$D,Q,Q	R	R0 0 0 0 0) 0 0 0Z4 Z4 Z4 Z4 Z4H Z4 Z4 Z4zS2 S2 S2 S2 S28 S2 S2 S2l*B *B *B *B *BH *B *B *BZB
 B
 B
 B
 B
h B
 B
 B
J~D ~D ~D ~D ~Dh ~D ~D ~DBE E E E EH E E E E Er   