
    J/Pht                     D   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	 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)types)jitnjit)override_configTestCasez#please install the 'jinja2' packagec                       e Zd Zej        d             Zej        d             Zej        d             Z ej	        e
du d          d             ZdS )TestAnnotationc                 h   d } t          t          j        t          j        f          |          }|j        |j        d                  }|j        }t                      }|                    |           |                                }|	                                 | 
                    d|           dS )z4
        Ensures template.html is available
        c                 8    |}t          |           D ]}||z  }|S Nrange)nasis       \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_annotations.pyfooz3TestAnnotation.test_exercise_code_path.<locals>.foo   s,    A1XX  QH    r   r   N)r   r   int32	overloads
signaturestype_annotationr   html_annotategetvaluecloseassertIn)selfr   cfunccrestabufoutputs          r   test_exercise_code_pathz&TestAnnotation.test_exercise_code_path   s    	 	 	 1ek5;/0055u/23!jj
		eV$$$$$r   c                    d fd} t          t          j        f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 r    )xs    r   barzDTestAnnotation.test_exercise_code_path_with_lifted_loop.<locals>.bar4   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>.foo7   sf    A1XX  E1XX  E AJHr   T)forceobjloopliftr   r*   r   
LiftedLoopN)r   r   intpr   r   r   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    	 	 		 	 	 	 	 AUZMD4@@@EEu/23!jj
		eV$$$eV$$$lF+++++r   c                 r   t          j        d          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
        T)r.   c                 T    t                       d}t          |           D ]}||z  }|S )Nr   )objectr   )r)   zr   s      r   udtz=TestAnnotation.test_html_output_with_lifted_loop.<locals>.udtT   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)numbar   recompile	MULTILINEr   int64r   r   r   r   r   r   assertEqualcountformatlenfindallfloat64)	r   r7   re_lifted_tagsig_i64r!   r#   r$   sigfmtsig_f64s	            r   !test_html_output_with_lifted_loopz0TestAnnotation.test_html_output_with_lifted_loopO   se   
 
D	!	!	!	 	 
"	!	 
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   r8   r:   T)prettyzshould be None)rN   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   run_test_in_subprocessr%   r2   rJ   unittestskipIfpygmentsrV   r(   r   r   r
   r
      s         $% % %$%* $, , %$,@ $: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})	enumeraterR   rB   )r   linespatr   lns        r   
findpatloczTestTypeAnnotation.findpatloc   sQ    u%% 	 	EArbyy *11#66777r   c                     t                      }|                    |           |                                                                S r   )r   rP   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   r8   r:   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   r@   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 )Nr8   r   r   r   s         r   test_delete_extended_lifetimesz1TestTypeAnnotation.test_delete_extended_lifetimes   s     (,';';1';'E'E$B$D!!!D!!!4***4*****r   N)	rW   rX   rY   re   rj   rt   r~   r   r   r(   r   r   r_   r_      sn        8 8 8. . .
     &, , ,,+ + +&+ + + + +r   r_   __main__)r<   ior   r;   
numba.corer   r   r   numba.tests.supportr   r   r[   jinja2ImportErrorr]   r\   r
   r_   rW   mainr(   r   r   <module>r      s   				                      9 9 9 9 9 9 9 9 MMMM   FFFOOOO   HHH 4!FGGE- E- E- E- E-X E- E- HGE-PZ+ Z+ Z+ Z+ Z+* Z+ Z+ Z+z zHMOOOOO s   / 99A AA