o
    1Æ&ip  ã                   @   sâ   d dl Z d dlmZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 d dlZzd dlZW n ey9   dZY nw zd dlZW n eyK   dZY nw e edu d¡G dd„ de
ƒƒZG d	d
„ d
ej
ƒZedkroe ¡  dS dS )é    N)ÚStringIO)Útypes)ÚjitÚnjit)Úoverride_configÚTestCasez#please install the 'jinja2' packagec                   @   sN   e Zd Zejdd„ ƒZejdd„ ƒZejdd„ ƒZe 	e
du d¡d	d
„ ƒZdS )ÚTestAnnotationc                 C   sb   dd„ }t tjtjfƒ|ƒ}|j|jd  }|j}tƒ }| |¡ | ¡ }| 	¡  |  
d|¡ dS )z4
        Ensures template.html is available
        c                 S   s   |}t | ƒD ]}||7 }q|S ©N©Úrange)ÚnÚaÚsÚi© r   úGC:\wamp64\www\opt\env\Lib\site-packages\numba/tests/test_annotations.pyÚfoo   s   
z3TestAnnotation.test_exercise_code_path.<locals>.foor   r   N)r   r   Zint32Ú	overloadsÚ
signaturesÚtype_annotationr   Úhtml_annotateÚgetvalueÚcloseÚassertIn©Úselfr   ZcfuncÚcresÚtaÚbufÚoutputr   r   r   Útest_exercise_code_path   s   
z&TestAnnotation.test_exercise_code_pathc                    sˆ   dd„ ‰ ‡ fdd„}t tjfddd|ƒ}|j|jd  }|j}tƒ }| |¡ | ¡ }| 	¡  |  
d|¡ |  
d	|¡ |  
d
|¡ dS )zM
        Ensures that lifted loops are handled correctly in obj mode
        c                 S   s   | S r	   r   )Úxr   r   r   Úbar4   s   zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.barc                    sD   d}t | ƒD ]}|| }qt | ƒD ]}|| }q| r |ˆ | ƒ }|S )Ng        r
   )r!   Úhr   Úk©r"   r   r   r   7   s   

zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.fooT)ÚforceobjZloopliftr   r"   r   Z
LiftedLoopN)r   r   Zintpr   r   r   r   r   r   r   r   r   r   r%   r   Ú(test_exercise_code_path_with_lifted_loop.   s   
z7TestAnnotation.test_exercise_code_path_with_lifted_loopc           	      C   sN  t jdddd„ ƒ}t dtj¡}tjf}| |¡ |j| }tƒ }|j	 
|¡ | ¡ }| ¡  |  | d¡d¡ d}|  | | |¡¡d¡ | jtt ||¡ƒdd	||f d
 tjf}| |¡ |j| }tƒ }|j	 
|¡ | ¡ }| ¡  |  | d¡d¡ |  | | |¡¡d¡ |  | | |¡¡d¡ |  tt ||¡ƒd¡ dS )zW
        Test some format and behavior of the html annotation with lifted loop
        T)r&   c                 S   s$   t ƒ  d}t| ƒD ]}||7 }q	|S )Nr   )Úobjectr   )r!   Úzr   r   r   r   ÚudtT   s
   
z=TestAnnotation.test_html_output_with_lifted_loop.<locals>.udtz<td class="lifted_tag">\s*\s*<details>\s*<summary>\s*<code>\s*[0-9]+:\s*[&nbsp;]+for i in range\(x\):  # this line is tagged\s*zFunction name: udté   z!with signature: {} -&gt; pyobjectz%s not found in %s)Úmsgé   N)Únumbar   ÚreÚcompileÚ	MULTILINEr   Zint64r   r   r   r   r   r   ÚassertEqualÚcountÚformatÚlenÚfindallZfloat64)	r   r*   Zre_lifted_tagZsig_i64r   r   r   ZsigfmtZsig_f64r   r   r   Ú!test_html_output_with_lifted_loopO   s<   

ù



ÿ

z0TestAnnotation.test_html_output_with_lifted_loopNz%please install the 'pygments' packagec                 C   sr   t jdd„ ƒ}|ddƒ |jdd |  t¡}|jddd W d   ƒ n1 s)w   Y  |  d	t|jƒ¡ d S )
Nc                 S   s   | |fS r	   r   )r!   Úyr   r   r   r      ó   z-TestAnnotation.test_pretty_print.<locals>.foor+   r-   T)Úprettyzshould be None)r:   Úfilez$`file` must be None if `pretty=True`)r.   r   Úinspect_typesÚassertRaisesÚ
ValueErrorr   ÚstrÚ	exception)r   r   Zraisesr   r   r   Útest_pretty_printŒ   s   

ÿÿz TestAnnotation.test_pretty_print)Ú__name__Ú
__module__Ú__qualname__r   Zrun_test_in_subprocessr    r'   r7   ÚunittestÚskipIfÚpygmentsrA   r   r   r   r   r      s    

 
<r   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestTypeAnnotationc                 C   s0   t |ƒD ]\}}||v r|  S qtd |¡ƒ‚)Nzcan't find {!r})Ú	enumerater>   r4   )r   ÚlinesÚpatr   Úlnr   r   r   Ú
findpatloc    s
   ÿzTestTypeAnnotation.findpatlocc                 C   s   t ƒ }| |¡ | ¡  ¡ S r	   )r   r<   r   Ú
splitlines)r   ÚfuncZstrbufr   r   r   Úgetlines¦   s   
zTestTypeAnnotation.getlinesc                 C   sn   t jdd„ ƒ}|ddƒ |  |¡}|  |d¡}|  |d¡}|  |d¡}|  |d¡}|  ||¡ |  ||¡ d S )	Nc                 S   s   | | S r	   r   )ZappleorangeZberrycherryr   r   r   r   ¬   r9   z+TestTypeAnnotation.test_delete.<locals>.foor+   r-   z&appleorange = arg(0, name=appleorange)z&berrycherry = arg(1, name=berrycherry)zdel appleorangezdel berrycherry)r.   r   rP   rM   Ú
assertLess)r   r   rJ   ÚsaÚsbZeaZebr   r   r   Útest_delete«   s   


zTestTypeAnnotation.test_deletec                 C   s¢   t d|ƒ tdd„ ƒ}d}||ƒ}|  ||¡ W d   ƒ n1 s"w   Y  |  |¡}|  |d¡}|  |d¡}|  |d¡}|  |d¡}	|  |d	¡}
||||	|
fS )
NZEXTEND_VARIABLE_LIFETIMESc                 S   s   | }|S r	   r   )r   Úbr   r   r   r   À   s   z/TestTypeAnnotation._lifetimes_impl.<locals>.fooé
   za = arg(0, name=a)zb = azcast(value=b)zdel azdel b)r   r   r2   rP   rM   )r   Úextendr   r!   rU   rJ   rR   rS   Úcast_retÚdelaÚdelbr   r   r   Ú_lifetimes_impl¾   s   
ù
	z"TestTypeAnnotation._lifetimes_implc                 C   sJ   | j dd\}}}}}|  ||¡ |  ||¡ |  ||¡ |  ||¡ d S )Nr   ©rW   ©r[   rQ   ZassertGreater©r   rR   rS   rX   rY   rZ   r   r   r   Útest_delete_standard_lifetimesÔ   ó
   z1TestTypeAnnotation.test_delete_standard_lifetimesc                 C   sJ   | j dd\}}}}}|  ||¡ |  ||¡ |  ||¡ |  ||¡ d S )Nr+   r\   r]   r^   r   r   r   Útest_delete_extended_lifetimesç   r`   z1TestTypeAnnotation.test_delete_extended_lifetimesN)	rB   rC   rD   rM   rP   rT   r[   r_   ra   r   r   r   r   rH   ž   s    rH   Ú__main__)r/   Úior   r.   Z
numba.corer   r   r   Znumba.tests.supportr   r   rE   Zjinja2ÚImportErrorrG   rF   r   rH   rB   Úmainr   r   r   r   Ú<module>   s0    ÿÿ 	]ÿ