
    F\hK                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	J
r
JrJr  Sr\R                  " S\R                  5      r " S S	\
R"                  5      rS
 rS rS rS rS r " S S\5      r\" 5       rg)zLoading unittests.    N)fnmatchfnmatchcase   )casesuiteutilTz[_a-z]\w*\.py$c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )_FailedTest   Nc                 8   > X l         [        [        U ]  U5        g N)
_exceptionsuperr
   __init__)selfmethod_name	exception	__class__s      &/usr/lib/python3.13/unittest/loader.pyr   _FailedTest.__init__   s    #k4)+6    c                 \   >^  UT R                   :w  a  [        [        T ]  U5      $ U 4S jnU$ )Nc                     > T R                   er   r   r   s   r   testFailure,_FailedTest.__getattr__.<locals>.testFailure    s    //!r   )_testMethodNamer   r
   __getattr__)r   namer   r   s   `  r   r   _FailedTest.__getattr__   s.    4'''d7==	"r   r   )	__name__
__module____qualname____firstlineno__r   r   r   __static_attributes____classcell__r   s   @r   r
   r
      s    O7 r   r
   c                 h    SU < S[         R                  " 5       < 3n[        U [        U5      X5      $ )NzFailed to import test module: 
)	traceback
format_exc_make_failed_testImportError)r    
suiteClassmessages      r   _make_failed_import_testr1   %   s+    i""$&GT;w#7MMr   c                 L    S[         R                  " 5       < 3n[        XX#5      $ )NzFailed to call load_tests:
)r+   r,   r-   )r    r   r/   r0   s       r   _make_failed_load_testsr3   *   s%    2;2F2F2HJG. .r   c                 .    [        X5      nU" U45      U4$ r   )r
   )
methodnamer   r/   r0   tests        r   r-   r-   /   s    z-Dtg''r   c                     [         R                  " [        U5      5      S 5       nX0n[        S[         R                  4U5      nU" U" U 5      45      $ )Nc                     g r    r   s    r   testSkipped'_make_skipped_test.<locals>.testSkipped4   s    r   ModuleSkipped)r   skipstrtypeTestCase)r5   r   r/   r:   attrs	TestClasss         r   _make_skipped_testrC   3   sQ    	YYs9~ %E_t}}&6>Iy,.//r   c                 F    [         R                  R                  U 5      S   $ )Nr   )ospathsplitext)rF   s    r   	_splitextrH   ;   s    77D!!$$r   c                      ^  \ rS rSrSrSr\" \R                  5      r	Sr
\R                  rSrU 4S jrS rSS.S jrSS	 jrSS
 jrS rSS jrS rS rS rS rS rS rSrU =r$ )
TestLoader?   zu
This class is responsible for loading tests according to various criteria
and returning them wrapped in a TestSuite
r6   Nc                 V   > [         [        U ]  5         / U l        [	        5       U l        g r   )r   rJ   r   errorsset_loading_packages)r   r   s    r   r   TestLoader.__init__J   s#    j$(* "%r   c                 4   [        U[        R                  5      (       a  [        S5      eU[        R
                  [        R                  4;   a  / nO,U R                  U5      nU(       d  [        US5      (       a  S/nU R                  [        X5      5      nU$ )z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?runTest)
issubclassr   	TestSuite	TypeErrorr   r@   FunctionTestCasegetTestCaseNameshasattrr/   map)r   testCaseClasstestCaseNamesloaded_suites       r   loadTestsFromTestCase TestLoader.loadTestsFromTestCaseQ   s    mU__55 ( ) ) T]]D,A,ABBM 11-@M W]I%F%F!*s='HIr   patternc                B   / n[        U5       H  n[        X5      n[        U[        5      (       d  M%  [	        U[
        R                  5      (       d  MF  U[
        R                  [
        R                  4;  d  Ml  UR                  U R                  U5      5        M     [        USS5      nU R                  U5      nUb
   U" XU5      $ U$ ! [         aI  n[        UR                  XpR                  5      u  pU R                  R                  U	5        Us SnA$ SnAff = f)z>Return a suite of all test cases contained in the given module
load_testsN)dirgetattr
isinstancer?   rS   r   r@   rV   appendr]   r/   	Exceptionr3   r"   rM   )
r   moduler`   testsr    objrb   e
error_caseerror_messages
             r   loadTestsFromModuleTestLoader.loadTestsFromModulea   s    KD&'C3%%sDMM22t/D/DEET77<=   V\48
&!"!$w77   ",COOQ-9)
""=1!!	"s    C 
D>DDDc           
         UR                  S5      nSu  pEUc/  USS nU(       a   SR                  U5      n[        U5      n USS nUn	U H  n
 U	[        X5      pM     [        U	[        R                   5      (       a  U R#                  U	5      $ [        U	[$        5      (       aT  ['        U	[(        R*                  5      (       a5  U	[(        R*                  [(        R,                  4;  a  U R/                  U	5      $ [        U	[        R0                  5      (       a|  [        W[$        5      (       ag  ['        U[(        R*                  5      (       aH  US   nU" U5      n[        [        X5      [        R0                  5      (       d  U R                  U/5      $ O![        U	[2        R4                  5      (       a  U	$ [7        U	5      (       am  U	" 5       n[        U[2        R4                  5      (       a  U$ [        U[(        R*                  5      (       a  U R                  U/5      $ [9        SU	< S	U< S
35      e[9        SU	-  5      e! [         aP    UR	                  5       n[        XR                  5      u  pEU(       d  U R                  R                  U5        Us $  Of = fU(       a  GM  GNf! [         a  n[        U	SS5      b'  Ub$  U R                  R                  U5        Us SnAs  $ [        XU R                  S[        R                  " 5       < 35      u  pEU R                  R                  U5        Us SnAs  $ SnAff = f)a+  Return a suite of all test cases given a string specifier.

The name may resolve either to a module, a test case class, a
test method within a test case class, or a callable object which
returns a TestCase or TestSuite instance.

The method optionally resolves the names relative to a given module.
.)NNNr   __path__zFailed to access attribute:
zcalling z
 returned z, not a testz$don't know how to make test from: %s)splitjoin
__import__r.   popr1   r/   rM   rf   rd   AttributeErrorr-   r+   r,   re   types
ModuleTypern   r?   rS   r   r@   rV   r]   FunctionTyper   rT   callablerU   )r   r    rh   partsrl   rm   
parts_copymodule_namenext_attributerj   partparentrk   instr6   s                  r   loadTestsFromNameTestLoader.loadTestsFromNamey   s    

3$.!
>qJ*"%((:"6K'4F !"IED&!73#5 . c5++,,++C00sD!!3..DMM4+@+@AA--c22e0011&&//9D$<Dgd153E3EFFv.. GU__--JC==5D$00D$--00v..!$d!, - - BSHII} # *%/^^%5N0H&19-J%**=9)) &* *& " &CT2>". KK&&}5%% 1B%002516-J KK&&}5%%%&s=   I  J) AJJ)
M3-L< M(AL<4M<Mc                 n    U Vs/ s H  o0R                  X25      PM     nnU R                  U5      $ s  snf )zqReturn a suite of all test cases found using the given sequence
of string specifiers. See 'loadTestsFromName()'.
)r   r/   )r   namesrh   r    suitess        r   loadTestsFromNamesTestLoader.loadTestsFromNames   s8     DII54((65Iv&& Js   2c                    ^ ^ U U4S jn[        [        U[        T5      5      5      nT R                  (       a-  UR	                  [
        R                  " T R                  5      S9  U$ )zLReturn a sorted sequence of method names found within testCaseClass
        c                 "  >^ U R                  TR                  5      (       d  g[        TU 5      n[        U5      (       d  gSTR                  TR
                  U 4-  mTR                  S L =(       d    [        U4S jTR                   5       5      $ )NFz%s.%s.%sc              3   <   >#    U  H  n[        TU5      v   M     g 7fr   )r   ).0r`   fullNames     r   	<genexpr>KTestLoader.getTestCaseNames.<locals>.shouldIncludeMethod.<locals>.<genexpr>   s     XBWwK'22BWs   )
startswithtestMethodPrefixrd   r|   r#   r$   testNamePatternsany)attrnametestFuncr   r   rZ   s     @r   shouldIncludeMethod8TestLoader.getTestCaseNames.<locals>.shouldIncludeMethod   s    &&t'<'<==}h7HH%%!((-*D*Dh& H ((D0 YX$BWBWXXYr   )key)listfilterrc   sortTestMethodsUsingsort	functools
cmp_to_key)r   rZ   r   testFnNamess   ``  r   rW   TestLoader.getTestCaseNames   sS    
	Y 6"5s=7IJK$$!5!5d6O6O!PQr   c                    U R                   nSnUc  U R                   b  U R                   nOUc  SnUn[        R                  R                  U5      nU[        R                  ;  a   [        R                  R                  SU5        X0l         Sn[        R                  R                  [        R                  R                  U5      5      (       ag  [        R                  R                  U5      nX:w  aB  [        R                  R                  [        R                  R                  US5      5      (       + nO [        U5        [        R                  U   nUR                  S5      S   n [        R                  R                  [        R                  R                  UR                  5      5      nU(       a5  U R%                  U5      U l         [        R                  R'                  U5        U(       a  [)        S	U-  5      e[+        U R-                  X5      5      n	X@l         U R/                  U	5      $ ! [         a;    UR                  [        R                   ;   a  [#        S5      Se[#        SU< 35      Sef = f! [(         a    Sn Nf = f)
a}  Find and return all test modules from the specified start
directory, recursing into subdirectories to find them and return all
tests found within them. Only test files that match the pattern will
be loaded. (Using shell style pattern matching.)

All test modules must be importable from the top level of the project.
If the start directory is not the top level directory then the top
level directory must be specified separately.

If a test package name (directory with '__init__.py') matches the
pattern then the package will be checked for a 'load_tests' function. If
this exists then it will be called with (loader, tests, pattern) unless
the package has already had load_tests called from the same discovery
invocation, in which case the package module object is not scanned for
tests - this ensures that when a package uses discover to further
discover child tests that infinite recursion does not happen.

If load_tests exists then discovery does *not* recurse into the package,
load_tests is responsible for loading all tests in the package.

The pattern is deliberately not stored as a loader attribute so that
packages can continue discovery themselves. top_level_dir is stored so
load_tests does not need to pass this argument in to loader.discover().

Paths are sorted before being imported to ensure reproducible execution
order even on filesystems with non-alphabetical ordering like ext3/4.
FNTr   __init__.pyrq   z2Can not use builtin modules as dotted module namesz don't know how to discover from z%Start directory is not importable: %r)_top_level_dirrE   rF   abspathsysinsertisdirisfileru   rv   modulesrt   dirname__file__rx   r"   builtin_module_namesrU    _get_directory_containing_moduleremover.   r   _find_testsr/   )
r   	start_dirr`   top_level_diroriginal_top_level_dirset_implicit_topis_not_importable
the_moduletop_partri   s
             r   discoverTestLoader.discover   s   8 "&!4!4  T%8%8%D //M"#%M6(
 HHOOA}-+!77==344	2I)(*rww||I}7](^$^!39% ![[3
$??3/2( ")<)<>!@I $*.*O*OPX*YD'HHOOM2E	QRRT%%i9:4u%%' & (!**c.F.FF' )A BGKL (>znM#'((  )$(!)s    7I: *AH2 2AI7:J	J	c                    [         R                  U   n[        R                  R	                  UR
                  5      n[        R                  R                  U5      R                  5       R                  S5      (       a<  [        R                  R                  [        R                  R                  U5      5      $ [        R                  R                  U5      $ )Nr   )
r   r   rE   rF   r   r   basenamelowerr   r   )r   r   rh   	full_paths       r   r   +TestLoader._get_directory_containing_module:  s    [)GGOOFOO4	77I&,,.99-HH77??277??9#=>>
 77??9--r   c                    XR                   :X  a  g[        [        R                  R	                  U5      5      n[        R                  R                  XR                   5      n[        R                  R                  U5      (       a   S5       eUR                  S5      (       a   S5       eUR                  [        R                  R                  S5      nU$ )Nrq   zPath must be within the projectz..)
r   rH   rE   rF   normpathrelpathisabsr   replacesep)r   rF   _relpathr    s       r   _get_name_from_pathTestLoader._get_name_from_pathF  s    &&&))$/077??4)<)<=77==**M,MM*&&t,,O.OO,S1r   c                 >    [        U5        [        R                  U   $ r   )rv   r   r   )r   r    s     r   _get_module_from_name TestLoader._get_module_from_nameR  s    4{{4  r   c                     [        X5      $ r   )r   )r   rF   r   r`   s       r   _match_pathTestLoader._match_pathV  s    t%%r   c              #   v  #    U R                  U5      nUS:w  a1  X0R                  ;  a"  U R                  X5      u  pEUb  Uv   U(       d  g[        [        R
                  " U5      5      nU H  n[        R                  R                  X5      nU R                  X5      u  pEUb  Uv   U(       d  ME  U R                  U5      nU R                  R                  U5         U R                  X5       Sh  vN   U R                  R                  U5        M     g N$! U R                  R                  U5        f = f7f)z/Used by discovery. Yields test suites it loads.rq   N)r   rO   _find_test_pathsortedrE   listdirrF   ru   addr   discard)	r   r   r`   r    ri   should_recursepathsrF   r   s	            r   r   TestLoader._find_testsZ  s     ''	2 3;4'='== %)$8$8$L!E ! rzz),-DY5I$($8$8$L!E ~//	:&&**409#//	CCC**2248  D**2248s6   B+D91,D9D2D3D7 D9DD66D9c                    [         R                  R                  U5      n[         R                  R                  U5      (       Gaz  [        R                  U5      (       d  gU R                  X1U5      (       d  gU R                  U5      n U R                  U5      n[         R                  R                  [        USU5      5      n[        [         R                  R                  U5      5      n[        [         R                  R                  U5      5      nUR                  5       UR                  5       :w  aw  [         R                  R                  U5      n	[        [         R                  R                  U5      5      n
[         R                  R                  U5      nSn[        XX4-  5      eU R!                  XRS9S4$ [         R                  R1                  U5      (       a  [         R                  R                  [         R                  R3                  US5      5      (       d  gSnSnU R                  U5      n U R                  U5      n[        USS5      nU R4                  R7                  U5         U R!                  UUS9nUb  US4U R4                  R9                  U5        $ US	4U R4                  R9                  U5        $ g! ["        R$                   a"  n['        XMU R(                  5      S4s SnA$ SnAf  [+        X@R(                  5      u  pU R,                  R/                  U5        US4s $ = f! U R4                  R9                  U5        f = f! ["        R$                   a"  n['        XMU R(                  5      S4s SnA$ SnAf  [+        X@R(                  5      u  pU R,                  R/                  U5        US4s $ = f)
zUsed by discovery.

Loads tests from a single file, or a directories' __init__.py when
passed the directory.

Returns a tuple (None_or_tests_from_file, should_recurse).
)NFr   zW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r_   FNr   rb   T)rE   rF   r   r   VALID_MODULE_NAMEmatchr   r   r   r   rd   rH   realpathr   r   r.   rn   r   SkipTestrC   r/   r1   rM   rf   r   ru   rO   r   r   )r   r   r`   r   r    rh   mod_filer   fullpath_noext
module_dirmod_nameexpected_dirmsgrk   rl   rm   rb   ri   packages                      r   r   TestLoader._find_test_pathz  s     77##I.77>>)$$$**844"##HAA"++I6DP33D9 77??FJ	:<$GG$$X.0!*GG$$Y/"1>>#~';';'==!#!:J(((3 5H#%77??9#=LDC%BBD D///H%OOWW]]9%%77>>"'',,y-"HII"JE++I6D944T: %WlDA
&&**409 44Wg4NE!-$e| **2248 !$;**2248k == K)$4??CUJJ),T??C *
""=1!5((Z **2248% == K)$4??CUJJ),T??C *
""=1!5((sN   
K <M 6L9 (L9 L6K93L69;L69MO-N
O
;O)rO   r   rM   r   )ztest*.pyN)r"   r#   r$   r%   __doc__r   staticmethodr   three_way_cmpr   r   r   rT   r/   r   r   r]   rn   r   r   rW   r   r   r   r   r   r   r   r&   r'   r(   s   @r   rJ   rJ   ?   s     '(:(:;JN'  6: 0PJd'&S&j
.
!&9@H Hr   rJ   )r   rE   rer   r+   ry   r   r   r    r   r   r   
__unittestcompile
IGNORECASEr   r@   r
   r1   r3   r-   rC   rH   objectrJ   defaultTestLoaderr9   r   r   <module>r      s     	 	 
    (  

 JJ0"--@ $-- N
.
(0%C CL L r   