o
    D2h3                  
   @   s  d dl Z d dlZd dlZd dlm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mZmZ G dd de
jZee
_dd ZG dd	 d	eZG d
d de jZG dd dejZG dd dejZdd ZG dd dejZG dd deZG dd deZG dd deZG dd dejZ zd dl!Z!W n
 e"y   Y dS w ze!#  W dS  e$y Z% zdZ&e'e&j(e%d W Y dZ%[%dS dZ%[%ww )    N)StringIO)resultrunnersignalsc                       s\   e Zd ZdZdZdZdZ fddZ fddZ fddZ	 fd	d
Z
 fddZ  ZS )NumbaTestProgramz
    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

    Currently the options are only added in 3.4+.
    Fc                    s4   | dd | _tjd tt| j|i | d S )Nsuitez:x)popdiscovered_suitesyswarnoptionsappendsuperr   __init__)selfargskwargs	__class__ l/var/www/html/alexa/alex_system/speach-to-text/venv/lib/python3.10/site-packages/llvmlite/tests/customize.pyr   !   s   zNumbaTestProgram.__init__c                    s(   | j d ur| j | _d S tt|   d S N)r	   testr   r   createTestsr   r   r   r   r   (   s   
zNumbaTestProgram.createTestsc                    sV   t t|  }| jd u r|jdddddd |jddd	dd
d |jddddd |S )N-Rz	--refleakrefleak
store_truezDetect reference / memory leaks)destactionhelp-mz--multiprocessmultiprocesszParallelize testsz	--profileprofilezProfile the test run)r   r   _getParentArgParser
testRunneradd_argument)r   parserr   r   r   r#   .   s   


z$NumbaTestProgram._getParentArgParserc                    sb   t jdk rd|v r|d d| _d|v r|d d| _tt| | | jdkr/d| _	d S d S )N)      r   Tr    r   )
r
   version_inforemover   r!   r   r   	parseArgs	verbositybuffer)r   argvr   r   r   r+   ?   s   




zNumbaTestProgram.parseArgsc              	      s    j rt _ttdstd n	 jd u rtj _ j	r*t
 j j j jd _ fdd} jr{tjtjtjd jd d }tjtjd	}|  z|| W |  td
|f  || d S |  td
|f  || w |  d S )Ngettotalrefcountz^detecting reference leaks requires a debug build of Python, only memory leaks will be detected)r,   failfastr-   c                      s   t t  d S r   )r   r   runTestsr   )r   r   r   r   run_tests_real`   s   z1NumbaTestProgram.runTests.<locals>.run_tests_real__main__r   z.prof)timerz!Writing test profile data into %r)r   RefleakTestRunnerr$   hasattrr
   warningswarnunittestTextTestRunnerr!   ParallelTestRunnerr,   r0   r-   r"   ospathsplitextbasenamemodules__file__cProfileProfiletimeperf_counterenableruncalldisableprint
dump_stats)r   r2   filenamepr   r   r   r1   N   sB   



zNumbaTestProgram.runTests)__name__
__module____qualname____doc__r   r"   r!   r   r   r#   r+   r1   __classcell__r   r   r   r   r      s    r   c                  C   s   zt j} W n ty   dd } Y nw zt j}W n ty%   dd }Y nw t jt jt jt jfD ]
}|d ur:|  q0t 	  t
  |  | fS )Nc                   S      dS N*   r   r   r   r   r   func1      z_refleak_cleanup.<locals>.func1c                   S   rR   rS   r   r   r   r   r   func2   rV   z_refleak_cleanup.<locals>.func2)r
   getallocatedblocksAttributeErrorr/   stdoutstderr
__stdout__
__stderr__flush_clear_type_cachegccollect)rU   rW   streamr   r   r   _refleak_cleanup{   s"   

rc   c                   @   s   e Zd ZdS )ReferenceLeakErrorN)rM   rN   rO   r   r   r   r   rd      s    rd   c                   @   s   e Zd Zdd ZdS )IntPoolc                 C   s   |S r   r   )r   keyr   r   r   __missing__   rV   zIntPool.__missing__N)rM   rN   rO   rg   r   r   r   r   re      s    re   c                       s,   e Zd ZdZdZdd Z fddZ  ZS )RefleakTestResultr'      c                 C   s   | j   | j}| j}dg||  }dg||  }t }tddD ]}||  q!d }}	t|D ]B}t }
||
 |
	 sO| j
|
j
 | j|
j t~
t \}}||krm|||	  ||| < |||  ||| < ||}}	q0||fS )Nr   i8   )rb   r^   repetitionswarmupre   ranger   
TestResultrunwasSuccessfulfailuresextenderrorsAssertionErrorrc   )r   r   repcountnwarmup	rc_deltasalloc_deltas	_int_poolialloc_before	rc_beforeresalloc_afterrc_afterr   r   r   
_huntLeaks   s8   



zRefleakTestResult._huntLeaksc              	      s   z	|  |\}}W n ty   |  rJ Y d S w dd }dd }d}|d|f|d|ffD ]:\}}}	|	|rhd|||t|f }
d	}zt|
 tyT   t }Y nw | jrb| j	
d
||f  | || q.|sutt| | d S d S )Nc                 S   s   t | S r   )anydeltasr   r   r   check_rc_deltas   s   z5RefleakTestResult.addSuccess.<locals>.check_rc_deltasc                 S   s2   d|  d t| k rdS t| tdksdS dS )Nr'   r   T)   r   F)countlensetr   r   r   r   check_alloc_deltas   s
   z8RefleakTestResult.addSuccess.<locals>.check_alloc_deltasF
referenceszmemory blocksz%s leaked %s %s, sum=%sTz%s = %r )r   rt   rp   sumrd   	Exceptionr
   exc_infoshowAllrb   write
addFailurer   rh   
addSuccess)r   r   rw   rx   r   r   failedr   	item_namecheckermsgr   r   r   r   r      s:   	zRefleakTestResult.addSuccess)rM   rN   rO   rl   rk   r   r   rQ   r   r   r   r   rh      s
    "rh   c                   @   s   e Zd ZeZdS )r5   N)rM   rN   rO   rh   resultclassr   r   r   r   r5      s    r5   c                 C   s2   t | tjrg }| D ]	}|t| q
|S | gS )z$Expand suite into list of tests
    )
isinstancer9   	TestSuiterr   _flatten_suite)r   testsxr   r   r   r      s   r   c                   @   s   e Zd ZdZdd ZdS )ParallelTestResultzA
    A TestResult able to inject results from other results.
    c                 C   sv   | j |j   | j   |  j|j7  _| j|j | j|j | j|j | j	|j	 | j
|j
 dS )zI
        Add the results from the other *result* to this result.
        N)rb   r   getvaluer^   testsRunrq   rr   rs   skippedexpectedFailuresunexpectedSuccesses)r   r   r   r   r   add_results  s   
zParallelTestResult.add_resultsN)rM   rN   rO   rP   r   r   r   r   r   r      s    r   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )_MinimalResultz7
    A minimal, picklable TestResult-alike object.
    )rq   rs   r   r   r   rb   
shouldStopr   c                 C   s
   d|_ dS )zR
        Remove any unpicklable attributes from TestCase instance *case*.
        N)_outcomeForDoCleanups)r   caser   r   r   
fixup_case  s   
z_MinimalResult.fixup_casec                 C   sp   | j D ]}t| |t|| q| jD ]	\}}| | q| jD ]	\}}| | q| jD ]	\}}| | q,d S r   )	__slots__setattrgetattrr   r   rs   rq   )r   original_resultattrr   _r   r   r   r   "  s   
z_MinimalResult.__init__N)rM   rN   rO   rP   r   r   r   r   r   r   r   r     s
    r   c                   @   s    e Zd ZdZdd Zdd ZdS )_FakeStringIOz:
    A trivial picklable StringIO-alike for Python 2.
    c                 C   s
   || _ d S r   _value)r   valuer   r   r   r   2  s   
z_FakeStringIO.__init__c                 C   s   | j S r   r   r   r   r   r   r   5  s   z_FakeStringIO.getvalueN)rM   rN   rO   rP   r   r   r   r   r   r   r   -  s    r   c                   @   s.   e Zd ZdZdd Zdd Zejd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                 C   s   || _ || _d S r   )
runner_clsrunner_args)r   r   r   r   r   r   r   ?  s   
z_MinimalRunner.__init__c                 C   s   | j }t |d< | jdi |}| }t  t| |j|_|j|_| 	| || W d    n1 s9w   Y  t
|j |_t|S )Nrb   r   )r   r   r   _makeResultr   installHandlerregisterResultr0   r-   cleanup_objectr   rb   r   r   )r   r   r   r   r   r   r   r   __call__F  s   


z_MinimalRunner.__call__c              	   c   s\    t |j}z|V  W t |j| }|D ]}|j|= qdS t |j| }|D ]}|j|= q&w )zu
        A context manager which cleans up unwanted attributes on a test case
        (or any other object).
        N)r   __dict__)r   r   vanilla_attrsspurious_attrsnamer   r   r   r   Y  s   


z_MinimalRunner.cleanup_objectN)	rM   rN   rO   rP   r   r   
contextlibcontextmanagerr   r   r   r   r   r   9  s    r   c                       s4   e Zd ZdZeZdd Zdd Z fddZ  Z	S )r;   z\
    A test runner which delegates the actual running to a pool of child
    processes.
    c                 K   s$   t jj| fi | || _|| _d S r   )r   r:   r   r   r   )r   r   r   r   r   r   r   p  s   
zParallelTestRunner.__init__c                 C   sl   t | j| j}t }|j}z||| jD ]}|| |jr! nq|W |	  |
  S |	  |
  w r   )r   r   r   multiprocessingPoolimap_unordered
_test_listr   r   	terminatejoin)r   r   child_runnerpoolimapchild_resultr   r   r   
_run_inneru  s   


zParallelTestRunner._run_innerc                    s   t || _tt| | jS r   )r   r   r   r;   ro   r   )r   r   r   r   r   ro     s   
zParallelTestRunner.run)
rM   rN   rO   rP   r   r   r   r   ro   rQ   r   r   r   r   r;   h  s    r;   z+Failed to enable faulthandler due to:
{err})err))collectionsr   rB   ior   r`   r<   r   r
   rD   r9   r7   r   r   r   mainr   rc   RuntimeErrorrd   defaultdictre   TextTestResultrh   r:   r5   r   r   objectr   r   r   r;   faulthandlerImportErrorrF   BaseExceptioner   r8   formatr   r   r   r   <module>   sJ   aQ/% 