o
    l¨Êhš  ã                   @   s¤   d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	 ddlm
Z
 ddlmZmZ G dd„ deƒZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )z/
Unit tests for the stack formatting utilities
é    N)Ú	safe_reprÚ_fixed_getframesÚformat_records)Ú
format_exc)Ú
with_numpyÚnpc                   @   s   e Zd Zdd„ ZdS )ÚViciousc                 C   s   t ‚©N©Ú
ValueError)Úself© r   úO/var/www/html/env/lib/python3.10/site-packages/joblib/test/test_format_stack.pyÚ__repr__   s   zVicious.__repr__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s    r   c                   C   s   t tƒ ƒ d S r	   )r   r   r   r   r   r   Útest_safe_repr   s   r   c                 C   s2   | \}}}}}}|  d¡r|d7 }||||||fS )Nz.pyÚc)Úendswith)ÚrecordÚ_1ÚfilenameÚ_2Ú_3Ú_4Ú_5r   r   r   Ú_change_file_extensions_to_pyc   s   
r   c                 C   s   dd„ }|| |ƒ dS )z7Function that raises with a non trivial call stack
    c                 S   s   t dƒ‚)NzNope, this can not workr
   )ÚaÚbr   r   r   Úhelper)   s   z _raise_exception.<locals>.helperNr   )r   r   r    r   r   r   Ú_raise_exception&   s   r!   c                  C   sÞ   zt ddƒ W d S  tyn   t ¡ d } t| ƒ}dd„ |D ƒ}t|ƒ}|D ]}d|v s.J ‚q&d}t |d |d	 tj¡s?J ‚t |d
 |d tj¡sMJ ‚d|d v sUJ ‚d|d v s]J ‚t |d |d tj¡skJ ‚Y d S w )Nr   é*   é   c                 S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0r   r   r   r   Ú
<listcomp>7   s    ÿz'test_format_records.<locals>.<listcomp>ztest_format_stack.py inú^-+>\s+\d+\s+z_raise_exception\('a', 42\)r   zhelper\(a, b\)é   za = 'a'zb = 42z-raise ValueError\('Nope, this can not work'\))	r!   r   ÚsysÚexc_infor   r   ÚreÚsearchÚ	MULTILINE)ÚetbÚrecordsÚpyc_recordsÚformatted_recordsÚfmt_recÚarrow_regexr   r   r   Útest_format_records/   s:   ÿ
þ
þÿýçr3   c              	   C   s,  t j | jd¡}ddg}d |¡}t|dƒ�}| |¡ W d   ƒ n1 s&w   Y  t d|¡}t|dƒs;t	 
d¡ z| ¡  W d S  ty•   t ¡ d	 }t|d
d�}|d \}}	}
}}}dd„ |D ƒ|ksjJ ‚t|ƒ}d	}t|d  ¡ ƒ}||t|ƒ ks‚J ‚d}t |d |d tj¡s’J ‚Y d S w )Nzsmall_file.pyzdef func():z    1/0Ú
ÚwÚ
small_fileÚfuncz	PyPy bug?r#   é
   ©Úcontextéÿÿÿÿc                 S   s   g | ]}|  ¡ ‘qS r   )Úrstrip)r$   Úlr   r   r   r%   e   s    zItest_format_records_file_with_less_lines_than_context.<locals>.<listcomp>r'   r&   z1/0)ÚosÚpathÚjoinÚstrpathÚopenÚwriteÚimpÚload_sourceÚhasattrÚpytestÚskipr7   ÚZeroDivisionErrorr(   r)   r   r   ÚlenÚ
splitlinesr*   r+   r,   )Útmpdirr   Ú
code_linesÚcodeÚfr6   r-   r.   ÚframeÚtb_filenameÚlineÚ	func_namer:   Ú_r0   Ú
len_headerÚnb_lines_formatted_recordsr2   r   r   r   Ú5test_format_records_file_with_less_lines_than_contextQ   s4   
ÿ


þïrW   c               	   C   sZ   z	t j d¡ W d S  ty,   t ¡ \} }}t| ||dd�}d}t ||¡s)J ‚Y d S w )NÚinvalid_valuer8   r9   zmtrand[a-z0-9._-]*\.(so|pyd))	r   ÚrandomÚuniformÚ	Exceptionr(   r)   r   r*   r+   )Úexc_typeÚ	exc_valueÚexc_tracebackÚformatted_excÚpatternr   r   r   Ú"test_format_exc_with_compiled_codet   s   ÿùra   )Ú__doc__rD   r>   r*   r(   rG   Újoblib.format_stackr   r   r   r   Újoblib.test.commonr   r   Úobjectr   r   r   r!   r3   rW   ra   r   r   r   r   Ú<module>   s"    	"#