
    xKgt                     :   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	 d dlZ ej                  edu d       G d de
             Z G d	 d
ej                        Zedk(  r ej&                          yy# e$ r dZY ^w xY w# e$ r dZY fw xY w)    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y)TestAnnotationc                 R   d } t        t        j                  t        j                  f      |      }|j                  |j                  d      }|j
                  }t               }|j                  |       |j                         }|j                          | j                  d|       y)z4
        Ensures template.html is available
        c                 4    |}t        |       D ]  }||z  }	 |S Nrange)nasis       `/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_annotations.pyfooz3TestAnnotation.test_exercise_code_path.<locals>.foo   s#    A1X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ekk5;;/05u//23!!j
		eV$r   c                    d fd} t        t        j                  fdd      |      }|j                  |j                  d      }|j
                  }t               }|j                  |       |j                         }|j                          | j                  d|       | j                  d|       | j                  d|       y	)
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                 z    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   sK    A1XE 1X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UZZMD4@Eu//23!!j
		eV$eV$lF+r   c                    t        j                  d      d        }t        j                  dt        j                        }t
        j                  f}|j                  |       |j                  |   }t               }|j                  j                  |       |j                         }|j                          | j                  |j                  d      d       d}| j                  |j                  |j                  |            d       | j                  t!        t        j"                  ||            d|d|	       t
        j$                  f}|j                  |       |j                  |   }t               }|j                  j                  |       |j                         }|j                          | j                  |j                  d      d
       | j                  |j                  |j                  |            d       | j                  |j                  |j                  |            d       | j                  t!        t        j"                  ||            d
       y)zW
        Test some format and behavior of the html annotation with lifted loop
        T)r.   c                 H    t                d}t        |       D ]  }||z  }	 |S )Nr   )objectr   )r)   zr   s      r   udtz=TestAnnotation.test_html_output_with_lifted_loop.<locals>.udtT   s(    HA1X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   s   
 
D	!	 
"	 

J LL ;;.G}}W% j**3/		 	&:;Q?4fmmG&<=qARZZv>?5BFK 	 	M =="G}}W% j**3/		 	&:;Q?fmmG&<=qAfmmG&<=qARZZv>?Cr   Nz%please install the 'pygments' packagec                 *   t         j                  d        } |dd       |j                  d       | j                  t              5 }|j                  dd       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)	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*fT0@A +<&**+	- +*s   B		B)__name__
__module____qualname__r   run_test_in_subprocessr%   r2   rJ   unittestskipIfpygmentsrV   r(   r   r   r
   r
      s|     $$% %%* $$, %,@ $$:D %:Dx X__X%'NO- P-r   r
   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestTypeAnnotationc                 l    t        |      D ]  \  }}||v s|c S  t        dj                  |            )Nzcan't find {!r})	enumeraterR   rB   )r   linespatr   lns        r   
findpatloczTestTypeAnnotation.findpatloc   s:    u%EArby & *11#677r   c                 t    t               }|j                  |       |j                         j                         S r   )r   rP   r   
splitlines)r   funcstrbufs      r   getlineszTestTypeAnnotation.getlines   s-    6" ++--r   c                 <   t         j                  d        } |dd       | j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  ||       | j	                  ||       y )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__U$LM__U$56__U$56BBr   c                 x   t        d|      5  t        d        }d} ||      }| j                  ||       d d d        | j                        }| j	                  |d      }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j	                  |d      }
||||	|
fS # 1 sw Y   {xY w)	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AAQ" B c"__U$89__UG,??5/:ug.ug.2xt++' BAs   )B00B9c                     | j                  d      \  }}}}}| j                  ||       | j                  ||       | j                  ||       | j                  ||       y )Nr   rz   r~   ro   assertGreaterr   rp   rq   r{   r|   r}   s         r   test_delete_standard_lifetimesz1TestTypeAnnotation.test_delete_standard_lifetimes   s\     (,';';1';'E$B$D!D!h'4*r   c                     | j                  d      \  }}}}}| j                  ||       | j                  ||       | j                  ||       | j                  ||       y )Nr8   r   r   r   s         r   test_delete_extended_lifetimesz1TestTypeAnnotation.test_delete_extended_lifetimes   s^     (,';';1';'E$B$D!D!4*4*r   N)	rW   rX   rY   re   rj   rt   r~   r   r   r(   r   r   r_   r_      s     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 
 4!FGE-X E- HE-PZ+** Z+z zHMMO _  F
  Hs"   B B BBBB