
    ܙd                     P   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	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY w ej        edu d           G d d	e                      Z G d
 dej                  Zedk    r ej                     dS dS )    N)StringIO)compile_isolatedFlags)types)njit)override_configTestCasez#please install the 'jinja2' packagec                   X    e Zd Zd Zd Zd Z ej        edu d          d             Z	dS )TestAnnotationc                 (   d }t          |t          j        t          j        g          }|j        }t	                      }|                    |           |                                }|                                 |                     d|           dS )z4
        Ensures template.html is available
        c                 8    |}t          |           D ]}||z  }|S Nrange)nasis       <lib/python3.11/site-packages/numba/tests/test_annotations.pyfooz3TestAnnotation.test_exercise_code_path.<locals>.foo   s,    A1XX  QH    r   N)	r   r   int32type_annotationr   html_annotategetvaluecloseassertIn)selfr   crestabufoutputs         r   test_exercise_code_pathz&TestAnnotation.test_exercise_code_path   s    
	 	 	  ek5;%?@@!jj
		eV$$$$$r   c                    d fd}t                      }d|_        d|_        t          |t          j        g|          }|j        }t                      }|                    |           |	                                }|
                                 |                     d|           |                     d|           |                     d|           dS )	zM
        Ensures that lifted loops are handled correctly in obj mode
        c                     | S r    )xs    r   barzDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.bar2   s    Hr   c                     d}t          |           D ]}||z   }t          |           D ]}||z   }| r| |           z
  }|S )Ng        r   )r'   hr   kr(   s       r   r   zDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.foo5   sf    A1XX  E1XX  E AJHr   T)flagsr(   r   
LiftedLoopN)r   enable_pyobjectenable_loopliftr   r   intpr   r   r   r   r   r   )r   r   r,   r   r    r!   r"   r(   s          @r   (test_exercise_code_path_with_lifted_loopz7TestAnnotation.test_exercise_code_path_with_lifted_loop-   s    
	 	 		 	 	 	 	  $ $ej\???!jj
		eV$$$eV$$$lF+++++r   c                 `   t           j        d             }t          j        dt          j                  }t
          j        f}|                    |           |j        |         }t                      }|j	        
                    |           |                                }|                                 |                     |                    d          d           d}|                     |                    |                    |                    d           |                     t!          t          j        ||                    d|d|           t
          j        f}|                    |           |j        |         }t                      }|j	        
                    |           |                                }|                                 |                     |                    d          d           |                     |                    |                    |                    d           |                     |                    |                    |                    d           |                     t!          t          j        ||                    d           d	S )
zW
        Test some format and behavior of the html annotation with lifted loop
        c                 T    t                       d}t          |           D ]}||z  }|S )Nr   )objectr   )r'   zr   s      r   udtz=TestAnnotation.test_html_output_with_lifted_loop.<locals>.udtS   s5    HHHA1XX  QHr   z<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 not found in )msg   N)numbajitrecompile	MULTILINEr   int64	overloadsr   r   r   r   r   assertEqualcountformatlenfindallfloat64)	r   r6   re_lifted_tagsig_i64r   r!   r"   sigfmtsig_f64s	            r   !test_html_output_with_lifted_loopz0TestAnnotation.test_html_output_with_lifted_loopO   sY    
	 	 
	 
J L  ;.G}W% jj**3///		 	&:;;Q???4fmmG&<&<==qAAARZv>>??5B]]FFK 	 	M 	M 	M ="G}W% jj**3///		 	&:;;Q???fmmG&<&<==qAAAfmmG&<&<==qAAARZv>>??CCCCCr   Nz%please install the 'pygments' packagec                 V   t           j        d             } |dd           |                    d           |                     t                    5 }|                    dd           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )	Nc                 
    | |fS r   r&   )r'   ys     r   r   z-TestAnnotation.test_pretty_print.<locals>.foo   s    a4Kr   r7   r9   T)prettyzshould be None)rO   filez$`file` must be None if `pretty=True`)r:   r   inspect_typesassertRaises
ValueErrorr   str	exception)r   r   raisess      r   test_pretty_printz TestAnnotation.test_pretty_print   s
    
	 	 
	 	Aq			&&& z** 	BfT0@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B<&*++	- 	- 	- 	- 	-s   A66A:=A:)
__name__
__module____qualname__r#   r1   rK   unittestskipIfpygmentsrW   r&   r   r   r   r      sw        % % %( ,  ,  ,D:D :D :Dx X_X%'NOO- - PO- - -r   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestTypeAnnotationc                     t          |          D ]\  }}||v r|c S t          d                    |                    )Nzcan't find {!r})	enumeraterS   rC   )r   linespatr   lns        r   
findpatloczTestTypeAnnotation.findpatloc   sQ    u%% 	 	EArbyy *11#66777r   c                     t                      }|                    |           |                                                                S r   )r   rQ   r   
splitlines)r   funcstrbufs      r   getlineszTestTypeAnnotation.getlines   s;    6"""  ++---r   c                 z   t           j        d             } |dd           |                     |          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     ||           |                     ||           d S )Nc                     | |z   S r   r&   )appleorangeberrycherrys     r   r   z+TestTypeAnnotation.test_delete.<locals>.foo   s    ,,r   r7   r9   z&appleorange = arg(0, name=appleorange)z&berrycherry = arg(1, name=berrycherry)zdel appleorangezdel berrycherry)r:   r   rj   re   
assertLess)r   r   rb   sasbeaebs          r   test_deletezTestTypeAnnotation.test_delete   s    		- 	- 
	- 	Aq			c"" __U$LMM__U$LMM__U$566__U$566BBr   c                    t          d|          5  t          d             }d} ||          }|                     ||           d d d            n# 1 swxY w Y   |                     |          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
||||	|
fS )	NEXTEND_VARIABLE_LIFETIMESc                 
    | }|S r   r&   )r   bs     r   r   z/TestTypeAnnotation._lifetimes_impl.<locals>.foo   s    r   
   za = arg(0, name=a)zb = azcast(value=b)zdel azdel b)r   r   rA   rj   re   )r   extendr   r'   rx   rb   rp   rq   cast_retdeladelbs              r   _lifetimes_implz"TestTypeAnnotation._lifetimes_impl   s/   8&AA 	# 	#  T AAAQ"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# c""__U$899__UG,,??5/::ug..ug..2xt++s   4AAAc                     |                      d          \  }}}}}|                     ||           |                     ||           |                     ||           |                     ||           d S )Nr   rz   r~   ro   assertGreaterr   rp   rq   r{   r|   r}   s         r   test_delete_standard_lifetimesz1TestTypeAnnotation.test_delete_standard_lifetimes   s}     (,';';1';'E'E$B$D!!!D!!!h'''4*****r   c                     |                      d          \  }}}}}|                     ||           |                     ||           |                     ||           |                     ||           d S )Nr7   r   r   r   s         r   test_delete_extended_lifetimesz1TestTypeAnnotation.test_delete_extended_lifetimes   s     (,';';1';'E'E$B$D!!!D!!!4***4*****r   N)	rX   rY   rZ   re   rj   rt   r~   r   r   r&   r   r   r_   r_      sn        8 8 8. . .
     &, , ,,+ + +&+ + + + +r   r_   __main__)r<   ior   r:   numba.core.compilerr   r   
numba.corer   r   numba.tests.supportr   r	   r[   jinja2ImportErrorr]   r\   r   r_   rX   mainr&   r   r   <module>r      s   				        7 7 7 7 7 7 7 7             9 9 9 9 9 9 9 9 MMMM   FFFOOOO   HHH 4!FGGC- C- C- C- C-X C- C- HGC-LZ+ Z+ Z+ Z+ Z+* Z+ Z+ Z+z zHMOOOOO s   5 ??A AA