
    J/Ph=t                     "   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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 d dlmZ d dl
mZmZmZmZmZmZ ddlmZ d dlmZ 	 d dlmZ n# e$ r	 d d	lmZ Y nw xY wd
 Z ed          d             Zd Z d Z! G d de"          Z# G d de
j$                  Z% G d dej&                  Z' G d de
j(                  Z)dZ*d Z+d Z,dddZ-d6dZ.d  Z/d! Z0 G d" d#e1          Z2 G d$ d%e j3                  Z4 G d& d'ej5                  Z6 G d( d)ej&                  Z7 G d* d+ej5                  Z8 G d, d-e"          Z9 G d. d/e"          Z: G d0 d1e"          Z;d2 Z<d3Z= G d4 d5ej&                  Z>dS )7    N)	lru_cache)StringIO)resultrunnersignalssuiteloadercase   )
TestLoader)config)TimeoutError)Emptyc                       fd}|S )zO
    Create a decorator allowing tests to be tagged with the *known_tags*.
    c                  J      D ]}|vrt          d|           fd}|S )z
        Tag a test method with the given tags.
        Can be used in conjunction with the --tags command-line argument
        for runtests.py.
        zunknown tag: c                 (   t          |           r/t          | t                    s| j                            d          st          d          	 | j        }n%# t          $ r t                      x}| _        Y nw xY w|	                               | S )Ntest_z(@tag(...) should be used on test methods)
callable
isinstancetype__name__
startswith	TypeErrortagsAttributeErrorsetupdate)funcsr   s     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/testing/main.pydecoratez1make_tag_decorator.<locals>.tag.<locals>.decorate+   s    TNN Ljt&<&< L}//88L JKKK&I! & & & #%DIII&HHTNNNKs   A A:9A:
ValueError)r   tr!   
known_tagss   `  r    tagzmake_tag_decorator.<locals>.tag!   sZ      	; 	;A
"" jaa!9::: #		 		 		 		 		      )r%   r&   s   ` r    make_tag_decoratorr)      s#    
    , Jr'      )maxsizec                 ~    t          t          j                            t	          j        |                               S )zF
    Gets the mtime of the file in which a test class is defined.
    )strospathgetmtimeinspectgetfile)clss    r    
_get_mtimer4   ?   s,    
 rw 4 455666r'   c                     | j         }t          |          t          |           z   }ddlm} ||                                v r.t          |j                  dt          |j                  d|}|S )a>  
    Return a key for sorting tests bases on mtime and test name. For CUDA
    tests, interleaving tests from different classes is dangerous as the CUDA
    context might get reset unexpectedly between methods of a class, so for
    CUDA tests the key prioritises the test module and class ahead of the
    mtime.
    r   )CUDATestCase. )	__class__r4   r-   numba.cuda.testingr6   mro
__module__r   )xr3   keyr6   s       r    cuda_sensitive_mtimer?   G   sy     +C
S//CFF
"C//////swwyy  ////S\1B1B1B1BCCHJr'   c                 J   t          |           r| S | sd S 	 |                     d          \  t                    t                    n"# t          $ r d| z  }t	          |          w xY wdk    rd S dk     sdk     sk    rt	          d          fd}|S )zParses the argument string "useslice" as a shard index and number and
    returns a function that filters on those arguments. i.e. input
    useslice="1:3" leads to output something like `lambda x: zlib.crc32(x) % 3
    == 1`.
    c                     dS NTr(   r=   s    r    <lambda>zparse_slice.<locals>.<lambda>b        r'   :zExpected arguments shard index and count to follow option `-j i:t`, where i is the shard number and t is the total number of shards, found '%s'r   c                     dS rB   r(   rC   s    r    rD   zparse_slice.<locals>.<lambda>n   rE   r'   zSharding out of rangec                     t          | | j                  }dt          |di           v rdS t          t          j        |                                                     d                              z  k    S )Nalways_testr   Tzutf-8)getattr_testMethodNameabszlibcrc32idencode)testr   countindexs     r    decidezparse_slice.<locals>.decider   si    4!566Dfb 9 999ttz$''))"2"27";";<<==ENNr'   )r   splitint	Exceptionr#   )useslicemsgrT   rR   rS   s      @@r    parse_slicerZ   Y   s       ~	!,,E

E

   @BJK 	 oo zz~	eaii5E>>0111	O 	O 	O 	O 	O 	O
 s   6A A0c                       e Zd ZdZd Zd ZdS )
TestListerz5Simply list available tests rather than running them.c                 .    t          |          | _        d S N)rZ   rX   )selfrX   s     r    __init__zTestLister.__init__|   s    #H--r'   c                    t          j        t          j        dd          }t	          |          | _        t          t          | j        | j                            }| j        	                    t                     |D ]#}t          |                                           $t          dt          | j                  t          |          fz             |S )NTr   )descriptions	verbosityr>   z%d tests found. %s selected)r   TextTestResultsysstderr_flatten_suite
_test_listlistfilterrX   sortr?   printrO   len)r_   rQ   r   masked_listr$   s        r    runzTestLister.run   s    &sz124 4 4(..6$-AABB!5666 	 	A!$$&&MMMM+s4?/C/C/2;/?/?/A A 	B 	B 	Br'   N)r   r<   __qualname____doc__r`   rp   r(   r'   r    r\   r\   z   s8        ??. . .
 
 
 
 
r'   r\   c                   "     e Zd ZdZ fdZ xZS )SerialSuiteaA  A simple marker to make sure tests in this suite are run serially.

    Note: As the suite is going through internals of unittest,
          it may get unpacked and stuffed into a plain TestSuite.
          We need to set an attribute on the TestCase objects to
          remember they should not be run in parallel.
    c                     t          |t          j                  s|D ]}|                     |           d S d|_        t          t          |                               |           d S )NF)r   unittestTestCaseaddTest_numba_parallel_test_superrt   )r_   rQ   r$   r9   s      r    rx   zSerialSuite.addTest   sp    $ 122 	3    Q    */D&+t$$,,T22222r'   )r   r<   rq   rr   rx   __classcell__r9   s   @r    rt   rt      sB         3 3 3 3 3 3 3 3 3r'   rt   c                   $     e Zd Zd Z fdZ xZS )BasicTestRunnerc                 \    t          j        j        | fi | t          |          | _        d S r^   )r   TextTestRunnerr`   rZ   rX   )r_   rX   kwargss      r    r`   zBasicTestRunner.__init__   s1    &t66v666#H--r'   c                    t          t          | j        t          |                              }|                    t
                     t          j        |          }t          t          |           
                    |          S )Nrd   )rj   rk   rX   rh   rl   r?   rv   	TestSuiterz   r~   rp   )r_   rQ   rp   wrappedr9   s       r    rp   zBasicTestRunner.run   sg    6$-)=)=>>??)***$S))_d++//888r'   )r   r<   rq   r`   rp   r{   r|   s   @r    r~   r~      sG        . . .9 9 9 9 9 9 9 9 9r'   r~   c                   r     e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZ fdZ fdZd Z fdZdd	Z fd
Z xZS )NumbaTestPrograma3  
    A TestProgram subclass adding the following options:
    * a -R option to enable reference leak detection
    * a --profile option to enable profiling of the test run
    * a -m option for parallel execution
    * a -l option to (only) list tests

    Currently the options are only added in 3.4+.
    FN*   c                    |                     dd           }t          |          |d<   t          j                            d           |                     dd          | _         t          t          |           j        |i | d S )Ntopleveldir
testLoaderz:xnomultiprocF)	popr   rf   warnoptionsappendr   rz   r   r`   )r_   argsr   r   r9   s       r    r`   zNumbaTestProgram.__init__   s    jj55)+66| 	t$$$!::mU;;.%%.??????r'   c           	         t          t          |                                           }| j        |                    ddddd           |                    ddd	d
t
          t          j                    d           |                    ddddd           |                    ddt          d           |                    ddt          d           |                    ddt          d           |                    dddd           |                    ddd d
t          d!d"           d# }|                    d$d%d&|d'd
d()           |S )*Nz-Rz	--refleakrefleak
store_truezDetect reference / memory leaks)destactionhelpz-mz--multiprocessmultiprocess?zParallelize tests)r   nargsr   constr   -lz--listrj   zList tests without running themz--tagsr   zAComma-separated list of tags to select a subset of the test suite)r   r   r   z--exclude-tagsexclude_tagszDComma-separated list of tags to de-select a subset of the test suitez--randomrandom_selectz$Random proportion of tests to selectz	--profileprofilezProfile the test runz-jz--slicerX   NonezShard the test sequencec                 0    | dk    rt          d          | S )Nancestorzinvalid option for --gitdiffr"   rC   s    r    git_diff_strz:NumbaTestProgram._getParentArgParser.<locals>.git_diff_str   s    J !?@@@Hr'   z-gz	--gitdiffgitdiffFzRun tests from changes made against origin/release0.61 as identified by `git diff`. If set to "ancestor", the diff compares against the common ancestor.)r   r   defaultr   r   )
rz   r   _getParentArgParser
testRunneradd_argumentrV   multiprocessing	cpu_countr-   float)r_   parserr   r9   s      r    r   z$NumbaTestProgram._getParentArgParser   s    '..BBDD?"k	'3%F   H H H 	D"2"%!$"1";"="=!4	 	 	6 	6 	6
 	D(#/!B 	 	D 	D 	D 	H6"> 	 	? 	? 	? 	,>"> 	 	? 	? 	? 	J_5!G 	 	I 	I 	IKi#/!7 	 	9 	9 	9 	D)*C!$F!: 	 	< 	< 	<	 	 	
 	D+IL$)#A 	 	C 	C 	C r'   c                    d }|D ]}||v r||}t          d|z            |5|                    |          }	 ||k    r3||dz                                            }|                    |           nAd|v r.|                    d          d                                         }nt          d          n"# t          $ r d}t          ||z            w xY w|                    d          rt          d          d|v rd}t          ||z            |d	d                              dd
          }t          | ||           |                    |           d S d S )Nzargument %s supplied repeatedlyr   =unreachablez,%s requires at least one tag to be specified-z,tag starts with '-', probably a syntax errorz1%s argument contains '=', probably a syntax error   _)
r#   rS   stripremoverU   AssertionError
IndexErrorr   replacesetattr)	r_   argvtagstrfoundr=   posntag_argsrY   attrs	            r    _handle_tagszNumbaTestProgram._handle_tags   s    	Q 	QA{{=EE$%F%OPPP	  ::e$$D/F??#D1H~3355HKK))))e||$)KK$4$4Q$7$=$=$?$?,];;; / / /D v.../
 ""3'' Q !OPPP hI v...!"":%%c3//DD$)))KK3 s   A:B7 7Cc                 "   d|v r|                     d           d| _        t          t          |                               |           t          | d          r| j                                        s!| j        f| _	        | 
                                 | j        r@d | j                            d          D             }t          | j        |d          | _        | j        r@d | j                            d          D             }t          | j        |d	          | _        | j        r%t!          | j        | j        | j                  | _        | j        d
ur$t'          | j        | j        dk              | _        | j        dk    r	d| _        d S d S )Nr   TrQ   c                 6    g | ]}|                                 S r(   r   .0r   s     r    
<listcomp>z.NumbaTestProgram.parseArgs.<locals>.<listcomp>.  s     <<<!AGGII<<<r'   ,include)modec                 6    g | ]}|                                 S r(   r   r   s     r    r   z.NumbaTestProgram.parseArgs.<locals>.<listcomp>2  s     DDD!AGGIIDDDr'   excludeFr   use_common_ancestorr   )r   rj   rz   r   	parseArgshasattrrQ   countTestCasesdefaultTest	testNamescreateTestsr   rU   _choose_tagged_testsr   r   _choose_random_testsrandom_seedr   _choose_gitdiff_testsrc   buffer)r_   r   r   r9   s      r    r   zNumbaTestProgram.parseArgs   s   4<<KKDI%%//555 tV$$ 	DI,D,D,F,F 	".0DN9 	N<<tys';';<<<D,TY9MMMDI 	NDDt'8'>'>s'C'CDDDD,TY9MMMDI 	?,TY8J-1-=? ?DI <u$$-	%)\Z%?  DI
 >Q DKKK r'   c                     d S r^   r(   )r_   r   Loaders      r    _do_discoveryzNumbaTestProgram._do_discoveryD  s	    
 	r'   c                 j     j         r6t           _        t          t          d          st          j        d           nT j        rt           j	                   _        n3 j        ,t           j	         j         j         j                   _         j        r` j        sY j        dk     rd}t!          |          t#          t$          j         j         j	         j         j         j                   _         fd} j        r t*          j                            t*          j                            t          j        d         j                            d         d	z   }t7          j        t:          j        
          }|                                 	 |                     |           |!                                 tE          d|           |#                    |           d S # |!                                 tE          d|           |#                    |           w xY w |             d S )Ngettotalrefcountz^detecting reference leaks requires a debug build of Python, only memory leaks will be detected)rc   failfastr   r   zSValue specified for the number of processes to use in running the suite must be > 0c                  V    t          t                                                     d S r^   )rz   r   runTests)r9   r_   s   r    run_tests_realz1NumbaTestProgram.runTests.<locals>.run_tests_realh  s&    "D))2244444r'   __main__r   z.prof)timerzWriting test profile data into )$r   RefleakTestRunnerr   r   rf   warningswarnrj   r\   rX   r~   rc   r   r   r   r   r#   ParallelTestRunnerr   r   r   r.   r/   splitextbasenamemodules__file__cProfileProfiletimeperf_counterenableruncalldisablerm   
dump_stats)r_   rY   r   filenamepr9   s   `    r    r   zNumbaTestProgram.runTestsK  sC   < 	B/DO3 233 O N O O O Y 	B(77DOO_$-dm8<7;}59[B B BDO
  
	ET%5 
	E 1$$4 oo%01F151B15;?>:>-8<E E EDO	5 	5 	5 	5 	5 	5 < 	w''  Z!8!ABB H  t'8999AHHJJJ'		.)))		XXGHHHX&&&&& 		XXGHHHX&&&&Ns   G) )=H&r^   )r   r<   rq   rr   r   r   r   rX   rj   r   r   r   r   r`   r   r   r   r   r   r{   r|   s   @r    r   r      s          GGLHDDLMK@ @ @ @ @+ + + + +Z" " "J" " " " "H   - - - - - - - - -r'   r   )z?numba.cuda.tests.cudapy.test_libdevice.TestLibdeviceCompilationznumba.tests.test_num_threadsz!numba.tests.test_parallel_backendznumba.tests.test_svmlznumba.tests.test_ufuncsc                     g }t          | t          j        t          t          f          r(| D ]$}|                    t          |                     %n|                    |            |S )z&
    Workhorse for _flatten_suite
    )r   rv   r   rj   tupleextend_flatten_suite_innerr   )rQ   testsr=   s      r    r   r     sp     E$+T59::  	2 	2ALL-a001111	2 	TLr'   c                 X   t          |           }t                      }|D ]2}t          D ](}|t          |          v r|                    |           )3t          |          |z
  }d }t          ||          }|                    t          t          |          |                     |S )z6
    Expand nested suite into list of test cases.
    c                 D    | j         t          |           j        | j        fS r^   )r<   r   r   rK   rC   s    r    r>   z_flatten_suite.<locals>.key  s    |T!WW-q/@@@r'   rd   )r   r   
_GENERATEDr-   addsortedr   rj   )rQ   r   	generatedr$   gnormalr>   s          r    rh   rh     s     !&&E I ! ! 	! 	!ACFF{{a   	! ZZ)#FA A A6s###E	LLYS111222Lr'   Fr   c                  	 	 ddl m} n# t          $ r t          d          w xY w |d          	t          j                            dd          }|rt          d           d}nd	}	j                             ||d
          	                                }d |D             }g }	fd|D             }t          |           D ]P}t          |t          j                  sJ t          j        |j                  }||v r|                    |           Qt          dt%          |          z             t          j        |          S )Nr   )Repoz&gitpython needed for git functionalityr7   numbar   zGit diff by common ancestorzorigin/release0.61...HEADzorigin/release0.61..HEADT)	name_onlyc                 L    g | ]!}t           j                            |          "S r(   )r.   r/   normpath)r   r=   s     r    r   z)_choose_gitdiff_tests.<locals>.<listcomp>  s(    <<<127##A&&<<<r'   c                 Z    g | ]'}t           j                            j        |          (S r(   )r.   r/   joinworking_dir)r   r=   repos     r    r   z)_choose_gitdiff_tests.<locals>.<listcomp>  s,    JJJ27<< 0!44JJJr'   zGit diff identified %s tests)gitr  ImportErrorr#   r.   r/   r  rm   diffrU   rh   r   rv   rw   r1   getsourcefiler9   r   rn   r   )
r   r   r  r/   targetgdiff_pathsselectedrQ   fnamer	  s
            @r    r   r     sr   C C C CABBBC499D7<<))D ,,---,+(---==CCEEK<<<<<KHJJJJkJJJKu%% " "$ 122222%dn55KOOD!!!	
(3x==
8999h'''s   
 $r   c                    g }t          |          }t          |           D ]}t          |t          j                  sJ t          ||j                  }	 |j        }n# t          $ r Y nw xY wt          |dd          }|dk    r|||z  r|	                    |           |dk    r|||z  s|	                    |           t          d|z            t          j        |          S )z
    Select tests that are tagged/not tagged with at least one of the given tags.
    Set mode to 'include' to include the tests with tags, or 'exclude' to
    exclude the tests with the tags.
    r   Nr   r   zInvalid 'mode' supplied: %s.)r   rh   r   rv   rw   rJ   rK   im_funcr   r   r#   r   )r   r   r   r  rQ   r   
found_tagss          r    r   r     s    Ht99Du%% D D$ 122222tT122	<DD 	 	 	D	 T6400
9%*t*;%%%%Y!*t*;!%%%;dBCCCh'''s   A
A*)A*c                 V   t          j                    }|                    |           t          | t          j                  rt          |           } |                    | t          t          |           |z                      } t          | d           } t	          j        |           S )z7
    Choose a given proportion of tests at random.
    c                       | j                     S r^   rO   )r
   s    r    rD   z&_choose_random_tests.<locals>.<lambda>  s    74799 r'   rd   )randomRandomseedr   rv   r   rh   samplerV   rn   r   )r   ratior  rnds       r    r   r     s     -//CHHTNNN%+,, &u%%JJuc#e**u"45566E544555Ee$$$r'   c                  ^   t           j        } 	 t           j        }n# t          $ r d }Y nw xY wt           j        t           j        t           j        t           j        fD ]}||                                 t          j	                     t          j                      |              |            fS )Nc                      dS )Nr   r(   r(   r'   r    rD   z"_refleak_cleanup.<locals>.<lambda>  s     r'   )rf   getallocatedblocksr   r   stdoutrg   
__stdout__
__stderr__flush_clear_type_cachegccollect)func1func2streams      r    _refleak_cleanupr+    s    "E$   

 :sz3>3>J  LLNNNJLLL577EEGGs    ++c                       e Zd ZdS )ReferenceLeakErrorN)r   r<   rq   r(   r'   r    r-  r-  	  s        Dr'   r-  c                       e Zd Zd ZdS )IntPoolc                     |S r^   r(   )r_   r>   s     r    __missing__zIntPool.__missing__  s    
r'   N)r   r<   rq   r1  r(   r'   r    r/  r/    s#            r'   r/  c                   ,     e Zd ZdZdZd Z fdZ xZS )RefleakTestResult      c                 p   | j                                          | j        }| j        }dg||z
  z  }dg||z
  z  }t	                      }t          dd          D ]
}||          t          |          D ]}t          j                    }|                    |           |	                                sE| j
                            |j
                   | j                            |j                   t          ~t                      \  }	}
||k    r"||
|z
           |||z
  <   ||	|z
           |||z
  <   |	|
}}||fS )Nr   i8   )r*  r$  repetitionswarmupr/  ranger   
TestResultrp   wasSuccessfulfailuresr   errorsr   r+  )r_   rQ   repcountnwarmup	rc_deltasalloc_deltas	_int_pooliresalloc_afterrc_after	rc_beforealloc_befores                r    
_huntLeakszRefleakTestResult._huntLeaks  sV   #+C8g-.	sh01 II	tS!! 	 	AaLLLx 	< 	<A#%%CHHSMMM $$&& %$$S\222""3:...$$$4$6$6!KG||)28i3G)H	!g+&,5kL6P,QQ[)&18)LL,&&r'   c           
      B   	 |                      |          \  }}n'# t          $ r |                                 rJ Y d S w xY wd }d }d}|d|f|d|ffD ]\  }}}	 |	|          r|d|d|dt          |          }
d	}	 t	          |
          # t
          $ r t          j                    }Y nw xY w| j        r | j	        
                    |d
|d           |                     ||           |s*t          t          |                               |           d S d S )Nc                      t          |           S r^   )anydeltass    r    check_rc_deltasz5RefleakTestResult.addSuccess.<locals>.check_rc_deltas@  s    v;;r'   c                     d|                      d          z  t          |           k     rdS t          |           t          d          k    sdS dS )Nr4  r   T)r   r   F)rR   rn   r   rN  s    r    check_alloc_deltasz8RefleakTestResult.addSuccess.<locals>.check_alloc_deltasC  sH    6<<??"S[[00tv;;#j//11t5r'   F
referenceszmemory blocksz leaked r8   z, sum=Tz = )rJ  r   r<  sumr-  rW   rf   exc_infoshowAllr*  write
addFailurerz   r3  
addSuccess)r_   rQ   rA  rB  rP  rS  failedrO  	item_namecheckerrY   rV  r9   s               r    rZ  zRefleakTestResult.addSuccess7  s   	&*ood&;&;#I|| 	 	 	))+++++FF		 	 		 	 	  o6?,>?+A 	0 	0&FIw wv 
0DD&&&)))S[[[:.,S111  . . ."|~~HHH.< HK%%IIIvvv&FGGGh/// 	<#T**55d;;;;;	< 	<s      A A BB21B2)r   r<   rq   r9  r8  rJ  rZ  r{   r|   s   @r    r3  r3    sQ        FK' ' '>'< '< '< '< '< '< '< '< '<r'   r3  c                       e Zd ZeZdS )r   N)r   r<   rq   r3  resultclassr(   r'   r    r   r   a  s        #KKKr'   r   c                       e Zd ZdZd ZdS )ParallelTestResultzA
    A TestResult able to inject results from other results.
    c                    | j                             |j                                                    | j                                          | xj        |j        z  c_        | j                            |j                   | j                            |j                   | j                            |j                   | j	                            |j	                   | j
                            |j
                   dS )zI
        Add the results from the other *result* to this result.
        N)r*  rX  getvaluer$  testsRunr=  r   r>  skippedexpectedFailuresunexpectedSuccesses)r_   r   s     r    add_resultszParallelTestResult.add_resultsj  s     	&-0022333(V_---6=)))FN+++$$V%<=== ''(BCCCCCr'   N)r   r<   rq   rr   rh  r(   r'   r    ra  ra  e  s2         D D D D Dr'   ra  c                   $    e Zd ZdZdZd ZddZdS )_MinimalResultz7
    A minimal, picklable TestResult-alike object.
    )	r=  r>  re  rf  rg  r*  
shouldStoprd  test_idc                     d|_         dS )zR
        Remove any unpicklable attributes from TestCase instance *case*.
        N)_outcomeForDoCleanups)r_   r
   s     r    
fixup_casez_MinimalResult.fixup_case  s    
 &*"""r'   Nc           
      4   | j         D ]"}t          | |t          ||d                      #| j        D ]\  }}|                     |           | j        D ]\  }}|                     |           | j        D ]\  }}|                     |           || _        d S r^   )	__slots__r   rJ   rf  ro  r>  r=  rl  )r_   original_resultrl  r   r
   r   s         r    r`   z_MinimalResult.__init__  s    N 	F 	FDD$t D DEEEE, 	" 	"GD!OOD!!!!{ 	" 	"GD!OOD!!!!} 	" 	"GD!OOD!!!!r'   r^   )r   r<   rq   rr   rq  ro  r`   r(   r'   r    rj  rj  x  sH         I
* * *	 	 	 	 	 	r'   rj  c                       e Zd ZdZd Zd ZdS )_FakeStringIOz:
    A trivial picklable StringIO-alike for Python 2.
    c                     || _         d S r^   _value)r_   values     r    r`   z_FakeStringIO.__init__  s    r'   c                     | j         S r^   rv  )r_   s    r    rc  z_FakeStringIO.getvalue  s
    {r'   N)r   r<   rq   rr   r`   rc  r(   r'   r    rt  rt    s<               r'   rt  c                   >    e Zd ZdZd Zd Zej        d             ZdS )_MinimalRunnerzu
    A minimal picklable object able to instantiate a runner in a
    child process and run a test case with it.
    c                 "    || _         || _        d S r^   )
runner_clsrunner_args)r_   r}  r~  s      r    r`   z_MinimalRunner.__init__  s    $&r'   c                    | j         }t                      |d<    | j        di |} |j                    }t	          j                     t	          j        |           |j        |_        |j        |_        | 	                    |          5   ||           d d d            n# 1 swxY w Y   t          |j                                                  |_        t          ||                                          S )Nr*  r(   )r~  r   r}  _makeResultr   installHandlerregisterResultr   r   cleanup_objectrt  r*  rc  rj  rO   )r_   rQ   r   r   r   s        r    __call__z_MinimalRunner.__call__  s    ! $::x **6**##%%   v&&& /  && 	 	DLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &fm&<&<&>&>??fdggii000s   	B!!B%(B%c              #      K   t          |j                  }	 |V  t          |j                  |z
  }|D ]
}|j        |= dS # t          |j                  |z
  }|D ]
}|j        |= w xY w)zu
        A context manager which cleans up unwanted attributes on a test case
        (or any other object).
        N)r   __dict__)r_   rQ   vanilla_attrsspurious_attrsnames        r    r  z_MinimalRunner.cleanup_object  s       DM**	(JJJ //-?N& ( (M$''( ( !//-?N& ( (M$''(s   A &A(N)	r   r<   rq   rr   r`   r  
contextlibcontextmanagerr  r(   r'   r    r{  r{    s[         
' ' '1 1 1& ( ( ( ( (r'   r{  c                     g }g }g t          |t          |                     }d }|D ]8} ||          r|                    |           #|                    |           9||fS )z:
    Split test suite into parallel and serial tests.
    c                     | j         }t          | |          }|j        |k    r|j        dk    rdS t          | dd          S )NtestFailureFry   T)rK   rJ   r   )rQ   method_namemethods      r    is_parallelizable_test_casez=_split_nonparallel_tests.<locals>.is_parallelizable_test_case  sL     *{++?k))fo.N.N5t4d;;;r'   )rk   rh   r   )rQ   slicedptestsstestsflatr  r$   s          r    _split_nonparallel_testsr    s     FF2VFN400112D< < <   &&q)) 	MM!MM!6>r'   iX  c                   <     e Zd ZdZeZeZd Zd Z	d Z
 fdZ xZS )r   z\
    A test runner which delegates the actual running to a pool of child
    processes.
    c                     t          j        j        | fi | || _        || _        t          |          | _        || _        d S r^   )r   r   r`   r}  nprocsrZ   rX   r~  )r_   r}  r  rX   r   s        r    r`   zParallelTestRunner.__init__  sI    &t66v666$#H--!r'   c                     t           j         j                  }d fdt          dt	           j                            D             }|D ]}t          j         j                  }	  	                    ||||           |j
        r+|                                 	 |                                  n^|                                 n#  |                                  xY w	 |                                 # |                                 w xY w|j
        s+t           j                  }|                    |           |S d S )Nd   c                 4    g | ]}j         ||z            S r(   )_ptests)r   rD  
chunk_sizer_   s     r    r   z1ParallelTestRunner._run_inner.<locals>.<listcomp>  s?     L L L ,qZ'78 L L Lr'   r   )r{  r}  r~  r:  rn   r  r   Poolr  _run_parallel_testsrk  	terminater  closert   _stestsrp   )r_   r   child_runnersplitted_testsr   poolr  r  s   `      @r    
_run_innerzParallelTestRunner._run_inner  sq    &dot7GHH 
L L L L L#(C,=,=z#J#JL L L $ 	 	E"'44D((|UKKK $ !NN$$$
 		 JJLLLL    ! 				  	 ..FJJvM	 	s$   -CC<7C<C##C<<Dc                    t          d |D                       }|                    t                     |                    ||          }	 	 |                    | j                  } |j        |           |                    |j                   |j	        r	d|_	        d S ng# t          $ r Y d S t          $ rN}dd                    d t          |          D                       z  }	|	f|j        dd          z   |_        |d }~ww xY w)Nc              3   >   K   | ]}|                                 V  d S r^   r  )r   r$   s     r    	<genexpr>z9ParallelTestRunner._run_parallel_tests.<locals>.<genexpr>!  s*      22qADDFF222222r'   rd   Tz3Tests didn't finish before timeout (or crashed):
%s c              3       K   | ]	}d |z  V  
dS )z- %r
Nr(   )r   tids     r    r  z9ParallelTestRunner._run_parallel_tests.<locals>.<genexpr>,  s&       Q QCC Q Q Q Q Q Qr'   r   )r   rl   r?   imap_unordered__next__timeoutrh  discardrl  rk  StopIterationr   r  r   r   )
r_   r   r  r  r   remaining_idsitchild_resulterY   s
             r    r  z&ParallelTestRunner._run_parallel_tests   s=   22E22222

+
,,,  u55	!{{4<88 #"<000%%l&:;;;* (,F%F !      M Q Q6-;P;P Q Q QQQR !&*,	s   B" "
D/	D8A	DDc                    t          || j                  \  | _        | _        t	          dt          | j                  dt          | j                             t          t          |                               | j	                  S )Nz
Parallel: z
. Serial: )
r  rX   r  r  rm   rn   rz   r   rp   r  )r_   rQ   r9   s     r    rp   zParallelTestRunner.run7  s    %=d>Bm&M &M"dlC,=,=,=,=,/,=,=,=? 	@ 	@ 	@ '..224?CCCr'   )r   r<   rq   rr   ra  r_  _TIMEOUTr  r`   r  r  rp   r{   r|   s   @r    r   r     s         
 %KG" " "     D  .D D D D D D D D Dr'   r   )r   )?collectionsr  r   r1   r&  r   r.   r  rf   r   rv   r   rM   	functoolsr   ior   r   r   r   r   r	   r
   r   
numba.corer   r   r  Queuer   r)   r4   r?   rZ   objectr\   r   rt   r   r~   mainr   r   r   rh   r   r   r   r+  RuntimeErrorr-  defaultdictr/  re   r3  r   ra  rj  rt  r{  r  r  r   r(   r'   r    <module>r     s             				     				  



                 A A A A A A A A A A A A A A A A            ,,,,,,,, , , ,++++++++,  F 37 7 7  $  B       $3 3 3 3 3($ 3 3 3(	9 	9 	9 	9 	9f+ 	9 	9 	9I I I I Ix} I I Ib

 
 
  . 9> ( ( ( ( (2( ( ( (>
% 
% 
%   (	 	 	 	 	 	 	 	    k%   K< K< K< K< K<- K< K< K<\$ $ $ $ $- $ $ $D D D D D. D D D&    V   :	 	 	 	 	F 	 	 	,( ,( ,( ,( ,(V ,( ,( ,(^  8 PD PD PD PD PD. PD PD PD PD PDs   A% %A32A3