
    wi                         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                     dS dS )    Nnjit)TestCase)get_func_body_first_linenoc                   x    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dS )TestFirstLineFinderz
    The following methods contains tests that are sensitive to the source
    locations w.r.t. the beginning of each method.
    c                 t    t          j                    }t          j        |          }|d         j        j        S )N   )inspectcurrentframegetouterframesframef_code)selfr   caller_frames      p/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/numba/tests/test_firstlinefinder.py_get_grandparent_caller_codez0TestFirstLineFinder._get_grandparent_caller_code   s0    $&&-e44A$++    c                 n    |                                  }|j        }|                     |||z              d S N)r   co_firstlinenoassertEqual)r   expectedoffset_from_callergrandparent_colnos        r   assert_line_locationz(TestFirstLineFinder.assert_line_location   s=    ::<<+3);#;<<<<<r   c                 p    t           d             }t          |          }|                     |d           d S )Nc                      dS N    r"   r   r   foozBTestFirstLineFinder.test_decorated_odd_comment_indent.<locals>.foo   s	     1r      r   r   r   r   r#   first_def_lines      r   !test_decorated_odd_comment_indentz5TestFirstLineFinder.test_decorated_odd_comment_indent   sF    		 	 
	 4C88!!.!44444r   c                 p    d }t          t          |                    }|                     |d           d S )Nc                      dS r    r"   r"   r   r   r#   zDTestFirstLineFinder.test_undecorated_odd_comment_indent.<locals>.foo%   s    1r      )r   r   r   r&   s      r   #test_undecorated_odd_comment_indentz7TestFirstLineFinder.test_undecorated_odd_comment_indent$   sB    	 	 	 4DII>>!!.!44444r   c                 n    d }t          t          |                    }|                     |           d S )Nc                      dS r    r"   r"   r   r   <lambda>z9TestFirstLineFinder.test_unnamed_lambda.<locals>.<lambda>-   s    a r   )r   r   assertIsNoner&   s      r   test_unnamed_lambdaz'TestFirstLineFinder.test_unnamed_lambda,   s6    i3DII>>.)))))r   c                 j    d } |            }t          |          }|                     |d           d S )Nc                  &    t           d             } | S )Nc                      dS r    r"   r"   r   r   r#   zBTestFirstLineFinder.test_nested_function.<locals>.foo.<locals>.foo4   s	     qr   r   )r#   s    r   r#   z5TestFirstLineFinder.test_nested_function.<locals>.foo3   s"      T Jr      )r   r   )r   r#   innerr'   s       r   test_nested_functionz(TestFirstLineFinder.test_nested_function2   sG    	 	 	 3E::!!.!44444r   c                 p    t           d             }t          |          }|                     |d           d S )Nc                      d S r   r"   r"   r   r   r#   z4TestFirstLineFinder.test_pass_statement.<locals>.foo@   s    Dr   r+   r%   r&   s      r   test_pass_statementz'TestFirstLineFinder.test_pass_statement?   sF    		 	 
	 4C88!!.!44444r   c                     d}i }t          ||           |d         }t          |          }|                     |           d S )N$def foo():
            pass
        r#   )execr   r0   )r   sourceglobalnsr#   r'   s        r   test_string_evalz$TestFirstLineFinder.test_string_evalG   sP     VXuo3C88.)))))r   c                    d }t          |          ||                    d          |f}|t          j        |<   t	          ||d          }i }t          ||           ||         }	t          |	          }
|                     |
|           d S )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   s    
 	Vi):):4)@)@(K$)	! vx00T8M* 4H==)<=====r   c                 F    d}d}d}d}|                      ||||           d S )Nr<   z<foo-basic>r#   r
   rN   r   r>   rG   rH   rI   s        r    test_string_eval_linecache_basicz4TestFirstLineFinder.test_string_eval_linecache_basicj   sF     !))(FM*=	? 	? 	? 	? 	?r   c                 F    d}d}d}d}|                      ||||           d S )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   sF     "))(FM*=	? 	? 	? 	? 	?r   c                 j    t          j        d          }d}d}d}|                     ||||           d S )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   sU     "   '))(FM*=	? 	? 	? 	? 	?r   c                 j    t          j        d          }d}d}d}|                     ||||           d S )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   sU     	" 	 	 -#))(FM*=	? 	? 	? 	? 	?r   c                 F    d}d}d}d}|                      ||||           d S )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   sF      ! ))(FM*=	? 	? 	? 	? 	?r   c                 p    t           d             }t          |          }|                     |d           d S )Nc                      d S r   r"   r"   r   r   r#   z:TestFirstLineFinder.test_single_line_function.<locals>.foo   s    4r   r
   r%   r&   s      r   test_single_line_functionz-TestFirstLineFinder.test_single_line_function   s=    	 
3C88!!.!44444r   c                 p    t           d             }t          |          }|                     |d           d S )Nc                      dS zDocstring
            Nr"   r"   r   r   r#   z/TestFirstLineFinder.test_docstring.<locals>.foo   s	     Dr   r5   r%   r&   s      r   test_docstringz"TestFirstLineFinder.test_docstring   sF    		 	 
	
 4C88!!.!44444r   c                 p    t           d             }t          |          }|                     |d           d S )Nc                      	 dS rh   r"   r"   r   r   r#   z1TestFirstLineFinder.test_docstring_2.<locals>.foo   s    Dr   r5   r%   r&   s      r   test_docstring_2z$TestFirstLineFinder.test_docstring_2   sF    		 	 
	 4C88!!.!4444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 5 5* * *5 5 55 5 5* * *> > >,	? 	? 	?? ? ?? ? ? ? ? ?$? ? ?05 5 55 5 55 5 5 5 5r   r   __main__)unittestrD   r   rX   numbar   numba.tests.supportr   numba.misc.firstlinefinderr   r   rm   mainr"   r   r   <module>rw      s                 ( ( ( ( ( ( A A A A A AN5 N5 N5 N5 N5( N5 N5 N5b zHMOOOOO r   