o
    it                     @   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   Z/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/numba/tests/test_annotations.pyfoo   s   
z3TestAnnotation.test_exercise_code_path.<locals>.foor   r   N)r   r   int32	overloads
signaturestype_annotationr   html_annotategetvaluecloseassertInselfr   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)forceobjloopliftr   r$   r   
LiftedLoopN)r   r   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   int64r   r   r   r   r   r   assertEqualcountformatlenfindallfloat64)	r   r/   re_lifted_tagsig_i64r   r    r!   sigfmt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>.foor0   r2   T)prettyzshould be None)rE   filez$`file` must be None if `pretty=True`)r3   r   inspect_typesassertRaises
ValueErrorr   str	exception)r   r   raisesr   r   r   test_pretty_print   s   

z TestAnnotation.test_pretty_print)__name__
__module____qualname__r   run_test_in_subprocessr"   r,   rB   unittestskipIfpygmentsrM   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})	enumeraterI   r:   )r   linespatr   lnr   r   r   
findpatloc   s
   zTestTypeAnnotation.findpatlocc                 C   s   t  }|| |  S r	   )r   rG   r   
splitlines)r   func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   )appleorangeberrycherryr   r   r   r      rD   z+TestTypeAnnotation.test_delete.<locals>.foor0   r2   z&appleorange = arg(0, name=appleorange)z&berrycherry = arg(1, name=berrycherry)zdel appleorangezdel berrycherry)r3   r   r^   rZ   
assertLess)r   r   rW   sasbea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 )
N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   r8   r^   rZ   )r   extendr   r#   rh   rW   rb   rc   cast_retdeladelbr   r   r   _lifetimes_impl   s   

	z"TestTypeAnnotation._lifetimes_implc                 C   sJ   | j dd\}}}}}| || | || | || | || d S )Nr   rj   rn   ra   assertGreaterr   rb   rc   rk   rl   rm   r   r   r   test_delete_standard_lifetimes   
   z1TestTypeAnnotation.test_delete_standard_lifetimesc                 C   sJ   | j dd\}}}}}| || | || | || | || d S )Nr0   ro   rp   rr   r   r   r   test_delete_extended_lifetimes   rt   z1TestTypeAnnotation.test_delete_extended_lifetimesN)	rN   rO   rP   rZ   r^   rf   rn   rs   ru   r   r   r   r   rU      s    rU   __main__)r4   ior   r3   
numba.corer   r   r   numba.tests.supportr   r   rR   jinja2ImportErrorrT   rS   r   rU   rN   mainr   r   r   r   <module>   s0     	]