o
    8Î®c!  ã                   @   sh   d dl Z d dlZd dlm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r2e  ¡  dS dS )	é    N©Únjit)Ú	PYVERSION)ÚTestCase)Úget_func_body_first_linenoc                   @   sh   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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   úG/tmp/pip-target-vg8gfxp4/lib/python/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   3   r    zBTestFirstLineFinder.test_nested_function.<locals>.foo.<locals>.foor   )r   r   r   r   r   2   s   
z5TestFirstLineFinder.test_nested_function.<locals>.fooé   )r   r   )r   r   Úinnerr$   r   r   r   Útest_nested_function1   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 )Nz$def foo():
            pass
        r   )Úexecr   r*   )r   ÚsourceÚglobalnsr   r$   r   r   r   Útest_string_evalF   s   
z$TestFirstLineFinder.test_string_evalc                 C   r   )Nc                   S   r/   r   r   r   r   r   r   r   T   s   z:TestFirstLineFinder.test_single_line_function.<locals>.foor   r"   r#   r   r   r   Útest_single_line_functionS   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_docstringZ   s   
z"TestFirstLineFinder.test_docstringc                 C   s<   t dd„ ƒ}t|ƒ}tdkr|  |d¡ d S |  |d¡ d S )Nc                   S   s   	 dS r6   r   r   r   r   r   r   e   s   z1TestFirstLineFinder.test_docstring_2.<locals>.foo)r'   é   é   r,   )r   r   r   r   r#   r   r   r   Útest_docstring_2d   s   
z$TestFirstLineFinder.test_docstring_2N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   r(   r+   r.   r0   r4   r5   r7   r:   r   r   r   r   r   
   s    	
r   Ú__main__)Úunittestr	   Únumbar   Únumba.core.utilsr   Únumba.tests.supportr   Únumba.misc.firstlinefinderr   r   r;   Úmainr   r   r   r   Ú<module>   s    lÿ