
    rhA3                       S r SSKJ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  \R"                  " S5      r\R&                   " S	 S
5      5       rS rSS jrS r\S:X  a  \" 5         gg)a#  
Multiprocess testing.  Tests all doctests and Test unittest objects in all
modules that are imported when running "import music21".  Runs a thread on
each core of a multicore system unless there are more than 2 cores, in which
case it runs on n-1 cores.

N.B. this gets a slightly different set of modules than test/test.py does
because the `imp` module is not available for threaded processing.  Running
both modules gives great coverage of just about everything -- do that before
building a new release.

Run test/testDocumentation after this.
    )annotationsN)environment)common)
testRunner)
commonTestztest.multiprocessTestc                      \ rS rSr% SrS\S'   SrS\S'   SrS\S'   SrS\S'   Sr	S\S	'   Sr
S\S
'   SrS\S'   SrS\S'   SrS\S'   Srg)ModuleResponse)   Nz
str | None
returnCodezt.Anyfp
moduleNamesuccessr   errorsfailurestestsRunrunTime )__name__
__module____qualname____firstlineno__r   __annotations__r   r   r   r   r   r   r   r   __static_attributes__r       W/home/james-whalen/.local/lib/python3.13/site-packages/music21/test/multiprocessTest.pyr	   r	   )   s\    JBJGUJFEHeHeGUr   r	   c                :   U S   nU S   nSn[         R                   " 5       nUR                  U5      n[        R                  SU< SU< S35        UR	                  U5      nUS:X  a$  U S3n[        R                  U5        [        S	X'S
9$ US:X  a$  U S3n[        R                  U5        [        SX'S
9$  UR	                  USS9n[        R                  " 5       n	[        US5      (       d  [        R                  U S35        O:[        R                  R                  UR                  5      n
U	R                  U
5         [        R                  " U5      nU	R                  U5        [        R                   " U	5        [        R                  S5        [        R"                  " US9n UR%                  U	5      n/ nUR&                   H  nUR)                  US   5        M     / nUR*                   H  nUR)                  US   5        M     [-        S[         R                   " 5       U-
  -  5      S-  n[        SUUUR/                  5       [1        U5      UUUR2                  US9	$ ! [         a    [        R                  U S35         GN!f = f! [4         a<  n[        R                  SU SU S35        [        SUUS [1        U5      S9s S nA$ S nAff = f! [4         a:  n[        R                  SU SU S35        [        SU[1        U5      S9s S nA$ S nAff = f) Nr      Fzrunning fp=z moduleObject=
skipz is skipped 
Skipped)r   r   r   	notInTreezI is in the music21 directory but not imported in music21. Skipped -- fix!	NotInTree)addM21Testz has no Test classz cannot load Doctestszrunning Tests...
)	verbosity
         $@TestsRun)	r   r   r   r   r   r   r   r   r   z*** Exception in running : z...
TrappedException)r   r   r   r   r   z*** Large Exception in running LargeException)r   r   r   )timegetModuleWithoutImpenvironLocal
printDebug_getNamePeriodr	   r   defaultDoctestSuitehasattrunittestdefaultTestLoaderloadTestsFromTestCaser$   addTests
ValueErrorr   fixDoctestsMusic21TestRunnerrunr   appendr   roundwasSuccessfulstrr   	Exception)argsmodGathr   r%   	timeStartmoduleObject
namePeriodr   r   s1s2s3runner
testResultr   er   fr   excps                       r   runOneModuleWithoutImprM   8   s   1gG	aBI		I..r2Llre?\O2>?''+JvD'(rKK		$lcd 	 	(MM74++Bu+=
++- |V,,##|n4F$GH++AA,BSBSTBKKO	//=BKKO
 	r" 45--	B	$BJ F&&ad# 'H((!% )B$))+	"9:;dBG!Z%'-7*4*B*B*D-0_)/+3+5+>+>*13 3'  	##|n4I$JK	8  	$##&?
|2dVSX$YZ!-?%'-7*.-0Y	$ $	$  4"A"RvU ST)9!#),T4 	44sn   7B	K 'I$ (?K (B;J $"J
K 	J

K 
K1KK	K KK 
L /LLLc                ~  ^ [         R                  " 5         [        R                  n[        R                  " 5       n[
        R                  " 5       n[        SU SU S35        [         R                  " SS9mSnTR                  n[        R                  " US9 nUR                  [        U4S jU 5       5      n	Sn
S	nS	n/ nU
SL Ga-   U	R                  S
S9nUS:  a  [        S5        Ub  UR                  b  UR                  nUR!                  SS5      nOSnUR"                  nUb  [%        UR"                  S-  5      S-  nUR&                  (       d1  UR(                  (       d   [        SU SUR*                   SU S35        OO[-        UR&                  5      n[-        UR(                  5      n[        SU SUR*                   SU SU SU S35        S	nUS
-  nUR/                  U5        U
SL a  GM-  SSS5        U[        l        [5        WXG5        g! [        R0                   a    US
-  nUS:X  a  US	:  a  [        SSS9  OUS:X  a
  [        SSS9  US-  S	:X  a  [        [3        U5      S-   SSS9  X:  aC  US	:  a=  [        SSS9  S n
[5        XU5        UR7                  5         [        R8                  " 5          N[:         a&    S n
UR7                  5         UR=                  5          GN [>         a4  nUS
-  n[A        S![3        U5      S"9nUR/                  U5         SnAGN8SnAff = f! , (       d  f       GN?= f)#z6
Run all tests. Group can be "test" and/or "external"
z	Creating z) processes for multiprocessing (omitting z processors)T)useExtendedd   )	processesc              3  ,   >#    U  H	  nTU4v   M     g 7f)Nr   ).0r   	modGathers     r   	<genexpr>!mainPoolRunner.<locals>.<genexpr>   s     $Jzi_zs   r   r   )timeout    N	___init__r&   r'   z				r)   
 tests in z secsz tests, z errors z failures in zDelay in processing, seconds: )endz2Starting first modules, should take 5-10 seconds:  )r\   flushz
Too many delays, giving up.)r^   FUntrappedException)r   r   )!r   testImportssysstderrr,   r   cpusprintModuleGathermodulePathsmultiprocessingPoolimap_unorderedrM   nextr   replacer   r<   r   r   r   lenr;   TimeoutErrorr>   printSummarycloseexitStopIterationjoinr?   r	   )	testGrouprestoreEnvironmentDefaultsleaveOutnormalStdErrorrB   poolSize
maxTimeout
pathsToRunpoolres
continueIttimeoutseventsProcessedsummaryOutput	newResultmnrtnumErrnumFailrL   exceptionLogrT   s                        @r   mainPoolRunnerr      s    ZZN		I{{}H	IhZH
R^
_`''D9IJ&&J 
			1T !!"8$Jz$JL 
D 03HHQH/	q="I( ++7&11ZZR8"**B~"9#4#4r#9:TA(//	8J8J!HRD93E3E2FjQSPTTY"Z[%()9)9%:F&))*<*<&=G!HRD93E3E2Fh%+HHWI]2$e#U V1$$$Y// D  
2D  CJ	69 #// Aq=_q%8:C]NTVWa<1$#h-#-2TB(_q-@9F!&J :FJJLHHJ  "


		 31$-3"4y  $$\223u 
2	1sP   /L-	D$H-L-B(L*=L-?+L**L--	L*6)L%L-%L**L--
L<c                	   SnU  Vs/ s H  oDR                   PM     nnU H%  nXe;  d  M
  [        SUS9nU R                  U5        M'     Sn/ n	/ n
/ n/ nU  GH  n[        U5        UR                  S:X  a   U	R                  SUR                    35        M?  UR                  S:X  a!  UR                  SUR                    S35        Mp  UR                  S	:X  a   UR                  S
UR                    35        M  UR                  S:X  a=  UR                  SUR
                  < SUR                   < SUR                  < 35        M  UR                  S:X  a0  UR                  SUR                   < SUR                  < 35        GM-  UR                  S:X  a!  UR                  SUR                    35        GM^  UR                  S:X  a5  UR
                  S:X  a"  UR                  SUR
                   S35        GM  GM  UR                  S:X  Ga)  XR                  -  nUR                  (       a>  U
R                  UR
                  < SUR                  < SUR                  < S35        GM  UR                  nUR                  nUR                  SUR
                  < S[        U5      < S[        U5      < SUR                  < SUR                  < S3
-   S -   5        U H%  nUUS!-   -  nUR                  [        U5      5        M'     U H%  nUUS!-   -  nUR                  [        U5      5        M'     GM  UR                  S"U 35        GM     US#-  nU	 H  nUUS!-   -  nM     U
 H  nUUS!-   -  nM     U H  nUUS!-   -  nM     U H  nUUS!-   -  nM     US$-  n[        R                  " 5       U-
  nUS%U SUS& S'3-  n[         R"                  R%                  5         [        U5        [         R"                  R%                  5         SS Kn[(        R*                  R-                  [.        R1                  5       S(5      n[3        US)S*S+9 nUR5                  U5        UR5                  S,UR&                  R7                  5       R9                  S-5      -   5        S S S 5        [        S.U-   5        g s  snf ! , (       d  f       N"= f)/NrY   NoResult)r   r   r   r    z	Skipped: zSilent test fail for z: Run separately!r_   z(Untrapped Exception for unknown module: r*   zTrapped Exception for module z, at r)   r+   zLarge Exception for file ImportErrorzImport Error for r"   zNot in Tree Error: r]   r(   z successfully ran r[   z secondsz
-----------------------------
z had z ERRORS and z FAILURES in z tests after z
 seconds:
z-----------------------------
r   zUnknown return code zL

---------------SUMMARY---------------------------------------------------
zJ-------------------------------------------------------------------------
zRan z.4fz	 seconds
zlastResults.txtwzutf-8)encodingzRun at z%Y-%m-%d %H:%M:%SzResults at )r   r	   r;   rd   r   r   r   rI   r   r   r   r   r   rl   r>   r,   ra   stdoutr^   datetimeospathrr   r.   getRootTempDiropenwritenowstrftime)r   rB   ry   outStrisummaryOutputTwor   failLog
totalTestsskippedSummarysuccessSummaryerrorsFoundSummaryotherSummarymoduleResponse
errorsListfailuresListrJ   rK   lineelapsedTimer   lastResultss                         r   rn   rn      s]   F&34mm4%$
rBG  ) 
 JNNL'n$$	1!!In.?.?-@"AB&&*4"78I8I7JJ[ \]&&*>>"J>K\K\J] ^_&&*<<!/!:!:"0"3"3"0";";!= > &&*::!/!2!2N4M4M!O P&&-7"3N4E4E3F GH&&+5((B.##&9.:S:S9TTU$VW /&&*4111J%%%%)7)B)B)7)@)@)7)?)?'A B
 ,22
-66"))7#..J<(.*A*A>CYCY[[ 8	89 $Aa$h&F&--c!f5 $ &Aa$h&F&--c!f5 & "6~6F GHi (l __F$+ $+ $+ "$+ #
[[F))+	)K
ZL
;s*;:FFFJJ	&MJJ'',,|::<>OPK	k3	1Q			H--113<<=PQQR 
2 
-+
%&q 5h 
2	1s   R*AR//
R=__main__))testFr   )__doc__
__future__r   dataclassesrg   r   ra   r,   r3   typingtmusic21r   r   music21.testr   r   Environmentr.   	dataclassr	   rM   r   rn   r   r   r   r   <module>r      s    #   	 
      # #&&'>?	 	 	L4^V7rZ'z z 	 r   