B
      ›\  ã               @   sì   d dl mZmZ d dl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mZ yd dlZW n ek
r|   dZY nX yd dlZW n ek
r¢   dZY nX e edkd¡G dd	„ d	ejƒƒZG d
d„ dejƒZedkrèe ¡  dS )é    )Úabsolute_importÚdivisionN)Úunittest_support)Úcompile_isolatedÚFlags)ÚtypesÚutils)ÚStringIOz#please install the 'jinja2' packagec               @   s<   e Zd Zdd„ Zdd„ Zdd„ Ze edkd¡d	d
„ ƒZ	dS )ÚTestAnnotationc             C   sP   dd„ }t |tjtjgƒ}|j}tƒ }| |¡ | ¡ }| ¡  |  d|¡ dS )z4
        Ensures template.html is available
        c             S   s"   |}xt | ƒD ]}||7 }qW |S )N)Úrange)ÚnÚaÚsÚi© r   ú;lib/python3.7/site-packages/numba/tests/test_annotations.pyÚfoo   s    z3TestAnnotation.test_exercise_code_path.<locals>.foor   N)	r   r   Zint32Útype_annotationr	   Úhtml_annotateÚgetvalueÚcloseÚassertIn)Úselfr   ÚcresÚtaÚbufÚoutputr   r   r   Útest_exercise_code_path   s    
z&TestAnnotation.test_exercise_code_pathc                sŽ   dd„ ‰ ‡ fdd„}t ƒ }| d¡ | d¡ t|tjg|d}|j}tƒ }| |¡ | ¡ }| 	¡  |  
d|¡ |  
d	|¡ |  
d
|¡ dS )zM
        Ensures that lifted loops are handled correctly in obj mode
        c             S   s   | S )Nr   )Úxr   r   r   Úbar1   s    zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.barc                s2   d}xt | ƒD ]}|| }qW | r.|ˆ | ƒ }|S )Ng        )r   )r   ÚhÚk)r   r   r   r   4   s    zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.fooZenable_pyobjectZenable_looplift)Úflagsr   r   Z
LiftedLoopN)r   Úsetr   r   Zintpr   r	   r   r   r   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   sH  t j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
        c             S   s(   t ƒ  d}xt| ƒD ]}||7 }qW |S )Nr   )Úobjectr   )r   Úzr   r   r   r   ÚudtP   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)ÚnumbaZjitÚreÚcompileÚ	MULTILINEr   Zint64Z	overloadsr	   r   r   r   r   Z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_loopL   s6    	



z0TestAnnotation.test_html_output_with_lifted_loopNz%please install the 'pygments' packagec          	   C   s^   t jdd„ ƒ}|ddƒ |jdd}|  t¡}|jddd}W d Q R X |  d	t|jƒ¡ d S )
Nc             S   s   | |fS )Nr   )r   Úyr   r   r   r   ‹   s    z-TestAnnotation.test_pretty_print.<locals>.foor(   r*   T)Úprettyzshould be None)r5   Úfilez$`file` must be None if `pretty=True`)r+   ÚnjitÚinspect_typesZassertRaisesÚ
ValueErrorr   ÚstrZ	exception)r   r   ÚobjZraisesr   r   r   Útest_pretty_printˆ   s    
z TestAnnotation.test_pretty_print)
Ú__name__Ú
__module__Ú__qualname__r   r$   r3   ÚunittestÚskipIfÚpygmentsr<   r   r   r   r   r
      s    <r
   c               @   s   e Zd Zdd„ ZdS )ÚTestTypeAnnotationc                s~   t jdd„ ƒ}|ddƒ t ¡ }| |¡ | ¡  ¡ ‰ ‡ fdd„}|dƒ}|dƒ}|d	ƒ}|d
ƒ}|  ||¡ |  ||¡ d S )Nc             S   s   | | S )Nr   )ZappleorangeZberrycherryr   r   r   r   ›   s    z+TestTypeAnnotation.test_delete.<locals>.foor(   r*   c                s4   x t ˆ ƒD ]\}}| |kr
|S q
W td | ¡ƒ‚d S )Nzcan't find {!r})Ú	enumerater9   r0   )Zpatr   Zln)Úlinesr   r   Ú
findpatloc¦   s    z2TestTypeAnnotation.test_delete.<locals>.findpatlocz&appleorange = arg(0, name=appleorange)z&berrycherry = arg(1, name=berrycherry)zdel appleorangezdel berrycherry)r+   r7   r   r	   r8   r   Ú
splitlinesZ
assertLess)r   r   ZstrbufrF   ZsaZsbZeaZebr   )rE   r   Útest_deleteš   s    

zTestTypeAnnotation.test_deleteN)r=   r>   r?   rH   r   r   r   r   rC   ™   s   rC   Ú__main__)Z
__future__r   r   r,   r+   r   r@   Znumba.compilerr   r   r   r   Znumba.io_supportr	   Zjinja2ÚImportErrorrB   rA   ZTestCaser
   rC   r=   Úmainr   r   r   r   Ú<module>   s(   


 