o
    tBh                     @   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   t/var/www/html/riverr-enterprise-integrations-main/venv/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sJ d}t|d |d tjsJ Y d S w )Nzsmall_file.pyzdef func():z    1/0
w
small_filefuncz	PyPy bug?r#   
   contextc                 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"    	"#