
    pi                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	  G d de      Z
edk(  r e j                          yy)    Nnjit)TestCase)get_func_body_first_linenoc                   v    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestFirstLineFinderz
    The following methods contains tests that are sensitive to the source
    locations w.r.t. the beginning of each method.
    c                     t        j                         }t        j                  |      }|d   j                  j                  S )N   )inspectcurrentframegetouterframesframef_code)selfr   caller_frames      b/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/numba/tests/test_firstlinefinder.py_get_grandparent_caller_codez0TestFirstLineFinder._get_grandparent_caller_code   s6    $$&--e4A$$+++    c                 f    | j                         }|j                  }| j                  |||z          y N)r   co_firstlinenoassertEqual)r   expectedoffset_from_callergrandparent_colnos        r   assert_line_locationz(TestFirstLineFinder.assert_line_location   s1    ::<++3);#;<r   c                 V    t         d        }t        |      }| j                  |d       y )Nc                       yN    r"   r   r   foozBTestFirstLineFinder.test_decorated_odd_comment_indent.<locals>.foo   s     r      r   r   r   r   r#   first_def_lines      r   !test_decorated_odd_comment_indentz5TestFirstLineFinder.test_decorated_odd_comment_indent   s0    		 
	 4C8!!.!4r   c                 V    d }t        t        |            }| j                  |d       y )Nc                       yr    r"   r"   r   r   r#   zDTestFirstLineFinder.test_undecorated_odd_comment_indent.<locals>.foo%   s    r      )r   r   r   r&   s      r   #test_undecorated_odd_comment_indentz7TestFirstLineFinder.test_undecorated_odd_comment_indent$   s'    	 4DI>!!.!4r   c                 T    d }t        t        |            }| j                  |       y )Nc                       yr    r"   r"   r   r   <lambda>z9TestFirstLineFinder.test_unnamed_lambda.<locals>.<lambda>-   s    r   )r   r   assertIsNoner&   s      r   test_unnamed_lambdaz'TestFirstLineFinder.test_unnamed_lambda,   s#    3DI>.)r   c                 R    d } |       }t        |      }| j                  |d       y )Nc                      t         d        } | S )Nc                       yr    r"   r"   r   r   r#   zBTestFirstLineFinder.test_nested_function.<locals>.foo.<locals>.foo4   s     r   r   )r#   s    r   r#   z5TestFirstLineFinder.test_nested_function.<locals>.foo3   s      Jr      )r   r   )r   r#   innerr'   s       r   test_nested_functionz(TestFirstLineFinder.test_nested_function2   s*    	 3E:!!.!4r   c                 V    t         d        }t        |      }| j                  |d       y )Nc                       y r   r"   r"   r   r   r#   z4TestFirstLineFinder.test_pass_statement.<locals>.foo@   s    r   r+   r%   r&   s      r   test_pass_statementz'TestFirstLineFinder.test_pass_statement?   s0    		 
	 4C8!!.!4r   c                 f    d}i }t        ||       |d   }t        |      }| j                  |       y )N$def foo():
            pass
        r#   )execr   r0   )r   sourceglobalnsr#   r'   s        r   test_string_evalz$TestFirstLineFinder.test_string_evalG   s;     VXuo3C8.)r   c                     d }t        |      ||j                  d      |f}|t        j                  |<   t	        ||d      }i }t        ||       ||   }	t        |	      }
| j                  |
|       y )NTr=   )len
splitlines	linecachecachecompiler=   r   r   )r   filenamer>   function_nameexpected_first_line	timestampentrycoder?   functionr'   s              r   _test_with_patched_linecachez0TestFirstLineFinder._test_with_patched_linecacheT   sz    
 	Vi):):4)@(K$)	! vx0T8M* 4H=)<=r   c                 <    d}d}d}d}| j                  ||||       y )Nr<   z<foo-basic>r#   r
   rN   r   r>   rG   rH   rI   s        r    test_string_eval_linecache_basicz4TestFirstLineFinder.test_string_eval_linecache_basicj   s2     !))(FM*=	?r   c                 <    d}d}d}d}| j                  ||||       y )Nzif True:
        # indent designed to test against potential indent error in ast.parse

        def foo():
            pass
        z<foo-indent>r#   r5   rP   rQ   s        r   !test_string_eval_linecache_indentz5TestFirstLineFinder.test_string_eval_linecache_indentu   s2     "))(FM*=	?r   c                 b    t        j                  d      }d}d}d}| j                  ||||       y )Nz
        def foo_gen():
            def foo():
                pass
            return foo

        generated_foo = foo_gen()
        z	<foo-gen>generated_foor$   textwrapdedentrN   rQ   s        r   "test_string_eval_linecache_closurez6TestFirstLineFinder.test_string_eval_linecache_closure   s>     "  '))(FM*=	?r   c                 b    t        j                  d      }d}d}d}| j                  ||||       y )Nz
        def decorator(function):
            return function

        @decorator
        @decorator
        @decorator
        def decorated():
            pass
        z<foo-stacked-decorator>	decorated	   rW   rQ   s        r   -test_string_eval_linecache_stacked_decoratorszATestFirstLineFinder.test_string_eval_linecache_stacked_decorators   s>     	" 	 -#))(FM*=	?r   c                 <    d}d}d}d}| j                  ||||       y )Na  if 1:
        def decorator(function):
            return function

        def gen_decorated_foo():
            @decorator
            @decorator
            @decorator
            def _foo():
                pass

            return _foo

        foo_all = gen_decorated_foo()
        z	<foo-all>foo_all
   rP   rQ   s        r   test_string_eval_linecache_allz2TestFirstLineFinder.test_string_eval_linecache_all   s2      ! ))(FM*=	?r   c                 V    t         d        }t        |      }| j                  |d       y )Nc                       y r   r"   r"   r   r   r#   z:TestFirstLineFinder.test_single_line_function.<locals>.foo   s    r   r
   r%   r&   s      r   test_single_line_functionz-TestFirstLineFinder.test_single_line_function   s*    	 
3C8!!.!4r   c                 V    t         d        }t        |      }| j                  |d       y )Nc                       yzDocstring
            Nr"   r"   r   r   r#   z/TestFirstLineFinder.test_docstring.<locals>.foo   s     r   r5   r%   r&   s      r   test_docstringz"TestFirstLineFinder.test_docstring   s0    		 
	
 4C8!!.!4r   c                 V    t         d        }t        |      }| j                  |d       y )Nc                       	 yrh   r"   r"   r   r   r#   z1TestFirstLineFinder.test_docstring_2.<locals>.foo   s
    r   r5   r%   r&   s      r   test_docstring_2z$TestFirstLineFinder.test_docstring_2   s0    		 
	 4C8!!.!4r   N)__name__
__module____qualname____doc__r   r   r(   r,   r1   r7   r:   r@   rN   rR   rT   rZ   r^   rb   re   ri   rl   r"   r   r   r   r      s\    
,
=
55*55*>,	??? ?$?0555r   r   __main__)unittestrD   r   rX   numbar   numba.tests.supportr   numba.misc.firstlinefinderr   r   rm   mainr"   r   r   <module>rw      sC         ( AN5( N5b zHMMO r   