
    h                        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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rS SKJr  S SKJr  S SKJr  S SKJ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  S S	KJrJ r J!r!  S S
KJ"r#  S SKJ$r$  S SKJ%r&  S SKJ'r'  S SK(J)r)  S SK*J+r+   S SK,r- S SK/r0 " S S\Rb                  5      r2 " S S\Rb                  5      r3 " S S5      r4 " S S\Rj                  5      r6 " S S5      r7S r8S r9S q:      S.S jr;S r<S r= " S S \R|                  5      r? " S! S"5      r@ " S# S$5      rAS% rBS& rCS' rDS( rES/S) jrFS0S* jrGS+ rHS, rIS- rJg! \. a    S SK-r- Nf = f! \. a    Sr0 Nf = f)1    N)defaultdict)contextmanager)import_module)StringIO)call_command)connections)SimpleTestCaseTestCase)NullTimeKeeper
TimeKeeperiter_test_cases)setup_databases)setup_test_environment)teardown_databases)teardown_test_environment)
OrderedSet)PY312c                   j   ^  \ rS rSrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jr	S r
S	rU =r$ )
DebugSQLTextTestResult-   c                    > [         R                  " S5      U l        U R                  R                  [         R                  5        S U l        [        TU ]  XU5        g )Nzdjango.db.backends)logging	getLoggerloggersetLevelDEBUGdebug_sql_streamsuper__init__)selfstreamdescriptions	verbosity	__class__s       D/var/www/html/env/lib/python3.13/site-packages/django/test/runner.pyr   DebugSQLTextTestResult.__init__.   sC    ''(<=W]]+ $y9    c                    > [        5       U l        [        R                  " U R                  5      U l        U R
                  R                  U R                  5        [        TU ]!  U5        g N)	r   r   r   StreamHandlerhandlerr   
addHandlerr   	startTestr    testr$   s     r%   r-    DebugSQLTextTestResult.startTest4   sH     (
,,T-B-BCt||,$r'   c                 x  > [         TU ]  U5        U R                  R                  U R                  5        U R
                  (       at  U R                  R                  S5        U R                  R                  U R                  R                  5       5        U R                  R                  U R                  5        g g )Nr   )r   stopTestr   removeHandlerr+   showAllr   seekr!   writereadwriteln
separator2r.   s     r%   r2   DebugSQLTextTestResult.stopTest:   s}    !!$,,/<<!!&&q)KKd3388:;KK0 r'   c                    > [         TU ]  X5        U R                  c  SnO5U R                  R                  S5        U R                  R	                  5       nU R
                  S   U4-   U R
                  S'   g )N r   )r   addErrorr   r5   r7   errors)r    r/   errsqlr$   s       r%   r>   DebugSQLTextTestResult.addErrorB   se    #  (C!!&&q)'',,.C++b/SF2Br'   c                    > [         TU ]  X5        U R                  R                  S5        U R                  S   U R                  R                  5       4-   U R                  S'   g Nr   r=   )r   
addFailurer   r5   failuresr7   r    r/   r@   r$   s      r%   rE   !DebugSQLTextTestResult.addFailureL   sR    4%""1% MM"-1F1F1K1K1M0OObr'   c                   > [         TU ]  XU5        Ubv  U R                  R                  S5        [	        US   UR
                  5      (       a  U R                  OU R                  nUS   U R                  R                  5       4-   US'   g g rD   )	r   
addSubTestr   r5   
issubclassfailureExceptionrF   r?   r7   )r    r/   subtestr@   r?   r$   s        r%   rJ   !DebugSQLTextTestResult.addSubTestQ   s    4#.?!!&&q) c!fd&;&;<< [[ 
  t'<'<'A'A'C&EEF2J r'   c           	         U H  u  p4nU R                   R                  U R                  5        U R                   R                  U< SU R                  U5      < 35        U R                   R                  U R                  5        U R                   R                  U5        U R                   R                  U R                  5        U R                   R                  [
        R                  " USSS95        M     g )Nz: Tupper)reindentkeyword_case)r!   r8   
separator1getDescriptionr9   sqlparseformat)r    flavourr?   r/   r@   	sql_debugs         r%   printErrorList%DebugSQLTextTestResult.printErrorList\   s    $* DyKK0KKGT5H5H5N OPKK0KK$KK0KK	DwO %+r'   )r   r+   r   )__name__
__module____qualname____firstlineno__r   r-   r2   r>   rE   rJ   rY   __static_attributes____classcell__r$   s   @r%   r   r   -   s-    : 13P
	F	 	r'   r   c                   J   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrS rSr	U =r
$ )PDBDebugResulth   zR
Custom result class that triggers a PDB session when an error or failure
occurs.
c                 F   > [         TU ]  X5        U R                  U5        g r)   )r   r>   debugrG   s      r%   r>   PDBDebugResult.addErrorn   s    #

3r'   c                 F   > [         TU ]  X5        U R                  U5        g r)   )r   rE   rf   rG   s      r%   rE   PDBDebugResult.addFailurer   s    4%

3r'   c                 N   > Ub  U R                  U5        [        TU ]	  XU5        g r)   )rf   r   rJ   r    r/   rM   r@   r$   s       r%   rJ   PDBDebugResult.addSubTestv   s"    ?JJsO4#.r'   c                     U R                  5         SU l        Uu  p#n[        SU-  5        [        R                  " U5        g )NFz
Opening PDB: %r)_restoreStdoutbufferprintpdbpost_mortem)r    errorexc_type	exc_value	tracebacks        r%   rf   PDBDebugResult.debug{   s9    ).&Y!I-.	"r'   )ro   )r[   r\   r]   r^   __doc__r>   rE   rJ   rf   r_   r`   ra   s   @r%   rc   rc   h   s!    
/
# #r'   rc   c                   "    \ rS rSrSrSrS rSrg)	DummyList   zH
Dummy list class for faking storage of results in unittest.TestResult.
 c                     g r)   r|   )r    items     r%   appendDummyList.append   s    r'   N)r[   r\   r]   r^   rx   	__slots__r   r_   r|   r'   r%   rz   rz      s     Ir'   rz   c                      ^  \ rS rSrSrU 4S jrS r\S 5       rS r	S r
S rS	 rU 4S
 jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrS rS rSrU =r$ )RemoteTestResult   z
Extend unittest.TestResult to record events in the child processes so they
can be replayed in the parent process. Events include things like which
tests succeeded or failed.
c                    > [         TU ]  " U0 UD6  [        5       nX0l        X0l        X0l        X0l        X0l        [        b  [        R                  R                  5         / U l        g r)   )r   r   rz   rF   r?   skippedexpectedFailuresunexpectedSuccessestblibpickling_supportinstallevents)r    argskwargs
dummy_listr$   s       r%   r   RemoteTestResult.__init__   sX    $)&) [
" ! *#- ""**,r'   c                     U R                   R                  5       nUR                  SS 5        UR                  SS 5        UR                  SS 5        UR                  SS 5        U$ )N_stdout_buffer_stderr_buffer_original_stdout_original_stderr)__dict__copypop)r    states     r%   __getstate__RemoteTestResult.__getstate__   sW     ""$		"D)		"D)		$d+		$d+r'   c                      U R                   S-
  $ )N   )testsRunr    s    r%   
test_indexRemoteTestResult.test_index   s    }}q  r'   c                 X    [         R                  " [         R                  " U5      5        g)z
Confirm that obj can be pickled and unpickled as multiprocessing will
need to pickle the exception in the child process and unpickle it in
the parent process. Let the exception rise, if not.
N)pickleloadsdumps)r    objs     r%   _confirm_picklable#RemoteTestResult._confirm_picklable   s     	V\\#&'r'   c                 :    [        SR                  XU5      5        g )Na'  
Subtest failed:

    test: {}
 subtest: {}

Unfortunately, the subtest that failed cannot be pickled, so the parallel
test runner cannot handle it cleanly. Here is the pickling error:

> {}

You should re-run this test with --parallel=1 to reproduce the failure
with a cleaner failure message.
)rp   rV   )r    r/   rM   
pickle_excs       r%   _print_unpicklable_subtest+RemoteTestResult._print_unpicklable_subtest   s      Fz	
r'   c                 V    U R                  U5        g ! [         a  n[        US   5      n[        R                  " USSSS9n[        U5      n[        R                  " USSSS9n[
        c  [        SR                  X5      5        e [        SR                  XU5      5        e S nAff = f)Nr   K   z    )initial_indentsubsequent_indentz

{} failed:

{}

Unfortunately, tracebacks cannot be pickled, making it impossible for the
parallel test runner to handle this exception cleanly.

In order to see the traceback, you should install tblib:

    python -m pip install tblib
aL  

{} failed:

{}

Unfortunately, the exception it raised cannot be pickled, making it impossible
for the parallel test runner to handle it cleanly.

Here's the error encountered while trying to pickle the exception:

{}

You should re-run this test with the --parallel=1 option to reproduce the
failure and get a correct traceback.
)r   	Exceptionreprtextwrapfillr   rp   rV   )r    r/   r@   excoriginal_exc_txtpickle_exc_txts         r%   check_picklable RemoteTestResult.check_picklable   s    2	##C( 0	#CF|'}} "Vv  "#YN%]]6VN } FL )  F!( a0	s    
B(BB##B(c                 r     U R                  U5        g ! [         a  nU R                  XU5        e S nAff = fr)   )r   r   r   )r    r/   rM   r   s       r%   check_subtest_picklable(RemoteTestResult.check_subtest_picklable
  s8    	##G, 	++D3?	s    
616c                 X   > [         TU ]  5         U R                  R                  S5        g )N)startTestRun)r   r   r   r   r    r$   s    r%   r   RemoteTestResult.startTestRun  s!    ,-r'   c                 X   > [         TU ]  5         U R                  R                  S5        g )N)stopTestRun)r   r   r   r   r   s    r%   r   RemoteTestResult.stopTestRun  s!    +,r'   c                 r   > [         TU ]  U5        U R                  R                  SU R                  45        g )Nr-   )r   r-   r   r   r   r.   s     r%   r-   RemoteTestResult.startTest  s+    $K9:r'   c                 r   > [         TU ]  U5        U R                  R                  SU R                  45        g )Nr2   )r   r2   r   r   r   r.   s     r%   r2   RemoteTestResult.stopTest  s+    J89r'   c                 t   > [         TU ]  X5        U R                  R                  SU R                  U45        g )NaddDuration)r   r   r   r   r   )r    r/   elapsedr$   s      r%   r   RemoteTestResult.addDuration!  s-    D*M4??GDEr'   c                    > U R                  X5        U R                  R                  SU R                  U45        [        TU ]  X5        g )Nr>   )r   r   r   r   r   r>   rG   s      r%   r>   RemoteTestResult.addError%  s;    T'J=>#r'   c                    > U R                  X5        U R                  R                  SU R                  U45        [        TU ]  X5        g )NrE   )r   r   r   r   r   rE   rG   s      r%   rE   RemoteTestResult.addFailure*  s;    T'L$//3?@4%r'   c                    > UbJ  U R                  X5        U R                  X5        U R                  R                  SU R                  X#45        [
        TU ]  XU5        g )NrJ   )r   r   r   r   r   r   rJ   rk   s       r%   rJ   RemoteTestResult.addSubTest/  sT     ?   +((7KKdoowLM4#.r'   c                 r   > U R                   R                  SU R                  45        [        TU ]  U5        g )N
addSuccess)r   r   r   r   r   r.   s     r%   r   RemoteTestResult.addSuccess:  s+    L$//:;4 r'   c                 t   > U R                   R                  SU R                  U45        [        TU ]  X5        g )NaddSkip)r   r   r   r   r   )r    r/   reasonr$   s      r%   r   RemoteTestResult.addSkip>  s,    It?@%r'   c                    > [         c  US   US   S 4nU R                  X5        U R                  R                  SU R                  U45        [
        TU ]  X5        g )Nr   r   addExpectedFailure)r   r   r   r   r   r   r   rG   s      r%   r   #RemoteTestResult.addExpectedFailureB  sW    
 =a&#a&$&CT'0$//3GH"4-r'   c                 r   > U R                   R                  SU R                  45        [        TU ]  U5        g )NaddUnexpectedSuccess)r   r   r   r   r   r.   s     r%   r   %RemoteTestResult.addUnexpectedSuccessM  s,    2DOODE$T*r'   c                 J   ^ 1 Skm[        U4S jU R                   5       5      $ )z/Tells whether or not this result was a success.>   r>   rE   rJ   r   c              3   2   >#    U  H  oS    T;  v   M     g7f)r   Nr|   ).0efailure_typess     r%   	<genexpr>1RemoteTestResult.wasSuccessful.<locals>.<genexpr>T  s     BkQ4},ks   )allr   )r    r   s    @r%   wasSuccessfulRemoteTestResult.wasSuccessfulQ  s    XBdkkBBBr'   c                     g)Nr<   r|   )r    r@   r/   s      r%   _exc_info_to_string$RemoteTestResult._exc_info_to_stringV  s     r'   )r?   r   r   rF   r   r   )r[   r\   r]   r^   rx   r   r   propertyr   r   r   r   r   r   r   r-   r2   r   r>   rE   rJ   r   r   r   r   r   r   r_   r`   ra   s   @r%   r   r      s    	 ! !(
(9v.-;:F$
&
	/!&	.+C
 r'   r   c                   ,    \ rS rSrSr\rSS jrS rSr	g)RemoteTestRunneri]  z
Run tests and record everything but don't display anything.

The implementation matches the unpythonic coding style of unittest2.
Nc                 0    Xl         X0l        Ub  X l        g g r)   )failfastro   resultclass)r    r   r   ro   s       r%   r   RemoteTestRunner.__init__f  s     "* #r'   c                     U R                  5       n[        R                  " U5        U R                  Ul        U R                  Ul        U" U5        U$ r)   )r   unittestregisterResultr   ro   )r    r/   results      r%   runRemoteTestRunner.runl  s@    !!#'--Vr'   )ro   r   r   )FNF)
r[   r\   r]   r^   rx   r   r   r   r   r_   r|   r'   r%   r   r   ]  s     #K+r'   r   c                      [         R                  " 5       S;  a  g [        [        R                  S   5      $ ! [
         a    [         R                  " 5       s $ f = f)zH
The maximum number of test processes when using the --parallel option.
>   forkspawnr   DJANGO_TEST_PROCESSES)multiprocessingget_start_methodintosenvironKeyError	cpu_countr|   r'   r%   get_max_test_processesr  u  sQ     '')1BB+2::5677 +((**+s   8 AAc                 z    U S:X  a  U $  [        U 5      $ ! [         a    [        R                  " U < S35      ef = f)z,Parse value passed to the --parallel option.autoz' is not an integer or the string 'auto')r   
ValueErrorargparseArgumentTypeError)values    r%   parallel_typer    sJ    
5z 
((i>?
 	

s   
 %:c                 H   U R                  5          U =R                  S-  sl        U R                  qSSS5        [        R                  " 5       nUS:X  a?  U(       a  [        U5      (       a
  Uc  SnU" U6   [        R                  " 5         [        US9  Ub  UO[        nU Hl  n	[        U	   n
US:X  a;  U
R                  R                  X   5        UR                  U	5      =n(       a  Xl        U
R                  R                  [        5        Mn     g! , (       d  f       N= f)z
Switch to databases dedicated to this worker.

This helper lives at module-level because of the multiprocessing module's
requirements.
r   Nr   r|   rf   )get_lockr
  
_worker_idr   r   callabledjangosetupr   r   settings_dictupdateget_test_serialized_contentscreationsetup_worker_connection)counterinitial_settingsserialized_contentsprocess_setupprocess_setup_args
debug_modeused_aliasesstart_method
db_aliasesalias
connectionr
  s               r%   _init_workerr$    s    $ 
			]]
 
 #335LwXm44!)%'"-.Z0!-!9{J '
7"$$++,<,CD+//66u67<433J?  
	s   "D
D!c                 V    U u  pp4nU" XES9nUR                  U5      nX'R                  4$ )z
Run a suite of tests with a RemoteTestRunner and return a RemoteTestResult.

This helper lives at module-level and its arguments are wrapped in a tuple
because of the multiprocessing module's requirements.
)r   ro   )r   r   )r   runner_classsubsuite_indexsubsuiter   ro   runnerr   s           r%   _run_subsuiter*    s7     @D<L(f8;FZZ!F==((r'   c                      g)z-Stub method to simplify run() implementation.Nr|   )r   s    r%   _process_setup_stubr,    s    r'   c                   X   ^  \ rS rSrSr\r\rSr	\
r\r S	U 4S jjrS rS rS rSrU =r$ )
ParallelTestSuitei  ay  
Run a series of tests in parallel in several processes.

While the unittest module's documentation implies that orchestrating the
execution of tests is the responsibility of the test runner, in practice,
it appears that TestRunner classes are more concerned with formatting and
displaying test results.

Since there are fewer use cases for customizing TestSuite than TestRunner,
implementing parallelization at the level of the TestSuite improves
interoperability with existing custom test runners. A single instance of a
test runner can still collect results from all tests without being aware
that they have been run in parallel.
r|   c                    > Xl         X l        X0l        X@l        XPl        S U l        S U l        S U l        [        TU ]%  5         g r)   )
	subsuites	processesr   r  ro   r  r  r  r   r   )r    r0  r1  r   r  ro   r$   s         r%   r   ParallelTestSuite.__init__  sA     #" $ $#'  r'   c                    U R                  5         [        R                  " [        R                  S5      n[        R
                  " U R                  U R                  R                  UU R                  U R                  U R                  R                  U R                  U R                  U R                  /S9n[        U R                   5       VVs/ s H)  u  pEU R"                  XEU R$                  U R&                  4PM+     nnnUR)                  U R*                  R                  U5      n UR,                  (       a  UR/                  5         O` UR1                  SS9u  p[9        U R                   U   5      n
U	 H.  nUS   n[;        XS5      nUc  M  XS      nUSS nU" U/UQ76   M0     M  UR=                  5         U$ s  snnf ! [        R2                   a     M  [4         a    UR7                  5          MK  f = f)a  
Distribute TestCases across workers.

Return an identifier of each TestCase with its result in order to use
imap_unordered to show results as soon as they're available.

To minimize pickling errors when getting results from workers:

- pass back numeric indexes in self.subsuites instead of tests
- make tracebacks picklable with tblib, if available

Even with tblib, errors may still occur for dynamically created
exception classes which cannot be unpickled.
r   )r1  initializerinitargsg?)timeoutNr      )initialize_suiter   Valuectypesc_intPoolr1  init_worker__func__r  r  r  r  r  r  	enumerater0  r&  r   ro   imap_unorderedrun_subsuite
shouldStop	terminatenextTimeoutErrorStopIterationcloselistgetattrjoin)r    r   r  poolindexr(  r   test_resultsr'  r   testsevent
event_namer+   r/   s                  r%   r   ParallelTestSuite.run  s    	!''a8##nn((11%%((""++''!!
 $-T^^#<
#< L#< 	 
 **4+<+<+E+EtL   )5):):3):)G& 78E"1X
!&d;?1XQRy$t$   . 			?
 #//   

s   0F=G G7G76G7c                 ,    [        U R                  5      $ r)   )iterr0  r   s    r%   __iter__ParallelTestSuite.__iter__2  s    DNN##r'   c                 $   [         R                  " 5       S:X  am  [         Vs0 s H  o[        U   R                  _M     snU l        [         Vs0 s H(  nXR
                  ;   d  M  U[        U   R                  _M*     snU l        g g s  snf s  snf )Nr   )r   r   r   r  r  serialized_aliasesr  r  )r    r"  s     r%   r8  "ParallelTestSuite.initialize_suite5  s    ++-8EP%EPE{5)777[%D!
 )((E333 D{5)CCC((D$	 9%(s   BB&B)ro   r  r   r  r1  r  r0  r  )FFF)r[   r\   r]   r^   rx   r$  r=  r,  r  r  r*  rA  r   r&  r   r   rT  r8  r_   r`   ra   s   @r%   r.  r.    sE      K'M L#L NS=~$	 	r'   r.  c                   R    \ rS rSrSrSr\S 5       rSS jr\	S 5       r
S rS	 rS
rg)ShuffleriA  a  
This class implements shuffling with a special consistency property.
Consistency means that, for a given seed and key function, if two sets of
items are shuffled, the resulting order will agree on the intersection of
the two sets. For example, if items are removed from an original set, the
shuffled order for the new set will be the shuffled order of the original
set restricted to the smaller set.
md5c                     [         R                  " U R                  SS9nUR                  UR	                  S5      5        UR                  5       $ )NF)usedforsecurityzutf-8)hashlibnewhash_algorithmr  encode	hexdigest)clstexths      r%   
_hash_textShuffler._hash_textN  s9    KK**EB	W%&{{}r'   Nc                 Z    Uc  [         R                  " SS5      nSnOSnXl        X l        g )Nr   l   c(	 	generatedgiven)randomrandintseedseed_source)r    rm  rn  s      r%   r   Shuffler.__init__T  s,    <>>!Z0D%K!K	&r'   c                 <    U R                   < SU R                   S3$ )Nz ()rm  rn  r   s    r%   seed_displayShuffler.seed_display^  s     ))b!1!1 2!44r'   c                 h    SR                  U R                  U" U5      5      nU R                  U5      $ )Nz{}{})rV   rm  rf  )r    r~   keyrd  s       r%   
_hash_itemShuffler._hash_itemb  s)    }}TYYD	2t$$r'   c                     0 nU H=  nU R                  XB5      nXS;   a   SR                  UUX5   5      n[        U5      eXCU'   M?     [        U5       Vs/ s H  oSU   PM	     sn$ s  snf )a2  
Return a new list of the items in a shuffled order.

The `key` is a function that accepts an item in `items` and returns
a string unique for that item that can be viewed as a string id. The
order of the return value is deterministic. It depends on the seed
and key function but not on the original order.
z)item {!r} has same hash {!r} as item {!r})rw  rV   RuntimeErrorsorted)r    itemsrv  hashesr~   hashedmsgs          r%   shuffleShuffler.shufflef  sv     D__T/FAHHN
 #3''!6N  .4F^<^6v^<<<s   A$rr  r)   )r[   r\   r]   r^   rx   r`  classmethodrf  r   r   rs  rw  r  r_   r|   r'   r%   rZ  rZ  A  sC     N 
' 5 5%=r'   rZ  c                   6   \ rS rSrSr\R                  r\r	\R                  r\R                  r\\4r                    SS jr\S 5       r\S 5       rSS jrS rS	 r\S
 5       rS rSS 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)DiscoverRunneri}  z8A Django test runner that uses unittest2 test discovery.Nc                 x   Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        [        U=(       d    / 5      U l        [        U=(       d    / 5      U l        [        R                  " 5       (       d8  U(       a1   [        R                  " [         R"                  R%                  5       S9  Xl        U R.                  (       a  U R                  S:  a  [1        S5      eXl        S U l        U(       a
  [7        5       O	[9        5       U l        U(       a#  U Vs1 s H  nSU;   a  UOSU-  iM     snU l        UU l        S U l        UU l         UU l!        g ! [&        [(        R*                  4 a3    [        R                  " [         R,                  R%                  5       S9   Nf = fs  snf )N)filer   zFYou cannot use --pdb with parallel tests; pass --parallel=1 to use it.*z*%s*)"pattern	top_levelr#   interactiver   keepdbreverser  	debug_sqlparallelsettagsexclude_tagsfaulthandler
is_enabledenablesysstderrfilenoAttributeErrorioUnsupportedOperation
__stderr__rq   r  ro   test_name_patternsr   r   time_keeperr  	_shufflerr   	durations)r    r  r  r#   r  r   r  r  r  r  r  r  r  r  rq   ro   enable_faulthandlertimingr  r   r  r   s                         r%   r   DiscoverRunner.__init__  sd   0 ""& $" 
O	 23&&((-@B##):):)<= 88)X  "&+1:<~7G
  2'1G '>v/??1'D# ") #B$;$;< B##)>)>)@AB's   0E' +F7'A
F43F4c           
         UR                  SSSS9  UR                  SSSSS	9  UR                  S
SSSS9  UR                  SSSS9  UR                  SSS[        SSS9  UR                  SSSSS9  UR                  SSSS9  UR                  SSSSS9  UR                  SSS S![        S"S#S$9  UR                  S%S&S'S(S)9  UR                  S*S&S+S,S)9  UR                  S-SS.S9  UR                  S/S0SS1S9  UR                  S2S3S4S5S)9  UR                  S6SS7S9  UR                  S8S&S9S:S)9  [        (       a  UR                  S;S<[        S S"S=S>9  g g )?Nz
--failfast
store_truez-Stops the test suite after the first failure.)actionhelpz-tz--top-level-directoryr  z,Top level of project for unittest discovery.)destr  z-pz	--patternztest*.pyz0The test matching pattern. Defaults to test*.py.)defaultr  z--keepdbz#Preserves the test DB between runs.z	--shuffle?FSEEDzShuffles test case order.)nargsr  typemetavarr  z-rz	--reversezReverses test case order.z--debug-modezSets settings.DEBUG to True.z-dz--debug-sqlz%Prints logged SQL queries on failure.z
--parallelr  r   NzqRun tests using up to N parallel processes. Use the value "auto" to run one test process for each processor core.)r  constr  r  r  r  z--tagr   r  zBRun only tests with the specified tag. Can be used multiple times.)r  r  r  z--exclude-tagr  zDDo not run tests with the specified tag. Can be used multiple times.z--pdbz@Runs a debugger (pdb, or ipdb if installed) on error or failure.z-bz--bufferz"Discard output from passing tests.z--no-faulthandlerstore_falser  z5Disables the Python faulthandler module during tests.z--timingz=Output timings, including database set up and total run time.z-kr  z~Only run test methods and classes that match the pattern or substring. Can be used multiple times. Same as unittest -k option.z--durationsr  z,Show the N slowest test cases (N=0 for all).)r  r  r  r  r  )add_argumentr   r  r   )rc  parsers     r%   add_argumentsDiscoverRunner.add_arguments  sE   @ 	 	

 	#?	 	 	
 	C	 	 	
 	|2W 	 	
 	, 	 	
 	,	 	 	
 	/ 	 	

 	8	 	 	
 	J 	 	
 	U	 	 	
 	W	 	 	
 	S 	 	

 	5	 	 	
 	 &H	 	 	
 	Q 	 	

 	%& 	 		
 5 C    r'   c                 J    U R                   c  g U R                   R                  $ r)   )r  rm  r   s    r%   shuffle_seedDiscoverRunner.shuffle_seed4  s    >>!~~"""r'   c                     Uc  [         R                  nU R                  cA  U R                  S::  d$  U R                  S:X  a  U[         R                  :  a  g[	        U5        gU R                  R                  X!5        g)a,  
Log the message at the given logging level (the default is INFO).

If a logger isn't set, the message is instead printed to the console,
respecting the configured verbosity. A verbosity of 0 prints no output,
a verbosity of 1 prints INFO and above, and a verbosity of 2 or higher
prints all levels.
Nr   r   )r   INFOr   r#   rp   log)r    r  levels      r%   r  DiscoverRunner.log:  sX     =LLE;;~~"t~~':uw||?S#JKKOOE'r'   c                 T    [        U R                  S9  [        R                  " 5         g )Nr  )r   r  r   installHandlerr    r   s     r%   r   %DiscoverRunner.setup_test_environmentL  s    T__5!r'   c                     U R                   SL a  g [        U R                   S9nU R                  SUR                   35        Xl        g )NF)rm  zUsing shuffle seed: )r  rZ  r  rs  r  )r    shufflers     r%   setup_shufflerDiscoverRunner.setup_shufflerP  s?    <<5 .'(=(='>?@!r'   c              #      #    U R                   R                  nU R                  U R                   l         S v   XR                   l        g ! XR                   l        f = f7fr)   )test_loadertestNamePatternsr  )r    original_test_name_patternss     r%   load_with_patterns!DiscoverRunner.load_with_patternsW  sP     &*&6&6&G&G#,0,C,C)	L 1L-0K-s   2AA
 A
AAc                    [         R                  R                  U5      nS n[         R                  R                  U5      (       dK  U R	                  5          U R
                  R                  U5      nS S S 5        UR                  5       (       a  U$ [        U5      u  pVU(       a
  U(       d  U$ O_[         R                  R                  U5      (       d;  [         R                  R                  U5      (       a  Ub   e[        SU< S35      eU$ UR                  5       n[         R                  R                  U5      (       a  U R                  (       d  [        U5      US'   U R	                  5          U R
                  R                  " SSU0UD6nS S S 5        S U R
                  l        U$ ! , (       d  f       GN@= f! , (       d  f       N3= f)Nz,One of the test labels is a path to a file: zR, which is not supported. Use a dotted module name or path to a directory instead.top_level_dir	start_dirr|   )r   pathabspathexistsr  r  loadTestsFromNamecountTestCasestry_importingisdirrz  r   r  find_top_leveldiscover_top_level_dir)r    labeldiscover_kwargslabel_as_pathrN  is_importable
is_packager   s           r%   load_tests_for_label#DiscoverRunner.load_tests_for_labela  sh   . ww~~m,,((*((::5A +##%%$1%$8! }--ww~~m,,}$}"B5) L3 4 
 L %%'77==''&4]&CF?#$$&$$--HHHE '
 +/'; +*. '&s   F+1F=+
F:=
Gc           	         U=(       d    S/n0 nU R                   b  U R                   US'   U R                  b  U R                  US'   U R                  5         / nU H.  nU R                  XS5      nUR	                  [        U5      5        M0     U R                  (       d  U R                  (       a  U R                  (       aC  U R                  SSR                  [        U R                  5      5      -  [        R                  S9  U R                  (       aC  U R                  SSR                  [        U R                  5      5      -  [        R                  S9  [        X@R                  U R                  5      n[        R                  R                   /U R"                  Q7n[%        ['        UUU R(                  U R*                  S95      nU R                  S	[-        U5      -  5        U R/                  U5      nU R0                  S
:  ai  [3        U5      n	[5        U R0                  [-        U	5      5      n
Xl        U
S
:  a3  U R7                  U	U
U R8                  U R:                  U R<                  5      nU$ )N.r  r  zIncluding test tag(s): %s., r  zExcluding test tag(s): %s.r  r  zFound %d test(s).r   )r  r  r  r  extendr   r  r  r  rJ  r{  r   r   filter_tests_by_tagsr   loader_FailedTest
reorder_byrH  reorder_testsr  r  len
test_suiter  partition_suite_by_caseminparallel_test_suiter   r  ro   )r    test_labelsr   r  	all_testsr  rN  
test_typessuiter0  r1  s              r%   build_suiteDiscoverRunner.build_suite  s   !*cU<<#)-OI&>>%/3~~OO,	 E--eEE_U34 ! 99))yy0499VDII=N3OO!--     0499VDDUDU=V3WW!--   -Y		4CTCTUI
 oo11DDOOD
	
	 	$s9~56	*==1/6I DMM3y>:I &M1}00MMOOKK r'   c                     [        U R                  U R                  4U R                  U R                  U R
                  U R                  S.UD6$ )N)r  r  r  r  )_setup_databasesr#   r  r  r  r  r  r  s     r%   r   DiscoverRunner.setup_databases  sN    NN
 ((;;nn]]
 
 	
r'   c                 `    U R                   (       a  [        $ U R                  (       a  [        $ g r)   )r  r   rq   rc   r   s    r%   get_resultclassDiscoverRunner.get_resultclass  s!    >>))XX!! r'   c                     U R                   U R                  5       U R                  U R                  S.n[        (       a  U R
                  US'   U$ )N)r   r   r#   ro   r  )r   r  r#   ro   r   r  r  s     r%   get_test_runner_kwargs%DiscoverRunner.get_test_runner_kwargs  sD    //1kk	
 5"&..F;r'   c                 .    [        SU R                  US9  g )Ncheck)r#   	databases)r   r#   )r    r   s     r%   
run_checksDiscoverRunner.run_checks  s     	W)Lr'   c                 T   U R                  5       nU R                  " S0 UD6n UR                  U5      U R                  b+  U R                  R                  nU R                  SU 35        $ $ ! U R                  b+  U R                  R                  nU R                  SU 35        f f = f)NzUsed shuffle seed: r|   )r  test_runnerr   r  rs  r  )r    r  r   r)  rs  s        r%   	run_suiteDiscoverRunner.run_suite  s    ,,.!!+F+	?::e$~~)#~~::.|n=> *t~~)#~~::.|n=> *s   A- -:B'c                 X    [        UU R                  U R                  U R                  S9  g)z%Destroy all the non-mirror databases.)r#   r  r  N)_teardown_databasesr#   r  r  )r    
old_configr   s      r%   r   !DiscoverRunner.teardown_databases  s"    nn]];;		
r'   c                 B    [         R                  " 5         [        5         g r)   )r   r3   r   r  s     r%   r   (DiscoverRunner.teardown_test_environment  s     !#r'   c                     [        UR                  5      [        UR                  5      -   [        UR                  5      -   $ r)   )r  rF   r?   r   )r    r  r   r   s       r%   suite_resultDiscoverRunner.suite_result  s1     3v}}#55F<V<V8WW	
r'   c                    ^^ 0 m[        U5       HN  n[        USS 5      nUS:X  a  [        nU(       d  M%  [        USS5      mTR                  UU4S jU 5       5        MP     T$ )Nr   __all__serialized_rollbackFc              3   ^   >#    U  H"  nUT=(       d    TR                  US 5      4v   M$     g7fFN)r  )r   r"  r   r  s     r%   r   0DiscoverRunner._get_databases.<locals>.<genexpr>  s.      !!/ /N9==3NO!/s   *-)r   rI  r   r  )r    r  r/   test_databasesr   r  s       @@r%   _get_databasesDiscoverRunner._get_databases   sj    	#E*D$T;=N*!,~&-d4I5&Q#   !!/!  + r'   c                     U R                  U5      n[         Vs/ s H  o3U;  d  M
  UPM     nnU(       a9  U R                  SSR                  [	        U5      5      -  [
        R                  S9  U$ s  snf )Nz)Skipping setup of unused database(s): %s.r  r  )r  r   r  rJ  r{  r   r   )r    r  r   r"  unused_databasess        r%   get_databasesDiscoverRunner.get_databases  so    ''.	/:U{e9>TE{UHH;))F#3456mm  
  Vs
   	A1A1c                    U R                  5         U R                  U5      nU R                  U5      n[        S UR	                  5        5       5      Ul        [        U5      Ul        U R                  R                  S5         U R                  UUR
                  S9nSSS5        Sn U R                  U5        U R                  U5      n  U R                  R                  S5         U R                  W5        SSS5        U R                  5         U R                  R                  5         U R!                  X75      $ ! , (       d  f       N= f! [         a    Sne f = f! , (       d  f       Nk= f! [         a    U(       d  e  Nrf = f!  U R                  R                  S5         U R                  W5        SSS5        O! , (       d  f       O= fU R                  5         f ! [         a    U(       d  e  f f = f= f)z
Run the unit tests for all the test labels in the provided list.

Test labels should be dotted Python paths to test modules, test
classes, or test methods.

Return the number of tests that failed.
c              3   <   #    U  H  u  pU(       d  M  Uv   M     g 7fr)   r|   )r   r"  	serializes      r%   r   +DiscoverRunner.run_tests.<locals>.<genexpr>%  s      '
*;&eyEE*;s   	zTotal database setup)aliasesrW  NFTzTotal database teardown)r   r  r  r  r|  rW  r  r  timedr   r  r  r   r   r   print_resultsr  )r    r  r   r  r   r	  
run_failedr   s           r%   	run_testsDiscoverRunner.run_tests  s    	##%  -&&u-	#& '
*3//*;'
 $
  !^##$:;--!#(#;#; . J <
 
	OOI&^^E*F
%%++,EF++J7 G..0 	&&(  /// <;  	J	
 GF   " "	%%++,EF++J7 GFF..0  " "s   D=)"E E0 (E:E0 =
EEF 
E-)E0 0FFG:
G"%G 7	G" 
G
G"!G:"G74G:6G77G:)r  ro   r  r  r  r  r   r  r  r   r  r  rq   r  r  r  r  r  r  r#   )NNr   TFFFFFr   NNNFFTFFNNr)   ))r[   r\   r]   r^   rx   r   	TestSuiter  r.  r  TextTestRunnerr  defaultTestLoaderr  r
   r	   r  r   r  r  r   r  r  r   r  r   r  r  r  r   r  r  r  r  r   r   r  r  r  r%  r_   r|   r'   r%   r  r  }  s   B##J+))K,,KN+J  +;#z n n` # #
($"" L L#J;z	
"	M
?
$

	'0r'   r  c                 b     [        U 5      nS[        US5      4$ ! [        [        4 a     gf = f)z
Try importing a test label, and return (is_importable, is_package).

Relative labels like "." and ".." are seen as directories.
)FFT__path__)r   ImportError	TypeErrorhasattr)r  mods     r%   r  r  C  s>    E" '#z*++ # s    ..c                      [         R                  R                  U S5      n[         R                  R                  U5      (       d   U $ [         R                  R	                  U 5      nX :X  a   U $ Un Mr  )Nz__init__.py)r   r  rJ  r  dirname)r  init_pytry_nexts      r%   r  r  Q  sh     '',,y-8ww~~g&&  77??9-  	 r'   c                 8    U R                    SU R                   3$ )Nr  )r\   r]   )rc  s    r%   _class_shuffle_keyr5  i  s    nnQs//011r'   c                   ^ 0 m[         R                  " U [        5       H4  u  p#[        U5      n[        US   5      nUR	                  US S9nUTU'   M6     UR	                  T[
        S9n[         R                  " U4S jU 5       6 $ )z
Return an iterator over the given tests in a shuffled order, keeping tests
next to other tests of their class.

`tests` should be an iterable of tests.
r   c                 "    U R                  5       $ r)   )id)r/   s    r%   <lambda>shuffle_tests.<locals>.<lambda>x  s
    TWWYr'   )rv  c              3   .   >#    U  H
  nTU   v   M     g 7fr)   r|   )r   rc  tests_by_types     r%   r    shuffle_tests.<locals>.<genexpr>}  s     C7C]3/7s   )	itertoolsgroupbyr  rH  r  r5  chain)rN  r  _class_tests	test_typeclassesr<  s         @r%   shuffle_testsrE  m  s     M#++E48;'Q(	&&{8N&O#.i 	 9 }2DEG??C7CDDr'   c                     Uc  U(       a  [        U 5      $ [        U 5      $ [        X5      n U(       d  U $ [        [        U 5      5      $ )z
Return an iterator that reorders the given tests, keeping tests next to
other tests of their class.

`tests` should be an iterable of tests that supports reversed().
)reversedrS  rE  rH  )rN  r  r  s      r%   reorder_test_binrH    sB     E?"E{%*EDK  r'   c              #     #    [        [        U5      S-   5       Vs/ s H  n[        [        5      PM     nnUGt pgU  HH  n[	        Xa5       H  u  p[        X5      (       d  M    O   Un	U	[        U5         R                  U5        MJ     U HK  n	[        [        R                  R                  U	R                  5       5      5      n [        XUS9 Sh  vN   MM     gs  snf  N7f)aF  
Reorder an iterable of tests, grouping by the given TestCase classes.

This function also removes any duplicates and reorders so that tests of the
same type are consecutive.

The result is returned as an iterator. `classes` is a sequence of types.
Tests that are instances of `classes[0]` are grouped first, followed by
instances of `classes[1]`, etc. Tests that are not instances of any of the
classes are grouped last.

If `reverse` is True, the tests within each `classes` group are reversed,
but without reversing the order of `classes` itself.

The `shuffler` argument is an optional instance of this module's `Shuffler`
class. If provided, tests will be shuffled within each `classes` group, but
keeping tests with other tests of their TestCase class. Reversing is
applied after shuffling to allow reversing the same random order.
r   r  N)ranger  r   r   zip
isinstancer  addrH  r>  r@  from_iterablevaluesrH  )rN  rD  r  r  ibins
class_binslast_binr/   test_bin
test_classs              r%   r  r    s     , .33w<!3C-DE-DK
#-DDE Z$'
$< H$++ %=  Hd  &  Y__228??3DEF#EgNNN  F 	Os"   C"C)C""A/C"C C"c                     [        U 5      n[        U 5      n[        R                  " U[         5       VVs/ s H  u  p4U" U5      PM     snn$ s  snnf )zBPartition a test suite by TestCase, preserving the order of tests.)r  r   r>  r?  )r  suite_classr  rA  rN  s        r%   r  r    sC    u+K&I/8/@/@D/QR/Q81K/QRRRs   Ac                    [        U [        R                  R                  5      (       a  g[	        [        U S/ 5      5      n[        U S[        U 5      5      n[        X5      (       a2  [        X5      n[        [        US/ 5      5      nUR                  U5      nU(       a  UR                  U5      (       a  gUR                  U5      $ )NTr  _testMethodNameF)rL  r   r  r  r  rI  strr.  rH  union
isdisjoint)r/   r  r  	test_tagstest_fn_nametest_fntest_fn_tagss          r%   test_match_tagsra    s    $3344 GD&"-.I4!2CI>Lt""$-GGVR89OOL1		$$T**--r'   c                     ^^ UU4S jU  5       $ )z)Return the matching tests as an iterator.c              3   P   >#    U  H  n[        UTT5      (       d  M  Uv   M     g 7fr)   )ra  )r   r/   r  r  s     r%   r   'filter_tests_by_tags.<locals>.<genexpr>  s     PUTodD,&ODDUs   &	&r|   )rN  r  r  s    ``r%   r  r    s    PUPPr'   )NNNNNN)NFr  )Kr  r:  r  r^  r  r>  r   r   r   r   rk  r  r   r   collectionsr   
contextlibr   	importlibr   r   rU   r  django.core.managementr   	django.dbr   django.testr	   r
   django.test.utilsr   r   r   r   r  r   r   r  r   django.utils.datastructuresr   django.utils.versionr   ipdbrq   r,  tblib.pickling_supportr   TextTestResultr   rc   rz   
TestResultr   r   r  r  r  r$  r*  r,  r'  r.  rZ  r  r  r  r5  rE  rH  r  r  ra  r  r|   r'   r%   <module>rr     s       	    	   
   # % #    / ! 0 I I A 4 G 7 2 &!
8X44 8v#X,, #6 Lx** L^ 0+	
 

 (@V
)	
o** od9= 9=xC0 C0L,02E&!($ONS. Q]%  
  Es$   E !E* 
E'&E'*E54E5