
    h_                        S r SSKrSSKrSSKJr  SSKJr  SSKJrJ	r	J
r
JrJr  SSKJr   " S S5      r " S	 S
\5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S5      r " S S\5      r " S S5      r " S S\\5      r\" S\4SSS.5      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      r  " S( S)\5      r! " S* S+\5      r" " S, S-\5      r#g).z6
Test cases for the L{twisted.python.reflect} module.
    N)deque)reflect)accumulateMethodsaddMethodNamesToDictfullyQualifiedNameprefixedMethodNamesprefixedMethods)SynchronousTestCasec                       \ rS rSrSrS rSrg)Base   zT
A no-op class which can be used to verify the behavior of
method-discovering APIs.
c                     g)z)
A no-op method which can be discovered.
N selfs    `/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_reflect.pymethodBase.method           r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s    
r   r   c                       \ rS rSrSrSrg)Sub$   z>
A subclass of a class with a method which can be discovered.
r   N)r   r   r   r   r   r   r   r   r   r   r   $   s    r   r   c                   $    \ rS rSrSrS rS rSrg)Separate*   z5
A no-op class with methods with differing prefixes.
c                     g)z:
A no-op method which a matching prefix to be discovered.
Nr   r   s    r   good_methodSeparate.good_method/   r   r   c                     g)z?
A no-op method with a mismatched prefix to not be discovered.
Nr   r   s    r   
bad_methodSeparate.bad_method4   r   r   r   N)r   r   r   r   r   r$   r'   r   r   r   r   r!   r!   *   s    
r   r!   c                   *    \ rS rSrSrS rS rS rSrg)AccumulateMethodsTests:   zh
Tests for L{accumulateMethods} which finds methods on a class hierarchy and
adds them to a dictionary.
c                 n    [        5       n0 n[        X5        U R                  SUR                  0U5        g)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_ownClass$AccumulateMethodsTests.test_ownClass@   s1     F!$(AHH-v6r   c                 n    [        5       n0 n[        X5        U R                  SUR                  0U5        g)z
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_baseClass%AccumulateMethodsTests.test_baseClassK   s1     E!$(AHH-v6r   c                 p    [        5       n0 n[        XS5        U R                  SUR                  0U5        g)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_prefix"AccumulateMethodsTests.test_prefixW   s3     J!W-(AMM2F;r   r   N)	r   r   r   r   r   r1   r4   r8   r   r   r   r   r*   r*   :   s    
	7
7	<r   r*   c                   $    \ rS rSrSrS rS rSrg)PrefixedMethodsTestsc   zf
Tests for L{prefixedMethods} which finds methods on a class hierarchy and
adds them to a dictionary.
c                 h    [        5       n[        U5      nU R                  UR                  /U5        g)zK
L{prefixedMethods} returns a list of the methods discovered on an
object.
N)r   r	   r-   r   r.   s      r   test_onlyObject$PrefixedMethodsTests.test_onlyObjecti   s+    
 F #!((V,r   c                 j    [        5       n[        US5      nU R                  UR                  /U5        g)zW
If a prefix is given, L{prefixedMethods} returns only methods named
with that prefix.
r7   N)r!   r	   r-   r$   r.   s      r   r8    PrefixedMethodsTests.test_prefixr   s-    
 J G,!--&1r   r   N)r   r   r   r   r   r>   r8   r   r   r   r   r;   r;   c   s    
-2r   r;   c                   $    \ rS rSrSrS rS rSrg)PrefixedMethodNamesTests|   z#
Tests for L{prefixedMethodNames}.
c                 F    U R                  S/[        [        S5      5        g)zr
L{prefixedMethodNames} returns a list including methods with the given
prefix defined on the class passed to it.
r   r7   N)r-   r   r!   r   s    r   test_method$PrefixedMethodNamesTests.test_method   s    
 	(%87%KLr   c                 \     " S S[         5      nU R                  S/[        US5      5        g)z
L{prefixedMethodNames} returns a list included methods with the given
prefix defined on base classes of the class passed to it.
c                       \ rS rSrSrg)<PrefixedMethodNamesTests.test_inheritedMethod.<locals>.Child   r   Nr   r   r   r   r   r   r   r   ChildrJ          r   rM   r   r7   N)r!   r-   r   )r   rM   s     r   test_inheritedMethod-PrefixedMethodNamesTests.test_inheritedMethod   s*    	H 	 	(%8%HIr   r   N)r   r   r   r   r   rF   rO   r   r   r   r   rC   rC   |   s    M	Jr   rC   c                       \ rS rSrSrS rSrg)AddMethodNamesToDictTests   z$
Tests for L{addMethodNamesToDict}.
c                 ~     " S S5      n " S S[         U5      n0 n[        X#SU5        U R                  SS0U5        g)	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S rSrSrg);AddMethodNamesToDictTests.test_baseClass.<locals>.Alternate   r   NrL   r   r   r   	AlternaterV      rN   r   rX   c                       \ rS rSrS rSrg)7AddMethodNamesToDictTests.test_baseClass.<locals>.Child   c                     g Nr   r   s    r   good_alternateFAddMethodNamesToDictTests.test_baseClass.<locals>.Child.good_alternate       r   r   N)r   r   r   r   r^   r   r   r   r   rM   rZ          r   rM   r7   	alternate   N)r!   r   r-   )r   rX   rM   results       r   r4   (AddMethodNamesToDictTests.test_baseClass   sB    	 		Hi 	 UGY?+q)62r   r   N)r   r   r   r   r   r4   r   r   r   r   rR   rR      s    3r   rR   c                       \ rS rSrSrS rSrg)Summer   z1
A class we look up as part of the LookupsTests.
c                     g)z
Do something.
Nr   r   s    r   	reallySetSummer.reallySet   r   r   r   N)r   r   r   r   r   rj   r   r   r   r   rg   rg      s    r   rg   c                   f    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)LookupsTests   z;
Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
c                 X    U R                  [        R                  " S5      [        5        g)zI
L{namedClass} should return the class object for the name it is passed.
 twisted.test.test_reflect.SummerN)assertIsr   
namedClassrg   r   s    r   test_namedClassLookup"LookupsTests.test_namedClassLookup   s     	g(()KLfUr   c                 \    SSK Jn  U R                  [        R                  " S5      U5        g)zK
L{namedModule} should return the module object for the name it is
passed.
r   monkeytwisted.python.monkeyN)twisted.pythonrw   rq   r   namedModuler   rw   s     r   test_namedModuleLookup#LookupsTests.test_namedModuleLookup   s!    
 	*g))*ABFKr   c                 l    SSK nU R                  [        R                  " S5      UR                  5        g)zI
L{namedAny} should return the package object for the name it is passed.
r   Ntwisted.python)ry   rq   r   namedAnypythonr   twisteds     r   test_namedAnyPackageLookup'LookupsTests.test_namedAnyPackageLookup   s%     	g&&'78'..Ir   c                 \    SSK Jn  U R                  [        R                  " S5      U5        g)zH
L{namedAny} should return the module object for the name it is passed.
r   rv   rx   N)ry   rw   rq   r   r   r{   s     r   test_namedAnyModuleLookup&LookupsTests.test_namedAnyModuleLookup   s!     	*g&&'>?Hr   c                 X    U R                  [        R                  " S5      [        5        g)zG
L{namedAny} should return the class object for the name it is passed.
rp   N)rq   r   r   rg   r   s    r   test_namedAnyClassLookup%LookupsTests.test_namedAnyClassLookup   s     	g&&'IJFSr   c                 l    U R                  [        R                  " S5      [        R                  5        g)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   r   rg   rj   r   s    r   test_namedAnyAttributeLookup)LookupsTests.test_namedAnyAttributeLookup   s*     	IJ	
r   c                     U R                  [        R                  " S5      [        R                  R
                  5        g)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)rq   r   r   rg   rj   r   r   s    r   "test_namedAnySecondAttributeLookup/LookupsTests.test_namedAnySecondAttributeLookup   s.     	TU$$	
r   c                 ,   U R                  [        [        R                  S5        U R                  [        [        R                  S5        U R                  [        [        R                  S5        U R                  [
        [        R                  S5        g)zu
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   r   
ValueErrorImportErrorr   s    r   test_importExceptions"LookupsTests.test_importExceptions   sz    
 	w//1R	
 	w//1R	
 	((*J	

 	))+K	
r   c                     U R                  [        [        R                  S5        U R                  [        [        R                  S5        U R                  [        [        R                  S5        g)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)r   AttributeErrorr   r   r   s    r   test_attributeExceptions%LookupsTests.test_attributeExceptions  s]     	G,,.N	
 	G,,.P	
 	>	
r   c                    U R                  [        R                  [        R                  S5      nU R	                  [        U5      S5        U R                  [        R                  [        R                  S5      nU R	                  [        U5      S5        U R                  [        R                  [        R                  S5      nU R	                  [        U5      S5        U R                  [        R                  [        R                  S5      nU R	                  [        U5      S5        S	 HQ  nU R                  [        R                  [        R                  U5      nU R	                  [        U5      S
U< 35        MS     g)aU  
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)r   r   ModuleNotFoundr   r-   strObjectNotFoundInvalidName)r   errinvalidNames      r   test_invalidNamesLookupsTests.test_invalidNames"  s4    ""G$4$46N
 	S#MN ""G$4$46F
 	S#MN""G$4$46N
 	S#UV 3 3W5E5ErJS#67FK##G$7$79I9I;WCC)47 Gr   c                 t    S H2  n[        5       n[        R                  " XS9nU R                  X25        M4     g)zS
When module import fails with ImportError it returns the specified
default value.
)nosuchmtopoduleno.such.moduledefaultN)objectr   requireModulerq   )r   namer   rd   s       r   test_requireModuleImportError*LookupsTests.test_requireModuleImportErrorG  s1    
 :DhG**4AFMM&* :r   c                 R    [         R                  " S5      nU R                  U5        g)z9
When module import fails it returns L{None} by default.
r   N)r   r   assertIsNone)r   rd   s     r   test_requireModuleDefaultNone*LookupsTests.test_requireModuleDefaultNoneS  s#     &&'78&!r   c                 n    SSK Jn  [        5       nU R                  [        R
                  " SUS9U5        g)zM
When module import succeed it returns the module and not the default
value.
r   rv   rx   r   N)ry   rw   r   rq   r   r   )r   rw   r   s      r   !test_requireModuleRequestedImport.LookupsTests.test_requireModuleRequestedImport[  s.    
 	*(!!"97K	
r   r   N)r   r   r   r   r   rs   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   rm      sN    VLJIT
	

*
*#J
+"
r   rm   c                   8    \ rS rSrSrSrS\4S jrS\4S jrSr	g)	Breakableij  Freturnc                 <    U R                   (       a  [        S5      eg)Nzstr!z<Breakable>)breakStrRuntimeErrorr   s    r   __str__Breakable.__str__n  s    ==v&& r   c                 <    U R                   (       a  [        S5      eg)Nzrepr!zBreakable())	breakReprr   r   s    r   __repr__Breakable.__repr__t  s    >>w'' r   r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   j  s$    IH! !!# !r   r   c                   (    \ rS rSrSr\S 5       r Srg)
BrokenTypei{  Fc                 <    U R                   (       a  [        S5      eg)Nzno namer   )	breakNamer   r   s    r   r   BrokenType.__name__~  s    >>y))r   r   N)r   r   r   r   r   propertyr   r   r   r   r   r   {  s    I r   r   BTBaseT)r   r   c                   &    \ rS rSr\" S 5      rSrg)NoClassAttri  c                     U R                   $ r]   )	not_class)r/   s    r   <lambda>NoClassAttr.<lambda>  s    1;;r   r   N)r   r   r   r   r   	__class__r   r   r   r   r   r     s    ./Ir   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)SafeReprTestsi  z*
Tests for L{reflect.safe_repr} function.
c           	          / SQS4nU R                  [        [        [        R                  U5      5      [        [        [
        U5      5      5        g)zO
L{reflect.safe_repr} produces the same output as C{repr} on a working
object.
rc            aN)r-   listmapr   	safe_reprrepr)r   xss     r   test_workingReprSafeReprTests.test_workingRepr  s;    
 c'"3"3R894D";NOr   c                    [        5       nSUl        [        R                  " U5      nU R	                  SU5        U R	                  [
        R                  R                  [        5      S   U5        U R	                  SU5        g)zj
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_brokenReprSafeReprTests.test_brokenRepr  sd    
 K!!!$0%8 	bgg&&x03U;+U3r   c                     [        5       nSUl        U R                  [        R                  " U5      [        U5      5        g)zD
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_brokenStrSafeReprTests.test_brokenStr  s1     K
**1-tAw7r   c                      " S S[         5      n[        R                  " U5        [        R                  " U" 5       5        g )Nc                       \ rS rSrSrSrg)-SafeReprTests.test_brokenClassRepr.<locals>.Xi  Tr   Nr   r   r   r   r   r   r   r   r   Xr         Ir   r   r   r   r   r   r   s     r   test_brokenClassRepr"SafeReprTests.test_brokenClassRepr  s.    	 	 	!!#r   c                      " S S[         5      n[        R                  " U5      nS[        U5      S S3nU R	                  X2R                  S5      S   5        g)	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S rSrSrSrg)2SafeReprTests.test_brokenReprIncludesID.<locals>.Xi  Tr   Nr   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_brokenReprIncludesID'SafeReprTests.test_brokenReprIncludesID  sQ    	 	 !!!$4RU1I=NOD(9!(<=r   c                      " S S[         5      n[        R                  " U5        [        R                  " U" 5       5        g )Nc                       \ rS rSrSrSrg),SafeReprTests.test_brokenClassStr.<locals>.Xi  Tr   Nr   r   r   r   r   r   r   r   r   r   r        Hr   r   r   r   s     r   test_brokenClassStr!SafeReprTests.test_brokenClassStr  s.    	 	 	!!#r   c                    [        5       nSUl        [        R                  " U5      nU R	                  SU5        U R	                  [
        R                  R                  [        5      S   U5        U R	                  SU5        g)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_brokenClassAttribute'SafeReprTests.test_brokenClassAttribute  sb     M!!!$2E:bgg&&x03U;+U3r   c                     " S S[         5      n[        R                  " U" 5       5      nU R                  SU5        U R                  [        R
                  R                  [        5      S   U5        U R                  SU5        g)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S rSrSrSrg)6SafeReprTests.test_brokenClassNameAttribute.<locals>.Xi  Tr   Nr   r   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_brokenClassNameAttribute+SafeReprTests.test_brokenClassNameAttribute  sb    	 	 !!!#&+U3bgg&&x03U;+U3r   r   N)r   r   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                   T    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)SafeStrTestsi  z)
Tests for L{reflect.safe_str} function.
c                 j    / SQnU R                  [        R                  " U5      [        U5      5        g )Nr   )r-   r   safe_strr   r   r/   s     r   test_workingStrSafeStrTests.test_workingStr  s&    ))!,c!f5r   c                 R    [        5       nSUl        [        R                  " U5        g NT)r   r   r   r  r   s     r   r   SafeStrTests.test_brokenStr  s    K
r   c                 T    SnU R                  [        R                  " U5      S5        g)zP
L{safe_str} for C{str} with ascii-only data should return the
value unchanged.
aN)r-   r   r  r  s     r   test_workingAsciiSafeStrTests.test_workingAscii  s$    
 ))!,c2r   c                 r    SnU R                  [        R                  " U5      UR                  S5      5        g)z_
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_3SafeStrTests.test_workingUtf8_3  s-    
 ))!,ahhw.?@r   c                 j    Sn[         R                  " U5      nU R                  U[        U5      5        g)z-
Use str() for non-utf8 bytes: "b'non-utf8'"
   N)r   r  r-   r   )r   r/   xStrs      r   test_brokenUtf8SafeStrTests.test_brokenUtf8  s-     "s1v&r   c                 R    [        5       nSUl        [        R                  " U5        g r  )r   r   r   r  r   s     r   r   SafeStrTests.test_brokenRepr  s    Kr   c                      " S S[         5      n[        R                  " U5        [        R                  " U" 5       5        g )Nc                       \ rS rSrSrSrg)+SafeStrTests.test_brokenClassStr.<locals>.Xi  Tr   Nr  r   r   r   r   r3    r	  r   r   r   r   r  r   s     r   r
   SafeStrTests.test_brokenClassStr  s.    	 	 	r   c                      " S S[         5      n[        R                  " U5        [        R                  " U" 5       5        g )Nc                       \ rS rSrSrSrg),SafeStrTests.test_brokenClassRepr.<locals>.Xi  Tr   Nr   r   r   r   r   r8    r   r   r   r4  r   s     r   r   !SafeStrTests.test_brokenClassRepr  s.    	 	 	r   c                    [        5       nSUl        [        R                  " U5      nU R	                  SU5        U R	                  [
        R                  R                  [        5      S   U5        U R	                  SU5        g)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  &SafeStrTests.test_brokenClassAttribute"  sb     M
"2D9bgg&&x03T:*D1r   c                     " S S[         5      n[        R                  " U" 5       5      nU R                  SU5        U R                  [        R
                  R                  [        5      S   U5        U R                  SU5        g)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S rSrSrSrg)5SafeStrTests.test_brokenClassNameAttribute.<locals>.Xi6  Tr   Nr  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  *SafeStrTests.test_brokenClassNameAttribute/  sb    	 	 $+T2bgg&&x03T:*D1r   r   N)r   r   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                   0    \ rS rSrSrS rS rS rS rSr	g)	FilenameToModuleTestsi?  z)
Test L{filenameToModuleName} detection.
c                 b   [         R                  R                  U R                  5       SS5      U l        [         R                  " U R                  5        [        [         R                  R                  U R                  S5      S5       nUR                  S5        S S S 5        [        [         R                  R                  [         R                  R                  U R                  5      S5      S5       nUR                  S5        S S S 5        g ! , (       d  f       Nz= f! , (       d  f       g = f)Nfakepackagetestz__init__.pywr   )r   r   joinmktempmakedirsopenwritedirname)r   fs     r   setUpFilenameToModuleTests.setUpD  s    GGLLvF	
DII"'',,tyy-8#>!GGBK ?"'',,rwwtyy9=I3OSTGGBK PO ?>OOs   	D4D 
D 
D.c                    [         R                  " U R                  5      nU R                  US5        [         R                  " U R                  [        R                  R
                  -   5      nU R                  US5        g)zS
L{filenameToModuleName} returns the correct module (a package) given a
directory.
zfakepackage.testN)r   filenameToModuleNamer   r-   r   sepr   modules     r   test_directory$FilenameToModuleTests.test_directoryL  s[    
 --dii8!34--dii"''++.EF!34r   c                     [         R                  " [        R                  R	                  U R                  S5      5      nU R                  US5        g)zP
L{filenameToModuleName} returns the correct module given the path to
its file.
ztest_reflect.pyfakepackage.test.test_reflectN)r   rR  r   r   rH  r-   rT  s     r   	test_fileFilenameToModuleTests.test_fileV  s>    
 --GGLL$56
 	!@Ar   c                     [         R                  " [        R                  R	                  U R                  R                  S5      S5      5      nU R                  US5        g)zW
L{filenameToModuleName} returns the correct module given a C{bytes}
path to its file.
r&  s   test_reflect.pyrY  N)r   rR  r   r   rH  encoder-   rT  s     r   
test_bytes FilenameToModuleTests.test_bytes`  sI    
 --GGLL))'24FG
 	!@Ar   )r   N)
r   r   r   r   r   rO  rV  rZ  r^  r   r   r   r   rC  rC  ?  s    5B	Br   rC  c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)FullyQualifiedNameTestsil  z!
Test for L{fullyQualifiedName}.
c                 :    U R                  [        U5      U5        g)zM
Helper to check that fully qualified name of C{obj} results to
C{expected}.
N)r-   r   )r   objexpecteds      r   _checkFullyQualifiedName0FullyQualifiedNameTests._checkFullyQualifiedNameq  s    
 	+C0(;r   c                 p    SSK nU R                  US5        SSKnU R                  UR                  S5        g)zL
L{fullyQualifiedName} returns the full name of a package and a
subpackage.
r   Nr   r   )r   re  ry   r   r   s     r   test_package$FullyQualifiedNameTests.test_packagex  s/    
 	%%gy9%%gnn6FGr   c                 X    SSK nU R                  UR                  R                  S5        g)zF
L{fullyQualifiedName} returns the name of a module inside a package.
r   Nztwisted.python.compat)twisted.python.compatre  r   compatr   s     r   test_module#FullyQualifiedNameTests.test_module  s"     	%%%gnn&;&;=TUr   c                 >    U R                  [        [         S35        g)zC
L{fullyQualifiedName} returns the name of a class and its module.
z.FullyQualifiedNameTestsN)re  ra  r   r   s    r   
test_class"FullyQualifiedNameTests.test_class  s     	%%#z1I%J	
r   c                 0    U R                  [        S5        g)zI
L{fullyQualifiedName} returns the name of a function inside its module.
z)twisted.python.reflect.fullyQualifiedNameN)re  r   r   s    r   test_function%FullyQualifiedNameTests.test_function  s     	%% K	
r   c                 x    U R                  U R                  [         SU R                  R                   S35        g)z[
L{fullyQualifiedName} returns the name of a bound method inside its
class and its module.
.z.test_boundMethodN)re  test_boundMethodr   r   r   s    r   rw  (FullyQualifiedNameTests.test_boundMethod  s7    
 	%%!!j$..1122CD	
r   c                     U R                  U R                  R                  [         SU R                  R                   S35        g)z^
L{fullyQualifiedName} returns the name of an unbound method inside its
class and its module.
rv  z.test_unboundMethodN)re  r   test_unboundMethodr   r   s    r   rz  *FullyQualifiedNameTests.test_unboundMethod  s;    
 	%%NN--j$..1122EF	
r   r   N)r   r   r   r   r   re  rh  rm  rp  rs  rw  rz  r   r   r   r   ra  ra  l  s,    <
HV



r   ra  c                   J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)ObjectGrepTestsi  c                     [        5       nSU0nUS0nU R                  S[        R                  " X![        R                  5      5        U R                  S[        R                  " X1[        R                  5      5        g)zF
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_dictionaryObjectGrepTests.test_dictionary  sW     HAYYhw~~ FGhw~~ FGr   c                     [        5       nSU/nU R                  S[        R                  " X![        R                  5      5        g)z(
Test references search through a list.
N[1]r  )r   r  Ls      r   	test_listObjectGrepTests.test_list  s1     H1IeW__Q7>>BCr   c                     [        5       nUS4nU R                  S[        R                  " X![        R                  5      5        g)z)
Test references search through a tuple.
N[0]r  )r   r  Ts      r   
test_tupleObjectGrepTests.test_tuple  s1     HIeW__Q7>>BCr   c                      " S S5      n[        5       nU" 5       nX#l        U R                  S[        R                  " X2[        R
                  5      5        g)z5
Test references search through an object attribute.
c                       \ rS rSrSrg),ObjectGrepTests.test_instance.<locals>.Dummyi  r   NrL   r   r   r   Dummyr    rN   r   r  z.oN)r   r  r   r   r  r  )r   r  r  ds       r   test_instanceObjectGrepTests.test_instance  s>    
	 	 HGdGOOA'..ABr   c                      " S S5      nU" 5       n[         R                  " U5      nU R                  S[        R                  " X2[        R
                  5      5        g)z2
Test references search through a weakref object.
c                       \ rS rSrSrg)+ObjectGrepTests.test_weakref.<locals>.Dummyi  r   NrL   r   r   r   r  r    rN   r   r  z()N)weakrefrefr   r   r  r  )r   r  r  w1s       r   test_weakrefObjectGrepTests.test_weakref  s?    
	 	 G[[^dGOOB7>>BCr   c                     " S S5      nU" 5       nUR                   nU R                  S[        R                  " X3R                  [        R
                  5      5        U R                  S[        R                  " X3R                  R                  [        R
                  5      5        U R                  S[        R                  " X3R                  [        R
                  5      5        g)z;
Test references search through method special attributes.
c                       \ rS rSrS rSrg)/ObjectGrepTests.test_boundMethod.<locals>.Dummyi  c                     g r]   r   r   s    r   dummy5ObjectGrepTests.test_boundMethod.<locals>.Dummy.dummy  r`   r   r   N)r   r   r   r   r  r   r   r   r   r  r    ra   r   r  z	.__self__z.__self__.__class__z	.__func__N)r  r   r   r  __self__r  r   __func__)r   r  r  ms       r   rw   ObjectGrepTests.test_boundMethod  s    
	 	 GGGk7??1jj'..#QR!OOAzz33W^^D	
 	k7??1jj'..#QRr   c                 *    " S S5      nU" 5       nSSSSUS0nSSUS/nU0 U" 5       4nS	S
US.nU" 5       nXgl         UR                  n[        R                  " U5      n	U R	                  S[
        R                  " X[
        R                  5      5        g)z6
Test references search using complex set of objects.
c                       \ rS rSrS rSrg).ObjectGrepTests.test_everything.<locals>.Dummyi  c                     g r]   r   r   s    r   r   5ObjectGrepTests.test_everything.<locals>.Dummy.method  r`   r   r   N)r   r   r   r   r   r   r   r   r   r  r    ra   r   r  r   bazNQuuxFooshr   foobar)r   rc   r   z"().__self__.attr[2][0][2]{'Foosh'})attrr   r  r  r   r   r  r  )
r   r  r  D1r  r  D2ir  rG  s
             r   test_everythingObjectGrepTests.test_everything  s    
	 	 G%vq'22r1EG5Q'GHHKKN0'//!2W	
r   c           
      \   / nU/nX/nX/nU R                  S/[        R                  " XA[        R                  SS95        U R                  SS/[        R                  " XA[        R                  SS95        U R                  / SQ[        R                  " XA[        R                  SS95        g)	z&
Test the depth of references search.
r  rc   )maxDepth[1][0]r   )r  r  z	[1][1][0]r   N)r-   r   r  r  )r   r"  r   cr  s        r   test_depthLimitObjectGrepTests.test_depthLimit  s     CFF%'//!QR"STHwqW^^aP	
 	*OOA'..1=	
r   c                     [        5       n[        5       nUR                  S5        UR                  U5        U R                  S[        R
                  " X![        R                  5      5        g)z0
Test references search through a deque object.
Nr  )r   r   appendr   r   r  r  )r   r  Ds      r   
test_dequeObjectGrepTests.test_deque&  sE     HG		eW__Q7>>BCr   r   N)r   r   r   r   r  r  r  r  r  rw  r  r  r  r   r   r   r   r}  r}    s6    	HDDCDS&
.
$	Dr   r}  c                       \ rS rSrS rSrg)GetClassTestsi2  c                      " S S5      nU" 5       nU R                  [        R                  " U5      R                  S5        U R                  [        R                  " U5      R                  S5        g )Nc                       \ rS rSrSrg)(GetClassTests.test_new.<locals>.NewClassi4  r   NrL   r   r   r   NewClassr  4  rN   r   r  type)r-   r   getClassr   )r   r  news      r   test_newGetClassTests.test_new3  sW    	 	 j))(3<<fE))#.77Dr   r   N)r   r   r   r   r  r   r   r   r   r  r  2  s    Er   r  )$r   r   r  collectionsr   ry   r   twisted.python.reflectr   r   r   r   r	   twisted.trial.unittestr
   TestCaser   r   r!   r*   r;   rC   rR   rg   rm   r   r  r   r   r   r   r  rC  ra  r}  r  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   