o
    mi                     @   sl   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 deZ
edkr4e   dS dS )    Nnjit)TestCase)get_func_body_first_linenoc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"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                 C   s   t  }t |}|d jjS )N   )inspectcurrentframegetouterframesframef_code)selfr   caller_frame r   _/var/www/html/pca-backend/venv/lib/python3.10/site-packages/numba/tests/test_firstlinefinder.py_get_grandparent_caller_code   s   
z0TestFirstLineFinder._get_grandparent_caller_codec                 C   s"   |   }|j}| |||  d S N)r   co_firstlinenoassertEqual)r   expectedoffset_from_callergrandparent_colnor   r   r   assert_line_location   s   z(TestFirstLineFinder.assert_line_locationc                 C   $   t dd }t|}| |d d S )Nc                   S      dS N   r   r   r   r   r   foo      zBTestFirstLineFinder.test_decorated_odd_comment_indent.<locals>.foo   r   r   r   r   r   first_def_liner   r   r   !test_decorated_odd_comment_indent   s   
z5TestFirstLineFinder.test_decorated_odd_comment_indentc                 C   s$   dd }t t|}| |d d S )Nc                   S   r   r   r   r   r   r   r   r   %      zDTestFirstLineFinder.test_undecorated_odd_comment_indent.<locals>.foo   )r   r   r   r"   r   r   r   #test_undecorated_odd_comment_indent$   s   z7TestFirstLineFinder.test_undecorated_odd_comment_indentc                 C   s"   dd }t t|}| | d S )Nc                   S   r   r   r   r   r   r   r   <lambda>-   s    z9TestFirstLineFinder.test_unnamed_lambda.<locals>.<lambda>)r   r   assertIsNoner"   r   r   r   test_unnamed_lambda,   s   z'TestFirstLineFinder.test_unnamed_lambdac                 C   s&   dd }| }t |}| |d d S )Nc                  S   s   t dd } | S )Nc                   S   r   r   r   r   r   r   r   r   4   r   zBTestFirstLineFinder.test_nested_function.<locals>.foo.<locals>.foor   )r   r   r   r   r   3   s   
z5TestFirstLineFinder.test_nested_function.<locals>.foo   )r   r   )r   r   innerr#   r   r   r   test_nested_function2   s   z(TestFirstLineFinder.test_nested_functionc                 C   r   )Nc                   S      d S r   r   r   r   r   r   r   @   r%   z4TestFirstLineFinder.test_pass_statement.<locals>.foor&   r!   r"   r   r   r   test_pass_statement?   s   
z'TestFirstLineFinder.test_pass_statementc                 C   s0   d}i }t || |d }t|}| | d S )N$def foo():
            pass
        r   )execr   r)   )r   sourceglobalnsr   r#   r   r   r   test_string_evalG   s   
z$TestFirstLineFinder.test_string_evalc                 C   s^   d }t |||d|f}|tj|< t||d}i }t|| || }	t|	}
| |
| d S )NTr1   )len
splitlines	linecachecachecompiler1   r   r   )r   filenamer2   function_nameexpected_first_line	timestampentrycoder3   functionr#   r   r   r   _test_with_patched_linecacheT   s   

z0TestFirstLineFinder._test_with_patched_linecachec                 C   $   d}d}d}d}|  |||| d S )Nr0   z<foo-basic>r   r   rA   r   r2   r:   r;   r<   r   r   r    test_string_eval_linecache_basicj   s   
z4TestFirstLineFinder.test_string_eval_linecache_basicc                 C   rB   )Nzif True:
        # indent designed to test against potential indent error in ast.parse

        def foo():
            pass
        z<foo-indent>r   r+   rC   rD   r   r   r   !test_string_eval_linecache_indentu   s   
z5TestFirstLineFinder.test_string_eval_linecache_indentc                 C   *   t 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dedentrA   rD   r   r   r   "test_string_eval_linecache_closure   s   
	
z6TestFirstLineFinder.test_string_eval_linecache_closurec                 C   rG   )Nz
        def decorator(function):
            return function

        @decorator
        @decorator
        @decorator
        def decorated():
            pass
        z<foo-stacked-decorator>	decorated	   rI   rD   r   r   r   -test_string_eval_linecache_stacked_decorators   s   

zATestFirstLineFinder.test_string_eval_linecache_stacked_decoratorsc                 C   rB   )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
   rC   rD   r   r   r   test_string_eval_linecache_all   s   
z2TestFirstLineFinder.test_string_eval_linecache_allc                 C   r   )Nc                   S   r.   r   r   r   r   r   r   r      s   z:TestFirstLineFinder.test_single_line_function.<locals>.foor   r!   r"   r   r   r   test_single_line_function   s   
z-TestFirstLineFinder.test_single_line_functionc                 C   r   )Nc                   S   r   zDocstring
            Nr   r   r   r   r   r      s   z/TestFirstLineFinder.test_docstring.<locals>.foor+   r!   r"   r   r   r   test_docstring   s   
z"TestFirstLineFinder.test_docstringc                 C   r   )Nc                   S   s   	 dS rT   r   r   r   r   r   r      s   z1TestFirstLineFinder.test_docstring_2.<locals>.foor+   r!   r"   r   r   r   test_docstring_2   s   
z$TestFirstLineFinder.test_docstring_2N)__name__
__module____qualname____doc__r   r   r$   r'   r*   r-   r/   r4   rA   rE   rF   rL   rO   rR   rS   rU   rV   r   r   r   r   r      s&    	
r   __main__)unittestr7   r   rJ   numbar   numba.tests.supportr   numba.misc.firstlinefinderr   r   rW   mainr   r   r   r   <module>   s     R