
    Vh_                        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#y).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y)Basez`
    A no-op class which can be used to verify the behavior of
    method-discovering APIs.
    c                      y)z9
        A no-op method which can be discovered.
        N selfs    I/home/dcms/DCMS/lib/python3.12/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y)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y)Separatez=
    A no-op class with methods with differing prefixes.
    c                      y)zJ
        A no-op method which a matching prefix to be discovered.
        Nr   r   s    r   good_methodzSeparate.good_method/   r   r   c                      y)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y)AccumulateMethodsTestszt
    Tests for L{accumulateMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 p    t               }i }t        ||       | j                  d|j                  i|       y)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@   s3     F!V$(AHH-v6r   c                 p    t               }i }t        ||       | j                  d|j                  i|       y)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   s3     E!V$(AHH-v6r   c                 r    t               }i }t        ||d       | j                  d|j                  i|       y)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   s5     J!VW-(AMM2F;r   N)r   r   r   r   r(   r*   r-   r   r   r   r"   r"   :   s    
	7
7	<r   r"   c                       e Zd ZdZd Zd Zy)PrefixedMethodsTestszr
    Tests for L{prefixedMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 h    t               }t        |      }| j                  |j                  g|       y)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+    
 F #!((V,r   c                 j    t               }t        |d      }| j                  |j                  g|       y)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-    
 J G,!--&1r   N)r   r   r   r   r1   r-   r   r   r   r/   r/   c   s    
-2r   r/   c                       e Zd ZdZd Zd Zy)PrefixedMethodNamesTestsz+
    Tests for L{prefixedMethodNames}.
    c                 F    | j                  dgt        t        d             y)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Lr   c                 \     G d dt               }| j                  dgt        |d             y)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y)<PrefixedMethodNamesTests.test_inheritedMethod.<locals>.ChildNr   r   r   r   r   r   Childr9          r   r;   r   r,   N)r   r$   r   )r   r;   s     r   test_inheritedMethodz-PrefixedMethodNamesTests.test_inheritedMethod   s*    	H 	 	(%8%HIr   N)r   r   r   r   r6   r=   r   r   r   r4   r4   |   s    M	Jr   r4   c                       e Zd ZdZd Zy)AddMethodNamesToDictTestsz,
    Tests for L{addMethodNamesToDict}.
    c                      G d d      } G d dt         |      }i }t        ||d|       | j                  ddi|       y)	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y);AddMethodNamesToDictTests.test_baseClass.<locals>.AlternateNr:   r   r   r   	AlternaterB      r<   r   rC   c                       e Zd Zd Zy)7AddMethodNamesToDictTests.test_baseClass.<locals>.Childc                      y 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   sD    	 		Hi 	 UFGY?+q)62r   N)r   r   r   r   r*   r   r   r   r?   r?      s    3r   r?   c                       e Zd ZdZd Zy)Summerz9
    A class we look up as part of the LookupsTests.
    c                      y)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y)LookupsTestszC
    Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
    c                 V    | j                  t        j                  d      t               y)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LfUr   c                 Z    ddl m} | j                  t        j                  d      |       y)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BFKr   c                 j    ddl }| j                  t        j                  d      |j                         y)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   s%     	g&&'78'..Ir   c                 Z    ddl m} | j                  t        j                  d      |       y)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&&'>?Hr   c                 V    | j                  t        j                  d      t               y)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JFSr   c                 j    | j                  t        j                  d      t        j                         y)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	
r   c                 ~    | j                  t        j                  d      t        j                  j
                         y)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$$	
r   c                 ,   | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t
        t        j                  d       y)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   sz    
 	w//1R	
 	w//1R	
 	((*J	

 	))+K	
r   c                     | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       y)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                    | j                  t        j                  t        j                  d      }| j	                  t        |      d       | j                  t        j                  t        j                  d      }| j	                  t        |      d       | j                  t        j                  t        j                  d      }| j	                  t        |      d       | j                  t        j                  t        j                  d      }| j	                  t        |      d       d	D ]O  }| j                  t        j                  t        j                  |      }| j	                  t        |      d
|       Q y)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"  s8    ""G$4$46N
 	S#MN ""G$4$46F
 	S#MN""G$4$46N
 	S#UV 3 3W5E5ErJS#67F 	K##G$7$79I9I;WCC)47	r   c                 x    dD ]5  }t               }t        j                  ||      }| j                  ||       7 y)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  s:    
 : 	+DhG**4AFMM&'*	+r   c                 P    t        j                  d      }| j                  |       y)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&!r   c                 r    ddl m} t               }| j                  t	        j
                  d|      |       y)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[  s.    
 	*(!!"97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      sN    VLJIT
	

*
*#J
+"
r   rS   c                   ,    e Zd ZdZdZdefdZdefdZy)	BreakableFreturnc                 2    | j                   rt        d      y)Nzstr!z<Breakable>)breakStrRuntimeErrorr   s    r   __str__zBreakable.__str__n  s    ==v&& r   c                 2    | j                   rt        d      y)Nzrepr!zBreakable())	breakReprr   r   s    r   __repr__zBreakable.__repr__t  s    >>w'' r   N)r   r   r   r   r   r}   r   r   r   r   r   r   r   j  s$    IH! !!# !r   r   c                        e Zd ZdZed        Z y)
BrokenTypeFc                 2    | j                   rt        d      y)Nzno namer   )	breakNamer   r   s    r   r   zBrokenType.__name__~  s    >>y))r   N)r   r   r   r   propertyr   r   r   r   r   {  s    I r   r   BTBaseT)r   r   c                       e Zd Z ed       Zy)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    ./Ir   r   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)SafeReprTestsz2
    Tests for L{reflect.safe_repr} function.
    c           	          g ddf}| j                  t        t        t        j                  |            t        t        t
        |                   y)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  s;    
 c'"3"3R894D";NOr   c                    t               }d|_        t        j                  |      }| j	                  d|       | j	                  t
        j                  j                  t              d   |       | j	                  d|       y)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  sd    
 K!!!$0%8 	bgg&&x03U;+U3r   c                     t               }d|_        | j                  t        j                  |      t        |             y)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  s1     K
**1-tAw7r   c                      G d dt               }t        j                  |       t        j                   |              y )Nc                       e Zd ZdZy)-SafeReprTests.test_brokenClassRepr.<locals>.XTNr   r   r   r   r   r   r   Xr         Ir   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}| j	                  ||j                  d      d          y)	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y)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  sS    	 	 !!!$4RU1I=NOD(9!(<=r   c                      G d dt               }t        j                  |       t        j                   |              y )Nc                       e Zd ZdZy),SafeReprTests.test_brokenClassStr.<locals>.XTNr   r   r   r   r   r   r   r   r         Hr   r   r   r   s     r   test_brokenClassStrz!SafeReprTests.test_brokenClassStr  s.    	 	 	!!#r   c                    t               }d|_        t        j                  |      }| j	                  d|       | j	                  t
        j                  j                  t              d   |       | j	                  d|       y)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  sb     M!!!$2E:bgg&&x03U;+U3r   c                 
    G d dt               }t        j                   |             }| j                  d|       | j                  t        j
                  j                  t              d   |       | j                  d|       y)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y)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  sb    	 	 !!!#&+U3bgg&&x03U;+U3r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s0    P48>44r   r   c                   L    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y)SafeStrTestsz1
    Tests for L{reflect.safe_str} function.
    c                 h    g d}| j                  t        j                  |      t        |             y )Nr   )r$   r   safe_strr}   r   r&   s     r   test_workingStrzSafeStrTests.test_workingStr  s&    ))!,c!f5r   c                 P    t               }d|_        t        j                  |       y NT)r   r   r   r   r   s     r   r   zSafeStrTests.test_brokenStr  s    K
r   c                 R    d}| j                  t        j                  |      d       y)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  s$    
 ))!,c2r   c                 p    d}| j                  t        j                  |      |j                  d             y)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                 h    d}t        j                  |      }| j                  |t        |             y)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-     "s1v&r   c                 P    t               }d|_        t        j                  |       y r   )r   r   r   r   r   s     r   r   zSafeStrTests.test_brokenRepr  s    Kr   c                      G d dt               }t        j                  |       t        j                   |              y )Nc                       e Zd ZdZy)+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                   |              y )Nc                       e Zd ZdZy),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                  |      }| j	                  d|       | j	                  t
        j                  j                  t              d   |       | j	                  d|       y)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"  sb     M
"2D9bgg&&x03T:*D1r   c                 
    G d dt               }t        j                   |             }| j                  d|       | j                  t        j
                  j                  t              d   |       | j                  d|       y)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y)5SafeStrTests.test_brokenClassNameAttribute.<locals>.XTNr   r   r   r   r   r  6  r   r   r   r   r   r   N)r   r   r   r   r   r   r   r   )r   r   r   s      r   r   z*SafeStrTests.test_brokenClassNameAttribute/  sb    	 	 $+T2bgg&&x03T:*D1r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s:    6
3A'
22r   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)FilenameToModuleTestsz1
    Test L{filenameToModuleName} detection.
    c                 L   t         j                  j                  | j                         dd      | _        t        j                  | j                         t        t         j                  j                  | j                  d      d      5 }|j                  d       d d d        t        t         j                  j                  t         j                  j                  | j                        d      d      5 }|j                  d       d d d        y # 1 sw Y   uxY w# 1 sw Y   y xY w)Nfakepackagetestz__init__.pywr{   )r   r   joinmktempmakedirsopenwritedirname)r   fs     r   setUpzFilenameToModuleTests.setUpD  s    GGLLvF	
DII"'',,tyy-8#> 	!GGBK	"'',,rwwtyy9=I3O 	STGGBK	 		 		 	s   D3DDD#c                     t        j                  | j                        }| j                  |d       t        j                  | j                  t        j                  j
                  z         }| j                  |d       y)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_directoryL  s[    
 --dii8!34--dii"''++.EF!34r   c                     t        j                  t        j                  j	                  | j                  d            }| j                  |d       y)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_fileV  s>    
 --GGLL$56
 	!@Ar   c                     t        j                  t        j                  j	                  | j                  j                  d      d            }| j                  |d       y)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_bytes`  sI    
 --GGLL))'24FG
 	!@Ar   N)r   r   r   r   r  r  r  r  r   r   r   r  r  ?  s    5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
y	)
FullyQualifiedNameTestsz)
    Test for L{fullyQualifiedName}.
    c                 :    | j                  t        |      |       y)ze
        Helper to check that fully qualified name of C{obj} results to
        C{expected}.
        N)r$   r   )r   objexpecteds      r   _checkFullyQualifiedNamez0FullyQualifiedNameTests._checkFullyQualifiedNameq  s    
 	+C0(;r   c                 p    ddl }| j                  |d       ddl}| j                  |j                  d       y)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_packagex  s/    
 	%%gy9%%gnn6FGr   c                 X    ddl }| j                  |j                  j                  d       y)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  s"     	%%%gnn&;&;=TUr   c                 >    | j                  t        t         d       y)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  s     	%%#z1I%J	
r   c                 0    | j                  t        d       y)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                 x    | j                  | j                  t         d| j                  j                   d       y)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  s7    
 	%%!!j$..1122CD	
r   c                     | j                  | j                  j                  t         d| j                  j                   d       y)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  s;    
 	%%NN--j$..1122EF	
r   N)r   r   r   r   r#  r%  r)  r+  r-  r0  r2  r   r   r   r  r  l  s,    <
HV



r   r  c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)ObjectGrepTestsc                     t               }d|i}|di}| j                  dt        j                  ||t        j                               | j                  dt        j                  ||t        j                               y)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  s[     HAYYhAw~~ FGhAw~~ FGr   c                     t               }d|g}| j                  dt        j                  ||t        j                               y)z8
        Test references search through a list.
        N[1]r6  )r   r9  Ls      r   	test_listzObjectGrepTests.test_list  s3     H1IeW__Q7>>BCr   c                     t               }|df}| j                  dt        j                  ||t        j                               y)z9
        Test references search through a tuple.
        N[0]r6  )r   r9  Ts      r   
test_tuplezObjectGrepTests.test_tuple  s3     HIeW__Q7>>BCr   c                      G d d      }t               } |       }||_        | j                  dt        j                  ||t        j
                               y)zE
        Test references search through an object attribute.
        c                       e Zd Zy),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  sB    
	 	 HGdGOOAq'..ABr   c                      G d d      } |       }t        j                  |      }| j                  dt        j                  ||t        j
                               y)zB
        Test references search through a weakref object.
        c                       e Zd Zy)+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  sA    
	 	 G[[^dGOOB7>>BCr   c                     G d d      } |       }|j                   }| j                  dt        j                  ||j                  t        j
                               | j                  dt        j                  ||j                  j                  t        j
                               | j                  dt        j                  ||j                  t        j
                               y)zK
        Test references search through method special attributes.
        c                       e Zd Zd Zy)/ObjectGrepTests.test_boundMethod.<locals>.Dummyc                      y 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    
	 	 GGGk7??1ajj'..#QR!OOAqzz33W^^D	
 	k7??1ajj'..#QRr   c                 *    G d d      } |       }dddd|di}dd|dg}|i  |       f}d	d
|d} |       }||_         |j                  }t        j                  |      }	| j	                  dt        j                  |	|t
        j                               y)zF
        Test references search using complex set of objects.
        c                       e Zd Zd Zy).ObjectGrepTests.test_everything.<locals>.Dummyc                      y 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    
	 	 G%vq'22r1EG5Q'GHHKKN0'//!Q2W	
r   c           	      r   g }|g}||g}||g}| j                  dgt        j                  ||t        j                  d             | j                  ddgt        j                  ||t        j                  d             | j                  g dt        j                  ||t        j                  d             y)	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THwq!W^^aP	
 	*OOAq'..1=	
r   c                     t               }t               }|j                  d       |j                  |       | j                  dt	        j
                  ||t        j                               y)z@
        Test references search through a deque object.
        Nr>  )r   r   appendr   r   r7  r8  )r   r9  Ds      r   
test_dequezObjectGrepTests.test_deque&  sG     HG		eW__Q7>>BCr   N)r   r   r   r<  r@  rD  rJ  rQ  r0  rg  rl  rp  r   r   r   r4  r4    s6    	HDDCDS&
.
$	Dr   r4  c                       e Zd Zd Zy)GetClassTestsc                      G d d      } |       }| j                  t        j                  |      j                  d       | j                  t        j                  |      j                  d       y )Nc                       e Zd Zy)(GetClassTests.test_new.<locals>.NewClassNr:   r   r   r   NewClassru  4  r<   r   rv  type)r$   r   getClassr   )r   rv  news      r   test_newzGetClassTests.test_new3  sW    	 	 j))(3<<fE))#.77Dr   N)r   r   r   rz  r   r   r   rr  rr  2  s    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	 	$   &<X &<R28 22Jx J03 3. q
8 q
h! !"D  
Hyl$D,Q	R0) 0Z4H Z4zS28 S2l*BH *BZB
h B
J~Dh ~DBEH Er   