
    RhR                        d Z ddlZddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
mZmZ dZ ej                  dej                        Z G d d	e
j"                        Zd
 Zd Zd Zd Zd Z G d de      Z e       ZddZej8                  dfdZdej8                  ej<                  fdZdej8                  ej<                  fdZ y)zLoading unittests.    N)fnmatchfnmatchcase   )casesuiteutilTz[_a-z]\w*\.py$c                   ,     e Zd ZdZ fdZ fdZ xZS )_FailedTestNc                 :    || _         t        t        |   |       y N)
_exceptionsuperr
   __init__)selfmethod_name	exception	__class__s      &/usr/lib/python3.12/unittest/loader.pyr   z_FailedTest.__init__   s    #k4)+6    c                 X     | j                   k7  rt        t           |      S  fd}|S )Nc                       j                   r   )r   r   s   r   testFailurez,_FailedTest.__getattr__.<locals>.testFailure    s    //!r   )_testMethodNamer   r
   __getattr__)r   namer   r   s   `  r   r   z_FailedTest.__getattr__   s.    4'''d7==	"r   )__name__
__module____qualname__r   r   r   __classcell__r   s   @r   r
   r
      s    O7 r   r
   c                 d    d| dt        j                         }t        | t        |      ||      S )NzFailed to import test module: 
)	traceback
format_exc_make_failed_testImportError)r   
suiteClassmessages      r   _make_failed_import_testr*   %   s-    i""$&GT;w#7WMMr   c                 L    dt        j                         }t        | |||      S )NzFailed to call load_tests:
)r$   r%   r&   )r   r   r(   r)   s       r   _make_failed_load_testsr,   *   s)    2;2F2F2HJGiW. .r   c                 0    t        | |      } ||f      |fS r   )r
   )
methodnamer   r(   r)   tests        r   r&   r&   /   s     z9-Dtg''r   c                     t        j                  t        |            d        }| |i}t        dt         j                  f|      } | ||       f      S )Nc                      y r    r   s    r   testSkippedz'_make_skipped_test.<locals>.testSkipped4   s    r   ModuleSkipped)r   skipstrtypeTestCase)r.   r   r(   r3   attrs	TestClasss         r   _make_skipped_testr;   3   sS    	YYs9~ %E_t}}&6>Iy,.//r   c                 F    t         j                  j                  |       d   S )Nr   )ospathsplitext)r>   s    r   	_splitextr@   ;   s    77D!!$$r   c                        e Zd ZdZdZ eej                        ZdZ	e
j                  ZdZ fdZd ZdddZddZdd	Zd
 ZddZd Zd Zd Zd Zd Zd Z xZS )
TestLoaderz
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    r/   Nc                 V    t         t        |           g | _        t	               | _        y r   )r   rB   r   errorsset_loading_packages)r   r   s    r   r   zTestLoader.__init__J   s#    j$(* "%r   c                    t        |t        j                        rt        d      |t        j
                  t        j                  fv rg }n"| j                  |      }|st        |d      rdg}| j                  t        ||            }|S )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   r8   FunctionTestCasegetTestCaseNameshasattrr(   map)r   testCaseClasstestCaseNamesloaded_suites       r   loadTestsFromTestCasez TestLoader.loadTestsFromTestCaseQ   s~    mU__5 ( ) ) T]]D,A,ABBM 11-@M W]I%F!*s=-'HIr   patternc                $   g }t        |      D ]}  }t        ||      }t        |t              s t	        |t
        j                        s;|t
        j                  t
        j                  fvs^|j                  | j                  |              t        |dd      }| j                  |      }|	  || ||      S |S # t        $ rK}t        |j                  || j                        \  }}	| j                  j                  |	       |cY d}~S d}~ww xY w)z>Return a suite of all test cases contained in the given module
load_testsN)dirgetattr
isinstancer7   rI   r   r8   rL   appendrS   r(   	Exceptionr,   r   rD   )
r   modulerU   testsr   objrW   e
error_caseerror_messages
             r   loadTestsFromModulezTestLoader.loadTestsFromModulea   s    K 	>D&$'C3%sDMM2t/D/DEET77<=	> V\48
&!"!$w77   ",COOQ-9)
M""=1!!	"s   /	B; ;	DA D
D
Dc           
         |j                  d      }d\  }}|*|dd }|r	 dj                  |      }t        |      }	 |dd }|}	|D ]  }
	 |	t        |	|
      }	} t        |	t        j                         r| j#                  |	      S t        |	t$              rMt'        |	t(        j*                        r3|	t(        j*                  t(        j,                  fvr| j/                  |	      S t        |	t        j0                        rmt        t$              r]t'        |t(        j*                        rC|d   } ||      }t        t        ||      t        j0                        s.| j                  |g      S t        |	t2        j4                        r|	S t7        |	      ra |	       }t        |t2        j4                        r|S t        |t(        j*                        r| j                  |g      S t9        d|	d	|d
      t9        d|	z        # t        $ rM |j	                         }t        || j                        \  }}|s| j                  j                  |       |cY S Y nw xY w|r=!# t        $ r}t        |	dd      &|$| j                  j                  |       |cY d}~c S t        |
|| j                  dt        j                               \  }}| j                  j                  |       |cY d}~c S d}~ww xY w)aS  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'   popr*   r(   rD   r[   rY   AttributeErrorr&   r$   r%   rZ   types
ModuleTyperc   r7   rI   r   r8   rL   rS   FunctionTyper   rJ   callablerK   )r   r   r]   partsra   rb   
parts_copymodule_namenext_attributer_   partparentr`   instr/   s                  r   loadTestsFromNamezTestLoader.loadTestsFromNamey   s    

3$.!
M>qJ*"%((:"6K'4F !"IE 	&D&!73#5	&. c5++,++C00sD!3.DMM4+@+@AA--c22e001&/9D$<DgdD153E3EFv..U__-JC=5D$0D$--0v..!$d!, - - BSHII} # *%/^^%5N0H&19-J%**=9)) &* & " &CT2>". KK&&}5%% 1Ba%002516-J KK&&}5%%%&s=   H  I AII	K4(+K/K4AK/'K4/K4c                 l    |D cg c]  }| j                  ||       }}| j                  |      S c c}w )zReturn a suite of all test cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        )ry   r(   )r   namesr]   r   suitess        r   loadTestsFromNameszTestLoader.loadTestsFromNames   s;     DII4$((v6IIv&& Js   1c                       fd}t        t        |t                          } j                  r/|j	                  t        j                   j                               |S )zLReturn a sorted sequence of method names found within testCaseClass
        c                    | j                  j                        syt        |       }t        |      sydj                  j
                  | fz  j                  d u xs t        fdj                  D              S )NFz%s.%s.%sc              3   6   K   | ]  }t        |        y wr   )r   ).0rU   fullNames     r   	<genexpr>zKTestLoader.getTestCaseNames.<locals>.shouldIncludeMethod.<locals>.<genexpr>   s     XwK'2Xs   )
startswithtestMethodPrefixrY   rq   r   r   testNamePatternsany)attrnametestFuncr   r   rP   s     @r   shouldIncludeMethodz8TestLoader.getTestCaseNames.<locals>.shouldIncludeMethod   s    &&t'<'<=}h7HH%!((-*D*Dh& H ((D0 YX$BWBWXXYr   )key)listfilterrX   sortTestMethodsUsingsort	functools
cmp_to_key)r   rP   r   testFnNamess   ``  r   rM   zTestLoader.getTestCaseNames   sS    
	Y 6"5s=7IJK$$!5!5d6O6O!PQr   c                    d}|| j                   | j                   }n|d}|}t        j                  j                  |      }|t        j                  vr t        j                  j                  d|       || _         d}t        j                  j                  t        j                  j                  |            rct        j                  j                  |      }||k7  rt        j                  j                  t        j                  j                  |d             }n	 t        |       t        j                  |   }|j                  d      d   }	 t        j                  j                  t        j                  j                  |j                              }|r6| j%                  |      | _         t        j                  j'                  |       	 |rt)        d	|z        t+        | j-                  ||            }| j/                  |      S # t        $ r8 |j                  t        j                   v rt#        d      dt#        d|      dw xY w# t(        $ r d}Y w xY w)
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__.pyre   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_dirr=   r>   abspathsysinsertisdirisfilerj   rk   modulesri   dirname__file__rm   r   builtin_module_namesrK    _get_directory_containing_moduleremover'   r   _find_testsr(   )	r   	start_dirrU   top_level_dirset_implicit_topis_not_importable
the_moduletop_partr^   s	            r   discoverzTestLoader.discover   s   8 ! T%8%8%D //M"#%M6(
 HHOOA}-+!77==34	2IM)(*rww||I}7](^$^!39% ![[3
$??3/2( ")<)<>!@I $*.*O*OPX*YD'HHOOM2E	QRRT%%i9:u%%% & (!**c.F.FF' )A BGKL (>znM#'((  )$(!)s    I AH AIIIc                    t         j                  |   }t        j                  j	                  |j
                        }t        j                  j                  |      j                         j                  d      r<t        j                  j                  t        j                  j                  |            S t        j                  j                  |      S )Nr   )
r   r   r=   r>   r   r   basenamelowerr   r   )r   rt   r]   	full_paths       r   r   z+TestLoader._get_directory_containing_module8  s    [)GGOOFOO4	77I&,,.99-H77??277??9#=>>
 77??9--r   c                    || j                   k(  ryt        t        j                  j	                  |            }t        j                  j                  || j                         }t        j                  j                  |      rJ d       |j                  d      rJ d       |j                  t        j                  j                  d      }|S )Nre   zPath must be within the projectz..)
r   r@   r=   r>   normpathrelpathisabsr   replacesep)r   r>   _relpathr   s       r   _get_name_from_pathzTestLoader._get_name_from_pathD  s    4&&&))$/077??4)<)<=77==*M,MM*&&t,O.OO,S1r   c                 >    t        |       t        j                  |   S r   )rk   r   r   )r   r   s     r   _get_module_from_namez TestLoader._get_module_from_nameP  s    4{{4  r   c                     t        ||      S r   )r   )r   r>   r   rU   s       r   _match_pathzTestLoader._match_pathT  s    tW%%r   c              #   ^  K   | j                  |      }|dk7  r,|| j                  vr| j                  ||      \  }}|| |syt        t	        j
                  |            }|D ]  }t        j                  j                  ||      }| j                  ||      \  }}|| |sA| j                  |      }| j                  j                  |       	 | j                  ||      E d{    | j                  j                  |        y7 "# | j                  j                  |       w xY ww)z/Used by discovery. Yields test suites it loads.re   N)r   rF   _find_test_pathsortedr=   listdirr>   rj   addr   discard)	r   r   rU   r   r^   should_recursepathsr>   r   s	            r   r   zTestLoader._find_testsX  s#     ''	2 3;4t'='== %)$8$8G$L!E> ! rzz),- 	9DY5I$($8$8G$L!E> //	:&&**409#//	7CCC**2248	9 D**2248s6   B#D-&,D-D(D)D-D-DD**D-c                 z   t         j                  j                  |      }t         j                  j                  |      rvt        j                  |      sy| j                  |||      sy| j                  |      }	 | j                  |      }t         j                  j                  t        |d|            }t        t         j                  j                  |            }t        t         j                  j                  |            }|j                         |j                         k7  ryt         j                  j                  |      }	t        t         j                  j                  |            }
t         j                  j                  |      }d}t        ||
|	|fz        | j!                  ||      dfS t         j                  j1                  |      rt         j                  j                  t         j                  j3                  |d            syd}d}| j                  |      }	 | j                  |      }t        |dd      }| j4                  j7                  |       	 | j!                  ||      }||df| j4                  j9                  |       S |d	f| j4                  j9                  |       S y# t"        j$                  $ r#}t'        ||| j(                        dfcY d}~S d}~w t+        || j(                        \  }}| j,                  j/                  |       |dfcY S xY w# | j4                  j9                  |       w xY w# t"        j$                  $ r#}t'        ||| j(                        dfcY d}~S d}~w t+        || j(                        \  }}| j,                  j/                  |       |dfcY S xY w)
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?rT   FNr   rW   T)r=   r>   r   r   VALID_MODULE_NAMEmatchr   r   r   r   rY   r@   realpathr   r   r'   rc   r   SkipTestr;   r(   r*   rD   r[   r   rj   rF   r   r   )r   r   rU   r   r   r]   mod_filer   fullpath_noext
module_dirmod_nameexpected_dirmsgr`   ra   rb   rW   r^   packages                      r   r   zTestLoader._find_test_pathx  s%    77##I.77>>)$$**84"##HiA"++I6DP33D9 77??FJ	:<$GG$$X.0!*GG$$Y/"1>>#~';';'==!#!:J(((3 5H#%77??9#=LDC%x\BBD D///H%OOWW]]9%77>>"'',,y-"H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),T4??C *
M""=1!5((Z **2248% == K)$4??CUJJ),T4??C *
M""=1!5((sN   <J7 )M
 #L* L* 7L'
K("L'(=L'*M
N:M;5N:;=N:r   )ztest*.pyN)r   r   r   __doc__r   staticmethodr   three_way_cmpr   r   r   rJ   r(   r   r   rS   rc   ry   r}   rM   r   r   r   r   r   r   r   r    r!   s   @r   rB   rB   ?   s     '(:(:;JN'  6: 0PJd'&Q&f
.
!&9@Hr   rB   c                 V    t               }||_        | |_        ||_        |r||_        |S r   )rB   r   r   r   r(   )prefix	sortUsingr(   r   loaders        r   _makeLoaderr     s1    \F"+F$F.F&Mr   c                 t    dd l }|j                  dt        d       t        |||      j	                  |       S )Nr   zunittest.getTestCaseNames() is deprecated and will be removed in Python 3.13. Please use unittest.TestLoader.getTestCaseNames() instead.   
stacklevel)r   )warningswarnDeprecationWarningr   rM   )rP   r   r   r   r   s        r   rM   rM     s?    MM	Eq  
 vy;KL]]^kllr   r/   c                 r    dd l }|j                  dt        d       t        |||      j	                  |       S )Nr   zunittest.makeSuite() is deprecated and will be removed in Python 3.13. Please use unittest.TestLoader.loadTestsFromTestCase() instead.r   r   )r   r   r   r   rS   )rP   r   r   r(   r   s        r   	makeSuiter     sB    MM	Jq  
 vy*5KK r   c                 r    dd l }|j                  dt        d       t        |||      j	                  |       S )Nr   zunittest.findTestCases() is deprecated and will be removed in Python 3.13. Please use unittest.TestLoader.loadTestsFromModule() instead.r   r   )r   r   r   r   rc   )r]   r   r   r(   r   s        r   findTestCasesr     sB    MM	Hq  
 vy*5II r   rf   )!r   r=   rer   r$   rn   r   r   r    r   r   r   
__unittestcompile
IGNORECASEr   r8   r
   r*   r,   r&   r;   r@   objectrB   defaultTestLoaderr   r   rM   rJ   r   r   r2   r   r   <module>r      s     	 	 
    (  

 BJJ0"--@ $-- N
.
(0%A AH L  7;6H6H[_ m %+d6H6H	 "(43E3E"__	r   