o
    i                     @   s   d dl Z d dlmZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlZzd dlZW n ey?   dZY nw zd dlZW n eyQ   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rue  dS dS )    N)StringIO)compile_isolatedFlags)types)njit)override_configTestCasez#please install the 'jinja2' packagec                   @   s<   e Zd Zdd Zdd Zdd Zeedu 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   |}t | D ]}||7 }q|S Nrange)nasi r   k/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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 r
   r   )xr   r   r   bar2   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   5   s   

zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.fooT)flagsr    r   Z
LiftedLoopN)r   Zenable_pyobjectZenable_loopliftr   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}t| D ]}||7 }q	|S )Nr   )objectr   )r   zr   r   r   r   udtS   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   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)r8   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   r%   r5   unittestskipIfpygmentsr?   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<   r2   )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      r7   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   rN   rK   
assertLess)r   r   rH   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   r0   rN   rK   )r   extendr   r   rS   rH   rP   rQ   cast_retdeladelbr   r   r   _lifetimes_impl   s   

	z"TestTypeAnnotation._lifetimes_implc                 C   sJ   | j dd\}}}}}| || | || | || | || d S )Nr   rU   rY   rO   ZassertGreaterr   rP   rQ   rV   rW   rX   r   r   r   test_delete_standard_lifetimes   
   z1TestTypeAnnotation.test_delete_standard_lifetimesc                 C   sJ   | j dd\}}}}}| || | || | || | || d S )Nr)   rZ   r[   r\   r   r   r   test_delete_extended_lifetimes   r^   z1TestTypeAnnotation.test_delete_extended_lifetimesN)	r@   rA   rB   rK   rN   rR   rY   r]   r_   r   r   r   r   rF      s    rF   __main__)r-   ior   r,   Znumba.core.compilerr   r   Z
numba.corer   r   Znumba.tests.supportr   r   rC   Zjinja2ImportErrorrE   rD   r	   rF   r@   mainr   r   r   r   <module>   s2     ]