
    tpd                         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e          Zd Zd	 Zd
 Zd Zd Zed             ZdS )z/
Unit tests for the stack formatting utilities
    N)	safe_repr_fixed_getframesformat_records)
format_exc)
with_numpynpc                       e Zd Zd ZdS )Viciousc                     t           N
ValueError)selfs    =lib/python3.11/site-packages/joblib/test/test_format_stack.py__repr__zVicious.__repr__   s        N)__name__
__module____qualname__r    r   r   r
   r
      s#            r   r
   c                  <    t          t                                 d S r   )r   r
   r   r   r   test_safe_reprr      s    giir   c                 X    | \  }}}}}}|                     d          r|dz  }||||||fS )Nz.pyc)endswith)record_1filename_2_3_4_5s          r   _change_file_extensions_to_pycr#      sF    #) B"b"b CxRR''r   c                 $    d } || |           dS )z7Function that raises with a non trivial call stack
    c                      t          d          )NzNope, this can not workr   )abs     r   helperz _raise_exception.<locals>.helper)   s    2333r   Nr   )r&   r'   r(   s      r   _raise_exceptionr)   &   s&    4 4 4 F1aLLLLLr   c                     	 t          dd           d S # t          $ r t          j                    d         } t	          |           }d |D             }t          |          }|D ]}d|v sJ 	d}t          j        |dz   |d         t          j                  sJ t          j        |d	z   |d
         t          j                  sJ d|d
         v sJ d|d
         v sJ t          j        |dz   |d         t          j                  sJ Y d S w xY w)Nr&   *      c                 ,    g | ]}t          |          S r   )r#   ).0r   s     r   
<listcomp>z'test_format_records.<locals>.<listcomp>7   s0     . . .! 6f== . . .r   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_regexs         r   test_format_recordsr=   /   s   'b!!!!! ' ' 'lnnQ"3''. .%,. . . +;77 ) 	8 	8G,77777 'y'EE*1-' ' 	' 	' 	' y'88*1-' ' 	' 	' 	' -a00000,Q/////yIJ*1-' ' 	' 	' 	' 	' 	' 	'3's    C3D
Dc                 J   t           j                            | j        d          }ddg}d                    |          }t	          |d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        d|          }t          |d          st          j
        d           	 |                                 d S # t          $ r t          j                    d	         }t          |d
          }|d         \  }}	}
}}}d |D             |k    sJ t!          |          }d	}t#          |d                                                   }||t#          |          z   k    sJ d}t'          j        |dz   |d         t&          j                  sJ Y d S w xY w)Nzsmall_file.pyzdef func():z    1/0
w
small_filefuncz	PyPy bug?r,   
   contextc                 6    g | ]}|                                 S r   )rstrip)r.   ls     r   r/   zItest_format_records_file_with_less_lines_than_context.<locals>.<listcomp>e   s     ,,,q

,,,r   r1   r0   z1/0)ospathjoinstrpathopenwriteimpload_sourcehasattrpytestskiprB   ZeroDivisionErrorr2   r3   r   r   len
splitlinesr4   r5   r6   )tmpdirr   
code_linescodefrA   r7   r8   frametb_filenameline	func_namerE   _r:   
len_headernb_lines_formatted_recordsr<   s                     r   5test_format_records_file_with_less_lines_than_contextrc   Q   s   w||FNO<<H+J99Z  D	h		 	               x88J:v&& !K   ' ' ' 'lnnQ"3333 ;B"+7{D)Wa,,G,,,
::::*733 
%():1)=)H)H)J)J%K%K"*j3z??.JJJJJ&yv-*1-' ' 	' 	' 	' 	' 	' 	'#'s%   A11A58A56C CF"!F"c                      	 t           j                            d           d S # t          $ rG t	          j                    \  } }}t          | ||d          }d}t          j        ||          sJ Y d S w xY w)Ninvalid_valuerC   rD   zmtrand[a-z0-9._-]*\.(so|pyd))	r   randomuniform	Exceptionr2   r3   r   r4   r5   )exc_type	exc_valueexc_tracebackformatted_excpatterns        r   "test_format_exc_with_compiled_codern   t   s    	1
	/***** 1 1 1-0\^^*)]"8Y#0"> > > 2y-000000001s   # AA43A4)__doc__rP   rJ   r4   r2   rS   joblib.format_stackr   r   r   r   joblib.test.commonr   r   objectr
   r   r#   r)   r=   rc   rn   r   r   r   <module>rs      s"    


 				 				 



  K K K K K K K K K K * * * * * * - - - - - - - -
    f   
  ( ( (  ' ' 'D '  '  'F 1 1 1 1 1r   