
    ,iaO                        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 ddlmZmZmZmZ ddlmZ ddlmZmZmZ dd	lmZmZmZmZ dd
lm Z  ddl!m"Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+Z+ G d de+j*                  Z, G d de+j*                  Z- G d de+j*                  Z. G d de+j*                  Z/ G d de'e+j*                  Z0 G d de'e*          Z1e2dk    r e+j3                     dS dS )z"
Unspecified error handling tests
    N)jitnjittypes)errors)	structref)overload	intrinsicoverload_methodoverload_attribute)CompilerBase)TranslateByteCode	FixupArgsIRProcessing)NopythonTypeInferenceDeadCodeEliminationNoPythonBackendNativeLowering)PassManager)_err_reasons)skip_parfors_unsupportedoverride_configSerialMixinskip_unless_cffiskip_unless_scipyTestCasec                       e Zd Zd ZdS )TestErrorHandlingBeforeLoweringc                    d }t           t          fD ]w}|                     t          j                  5 }  ||          d           d d d            n# 1 swxY w Y   d}|                     |t          |j                             xd S )Nc                     | dz   fd}|S )z return the closure    c                     | z   S N )xzs    \/var/www/html/speakWrite/venv/lib/python3.11/site-packages/numba/tests/test_errorhandling.pyinnerzmTestErrorHandlingBeforeLowering.test_unsupported_make_function_return_inner_func.<locals>.func.<locals>.inner%   s    1u    r#   )r$   r'   r%   s     @r&   funcz^TestErrorHandlingBeforeLowering.test_unsupported_make_function_return_inner_func.<locals>.func!   s*    AA    Lr(   r    z%Cannot capture the non-constant value)r   r   assertRaisesr   TypingErrorassertInstr	exception)selfr)   pipelineraisesexpecteds        r&   0test_unsupported_make_function_return_inner_funczPTestErrorHandlingBeforeLowering.test_unsupported_make_function_return_inner_func    s    	 	 	 T	 	; 	;H""6#566 "&q!!!" " " " " " " " " " " " " " " ?HMM(C(8$9$9::::	; 	;s   AA	A	N)__name__
__module____qualname__r3   r#   r(   r&   r   r      s#        ; ; ; ; ;r(   r   c                       e Zd Zd ZdS )TestUnsupportedReportingc                     t           d             }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   d}|                     |t          |j                             d S )Nc                  2    t          j        g d           d S )N)r          )np
asanyarrayr#   r(   r&   r)   zFTestUnsupportedReporting.test_unsupported_numpy_function.<locals>.func5   s    M'''"""""r(   z4Use of unsupported NumPy function 'numpy.asanyarray'r   r*   r   r+   r,   r-   r.   )r/   r)   r1   r2   s       r&   test_unsupported_numpy_functionz8TestUnsupportedReporting.test_unsupported_numpy_function3   s    		# 	# 
	# v122 	fDFFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 JhF$4 5 566666   AAAN)r4   r5   r6   r@   r#   r(   r&   r8   r8   1   s#        
7 
7 
7 
7 
7r(   r8   c                   T    e Zd Zd Zd Zd Zd Zd Zd Ze	d             Z
d Zd	 Zd
S )TestMiscErrorHandlingc                 ~    t           d             }t          j        dgt          j                  } ||           d S )Nc                     d| z  S N
   r#   r$   s    r&   fnzHTestMiscErrorHandling.test_use_of_exception_for_flow_control.<locals>.fnG   s    q5Lr(   g      ?)dtype)r   r=   arrayfloat64)r/   rI   as      r&   &test_use_of_exception_for_flow_controlz<TestMiscErrorHandling.test_use_of_exception_for_flow_controlB   sH    
 
	 	 
	 HcU,,,
1r(   c                     d }d }||fD ]f}|                      t                    5 } |             d d d            n# 1 swxY w Y   |                     dt          |j                             gd S )Nc                       t          d          )Ntest_string	Exceptionr#   r(   r&   foo_commentedz_TestMiscErrorHandling.test_commented_func_definition_is_not_a_definition.<locals>.foo_commentedT       M***r(   c                       t          d          )z> def docstring containing def might match function definition!rQ   rR   r#   r(   r&   foo_docstringz_TestMiscErrorHandling.test_commented_func_definition_is_not_a_definition.<locals>.foo_docstringX   rU   r(   rQ   )r*   rS   r,   r-   r.   )r/   rT   rW   r)   r1   s        r&   2test_commented_func_definition_is_not_a_definitionzHTestMiscErrorHandling.test_commented_func_definition_is_not_a_definitionN   s    	+ 	+ 	+	+ 	+ 	+ #M2 	@ 	@D""9--                MM-V-=)>)>????		@ 	@s   >A	A	c                 T    G d dt                     }t          |          d             }|                     t          j                  5 } |t          ddg                     d d d            n# 1 swxY w Y   d}|                     |t          |j                             d S )Nc                       e Zd Zd ZdS )FTestMiscErrorHandling.test_use_of_ir_unknown_loc.<locals>.TestPipelinec                    d}t          |          }|                    t          d           |                    t          d           |                    t          d           |                    t
          d           |                    t          d           |                    t          d           |                    t          d           |	                                 |gS )	Nbad_DCE_pipelinezanalyzing bytecodezfix up argszprocessing IRDCEznopython frontendznative loweringznopython mode backend)
r   add_passr   r   r   r   r   r   r   finalize)r/   namepms      r&   define_pipelineszWTestMiscErrorHandling.test_use_of_ir_unknown_loc.<locals>.TestPipeline.define_pipelinese   s    ) &&-/CDDDI}555L/::: /77713FGGGN,=>>>O-DEEEtr(   N)r4   r5   r6   rc   r#   r(   r&   TestPipeliner[   d   s#            r(   rd   )pipeline_classc                     dS )Nr   r#   rM   s    r&   fz;TestMiscErrorHandling.test_use_of_ir_unknown_loc.<locals>.fu   s    1r(   r    r;   z File "unknown location", line 0:)	r   r   r*   r   r+   iterr,   r-   r.   )r/   rd   rh   r1   r2   s        r&   test_use_of_ir_unknown_locz0TestMiscErrorHandling.test_use_of_ir_unknown_locb   s   	 	 	 	 	< 	 	 	" 
\	*	*	*	 	 
+	*	 v122 	fAdAa5kkNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 6hF$4 5 566666s   A33A7:A7c                     |                      t          j                  5 } |             d d d            n# 1 swxY w Y   ddg}|D ]*}|                     |t	          |j                             +d S )NzThe use of az'in globals, is not supported as globals)r*   r   r+   r,   r-   r.   )r/   r)   r1   r2   exs        r&   check_write_to_globalsz,TestMiscErrorHandling.check_write_to_globals   s    v122 	fDFFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #$MN 	5 	5BMM"c&"2334444	5 	5s   7;;c                 V    ddl m} |                     t          |                     d S )Nr   )global_reflected_write)"numba.tests.errorhandling_usecasesro   rm   r   )r/   ro   s     r&   *test_handling_of_write_to_reflected_globalz@TestMiscErrorHandling.test_handling_of_write_to_reflected_global   s7    MMMMMM##D)?$@$@AAAAAr(   c                 V    ddl m} |                     t          |                     d S )Nr   )global_dict_write)rp   rs   rm   r   )r/   rs   s     r&   +test_handling_of_write_to_typed_dict_globalzATestMiscErrorHandling.test_handling_of_write_to_typed_dict_global   s7    HHHHHH##D):$;$;<<<<<r(   c                    t          d          d             }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   d}|                     |t          |j                             d S )NT)parallelc                  *    t          d          D ]} d S rF   )prange)is    r&   foozPTestMiscErrorHandling.test_handling_forgotten_numba_internal_import.<locals>.foo   s$    BZZ   r(   zC'prange' looks like a Numba internal function, has it been importedr?   )r/   rz   r1   r2   s       r&   -test_handling_forgotten_numba_internal_importzCTestMiscErrorHandling.test_handling_forgotten_numba_internal_import   s    	t				 	 
		 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	+hF$4 5 566666   AAAc                 (   d }d}t          d          t          fD ]t}|                     t          j                  5 }  ||                       d d d            n# 1 swxY w Y   |                     |t          |j                             ud S )Nc                  8    d t          d          D              d S )Nc              3      K   | ]}|V  d S r"   r#   ).0r$   s     r&   	<genexpr>zdTestMiscErrorHandling.test_handling_unsupported_generator_expression.<locals>.foo.<locals>.<genexpr>   s"      ""1Q""""""r(   rG   )ranger#   r(   r&   rz   zQTestMiscErrorHandling.test_handling_unsupported_generator_expression.<locals>.foo   s"    ""b		""""""r(   z-The use of yield in a closure is unsupported.T)forceobj)r   r   r*   r   UnsupportedErrorr,   r-   r.   )r/   rz   r2   decr1   s        r&   .test_handling_unsupported_generator_expressionzDTestMiscErrorHandling.test_handling_unsupported_generator_expression   s    	# 	# 	# C%%%t+ 	; 	;C""6#:;; vC


              MM(C(8$9$9::::	; 	;s   AA"	%A"	c                     t           d             }d}|                     t          j                  5 } |             d d d            n# 1 swxY w Y   |                     |t          |j                             d S )Nc                      t           S r"   rg   r#   r(   r&   rz   zCTestMiscErrorHandling.test_handling_undefined_variable.<locals>.foo   s    Hr(   z"NameError: name 'a' is not definedr?   )r/   rz   r2   r1   s       r&    test_handling_undefined_variablez6TestMiscErrorHandling.test_handling_undefined_variable   s    		 	 
	 8v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	hF$4 5 566666s   A		AAN)r4   r5   r6   rN   rX   rj   rm   rq   rt   r   r{   r   r   r#   r(   r&   rC   rC   @   s        
 
 
@ @ @(7 7 7:5 5 5B B B= = = 7 7 7	; 	; 	;	7 	7 	7 	7 	7r(   rC   c                   |    e Zd Zd Zd Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zed             Zd ZdS )TestErrorMessagesc                    dd t                    fd            }t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }|                     t          d         	                                d         |           |                     |           d S )Nspecific_reasonc                      d S r"   r#   r#   r(   r&   rz   z2TestErrorMessages.test_specific_error.<locals>.foo       Dr(   c                  ,    t          j                   r"   )r   NumbaValueError)given_reasons   r&   ol_fooz5TestErrorMessages.test_specific_error.<locals>.ol_foo   s    (666r(   c                                     d S r"   r#   rz   s   r&   call_fooz7TestErrorMessages.test_specific_error.<locals>.call_foo       CEEEEEr(   specific_errorr   )
r   r   r*   r   r+   r-   r.   r,   error_reasons
splitlines)r/   r   r   r1   excstrrz   r   s        @@r&   test_specific_errorz%TestErrorMessages.test_specific_error   s5   (	 	 	 
#	7 	7 	7 	7 
	7 
	 	 	 	 
	 v122 	fHJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&m$45@@BB1EvNNNlF+++++   A**A.1A.c                 8   d t                    d             }t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }|                     d|           d S )Nc                      d S r"   r#   r#   r(   r&   rz   z2TestErrorMessages.test_no_match_error.<locals>.foo   r   r(   c                      d S r"   r#   r#   r(   r&   r   z5TestErrorMessages.test_no_match_error.<locals>.ol_foo   s    4r(   c                                     d S r"   r#   r   s   r&   r   z7TestErrorMessages.test_no_match_error.<locals>.call_foo   r   r(   zNo match)r   r   r*   r   r+   r-   r.   r,   )r/   r   r   r1   r   rz   s        @r&   test_no_match_errorz%TestErrorMessages.test_no_match_error   s    	 	 	 
#	 	 
	 
	 	 	 	 
	 v122 	fHJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&j&)))))   A%%A),A)c                    t           d             }|                     t          j                  5 } |             ddd           n# 1 swxY w Y   t	          |j                  }|                     t          d                                         d         |           t          j
                            ddd          }d| d	}|                     |                    |          |           dS )
z Checks that the reported source location for an overload is the
        overload implementation source, not the actual function source from the
        target library.c                  D    t           j                            d           d S )Nchars)r=   linalgsvdr#   r(   r&   rz   zDTestErrorMessages.test_error_function_source_is_correct.<locals>.foo   s    IMM'"""""r(   Nr   r   numbar=   z	linalg.pyz'Overload in function 'svd_impl': File: :)r   r*   r   r+   r-   r.   r,   r   r   ospathjoinformat)r/   rz   r1   r   expected_filer2   s         r&   %test_error_function_source_is_correctz7TestErrorMessages.test_error_function_source_is_correct   s    
	# 	# 
	# v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&m$45@@BB1EvNNNWdK@@M]MMMhoom44f=====rA   c                 (   t           d             }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t	          |j                  }|                     d|           |                     d|           d S )Nc                      ddz   S )NrM   r    r#   r#   r(   r&   rz   z<TestErrorMessages.test_concrete_template_source.<locals>.foo   s    7Nr(   zOverload of function 'add'	No match.r   r*   r   r+   r-   r.   r,   r/   rz   r1   r   s       r&   test_concrete_template_sourcez/TestErrorMessages.test_concrete_template_source   s    		 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&2F;;; 	k6*****rA   c                     t           d             }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t	          |j                  }|                     d|           d S )Nc                       t          d          S Nr    )lenr#   r(   r&   rz   z<TestErrorMessages.test_abstract_template_source.<locals>.foo  s    q66Mr(   zOverload of function 'len'r   r   s       r&   test_abstract_template_sourcez/TestErrorMessages.test_abstract_template_source  s    		 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&2F;;;;;rA   c                     t           d             }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t	          |j                  }|                     d|           d S )Nc                  *    t          j        d           S r"   )r=   angler#   r(   r&   rz   z<TestErrorMessages.test_callable_template_source.<locals>.foo  s    8D>>!r(   z6No implementation of function Function(<function angler   r   s       r&   test_callable_template_sourcez/TestErrorMessages.test_callable_template_source  s    		" 	" 
	" v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&N	 	 	 	 	rA   c                    d t                    d             }t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }|                     d|           t          j	        
                    ddd          }d| d	}|                     |                    |          |           |                     d
|           d S )Nc                     d S r"   r#   rH   s    r&   barzDTestErrorMessages.test_overloadfunction_template_source.<locals>.bar  r   r(   c                     d S r"   r#   rH   s    r&   ol_barzGTestErrorMessages.test_overloadfunction_template_source.<locals>.ol_bar       Dr(   c                        d          S r   r#   )r   s   r&   rz   zDTestErrorMessages.test_overloadfunction_template_source.<locals>.foo$  s    3q66Mr(   z
<numerous>r   testsztest_errorhandling.pyz"Overload of function 'bar': File: r   r   )r   r   r*   r   r+   r-   r.   assertNotInr   r   r   r,   r   )r/   r   rz   r1   r   r   expected_olr   s          @r&   %test_overloadfunction_template_sourcez7TestErrorMessages.test_overloadfunction_template_source  s`   	 	 	 
#	 	 
	 
	 	 	 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&& 	v...Wg%<> >K=KKKk((77@@@k6*****r   c                    ddt           fd            t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }|                     t          d         	                                d         |           |                     |           |                     |           |                     d|           d S )Nzx must be literalzarray.ndim must be 1c                     t          |t          j                  st          j                  |j        dk    rt          j                  t          j        ||          }d }||fS )Nr    c                     d S r"   r#   )contextbuilder	signatureargss       r&   codegenzSTestErrorMessages.test_intrinsic_template_source.<locals>.myintrin.<locals>.codegenD      r(   )
isinstancer   IntegerLiteralr   RequireLiteralValuendimr   intp)	typingctxr$   arrsigr   given_reason1given_reason2s        r&   myintrinzBTestErrorMessages.test_intrinsic_template_source.<locals>.myintrin:  sp    a!566 @0???x1}},];;;*Q$$C  <r(   c                  H    t          j        d          }  d|            d S )N)r;   r;   r    )r=   zeros)r   r   s    r&   call_intrinzETestErrorMessages.test_intrinsic_template_source.<locals>.call_intrinH  s*    (6""CHQr(   r   r   zIntrinsic in function)
r	   r   r*   r   r+   r-   r.   r,   r   r   )r/   r   r1   r   r   r   r   s       @@@r&   test_intrinsic_template_sourcez0TestErrorMessages.test_intrinsic_template_source5  sR   +.		  	  	  	  	  
	  
	 	 	 	 
	 v122 	fKMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&m$45@@BB1EvNNNmV,,,mV,,,-v66666s   A##A'*A'c                 B   t          t          j        d          d             }t          d             }|                     t
          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }| 	                    d|           d S )N
isnonsensec                     d S r"   r#   r/   s    r&   ol_unicode_isnonsensezTTestErrorMessages.test_overloadmethod_template_source.<locals>.ol_unicode_isnonsenseY  r   r(   c                  .    d                                  d S Nabcr   r#   r(   r&   rz   zBTestErrorMessages.test_overloadmethod_template_source.<locals>.foo]  s    r(   ,Overload of function 'ol_unicode_isnonsense')
r
   r   UnicodeTyper   r*   r   r+   r-   r.   r,   r/   r   rz   r1   r   s        r&   #test_overloadmethod_template_sourcez5TestErrorMessages.test_overloadmethod_template_sourceV  s     
*L	9	9	 	 
:	9	 
	 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&DfMMMMMr   c                 B   t          t          j        d          d             }t          d             }|                     t
          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }| 	                    d|           d S )Nr   c                     d S r"   r#   r   s    r&   r   zWTestErrorMessages.test_overloadattribute_template_source.<locals>.ol_unicode_isnonsensej  r   r(   c                      dj          d S r   r   r#   r(   r&   rz   zETestErrorMessages.test_overloadattribute_template_source.<locals>.foon  s    r(   r   )
r   r   r   r   r*   r   r+   r-   r.   r,   r   s        r&   &test_overloadattribute_template_sourcez8TestErrorMessages.test_overloadattribute_template_sourceg  s     
E-|	<	<	 	 
=	<	 
	 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&DfMMMMMr   c                    ddl m t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j                  }|                     d|           d S )Nr   c_cosc                        d           d S NrM   r#   r   s   r&   rz   zMTestErrorMessages.test_external_function_pointer_template_source.<locals>.foo{  s    E#JJJJJr(   .Type Restricted Function in function 'unknown')	numba.tests.ctypes_usecasesr   r   r*   r   r+   r-   r.   r,   )r/   rz   r1   r   r   s       @r&   .test_external_function_pointer_template_sourcez@TestErrorMessages.test_external_function_pointer_template_sourcex  s    555555		 	 	 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&FOOOOOr|   c                 D   ddl m} |                                 |j        t          fd            }|                     t          j                  5 } |             d d d            n# 1 swxY w Y   t          |j	                  }| 
                    d|           d S )Nr   )cffi_usecasesc                        d           d S r   r#   )r)   s   r&   rz   zITestErrorMessages.test_cffi_function_pointer_template_source.<locals>.foo  s    DIIIIIr(   r   )numba.testsr   initcffi_cosr   r*   r   r+   r-   r.   r,   )r/   modrz   r1   r   r)   s        @r&   *test_cffi_function_pointer_template_sourcez<TestErrorMessages.test_cffi_function_pointer_template_source  s    444444


|		 	 	 	 
	 v122 	fCEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 V%&&FOOOOOs   A++A/2A/c                    t           j         G d dt          j                              } G d dt           j                  }t          j        ||ddg           |                     t          j                  5 } |dd	           d d d            n# 1 swxY w Y   t          |j
                  }|                     d
|           d S )Nc                       e Zd ZdS );TestErrorMessages.test_missing_source.<locals>.ParticleTypeN)r4   r5   r6   r#   r(   r&   ParticleTyper    s        Dr(   r  c                       e Zd Zd ZdS )7TestErrorMessages.test_missing_source.<locals>.Particlec                 B    t           j                            | |          S r"   )r   StructRefProxy__new__)clsposmasss      r&   r  z?TestErrorMessages.test_missing_source.<locals>.Particle.__new__  s     /77SAAAr(   N)r4   r5   r6   r  r#   r(   r&   Particler	    s(        B B B B Br(   r  r  r  r    r;   )r  r  z#missing a required argument: 'mass')r   registerr   	StructRefr  define_proxyr*   r   r+   r-   r.   r,   )r/   r  r  r1   r   s        r&   test_missing_sourcez%TestErrorMessages.test_missing_source  s7   			 	 	 	 	5? 	 	 
			B 	B 	B 	B 	By/ 	B 	B 	B
 	xvGGGv122 	$fH####	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ V%&&;VDDDDDs   :BBBN)r4   r5   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r#   r(   r&   r   r      s       , , ,,* * *& > > >$+ + + 
< 
< 
<  + + +47 7 7BN N N"N N N"P P P P P PE E E E Er(   r   c                       e Zd Zd ZdS )"TestDeveloperSpecificErrorMessagesc                 N   d }t          dd          5  |                     t          j                  5 } t	          d          |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |j                  }|                     d|           d S )Nc                 0    |                      d           d S )N)maxrH   s    r&   rz   zPTestDeveloperSpecificErrorMessages.test_bound_function_error_string.<locals>.foo  s    EE"IIIIIr(   DEVELOPER_MODEr    zvoid(int64[:,:])ztoo many positional arguments)r   r*   r   r+   r   r-   r.   r,   r   s       r&    test_bound_function_error_stringzCTestDeveloperSpecificErrorMessages.test_bound_function_error_string  s(   	 	 	 -q11 	. 	.""6#566 .&('((---. . . . . . . . . . . . . . .	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. V%&&5v>>>>>s4    A0AA0A	A0 A	!A00A47A4N)r4   r5   r6   r  r#   r(   r&   r  r    s#        
? 
? 
? 
? 
?r(   r  c                   
   e Zd ZdZd Zd Zd Zd Z  ej	        ddi          e          Z
  ej	        dd	i          e          Z ej	        ddi          d
             Z ej	        ddi          d             ZdS )TestCapturedErrorHandlingzjChecks that the way errors are captured changes depending on the env
    var "NUMBA_CAPTURED_ERRORS".
    c           	      B   d t                    d             }t          j                    5  t          j        dt          j                   dt          fdt          j        ffD ]\  }}t          d|          5  | 	                    |          5 }t          d          fd            }d d d            n# 1 swxY w Y   d	}|                     |t          |j                             d d d            n# 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )
Nc                     d S r"   r#   rH   s    r&   r   z=TestCapturedErrorHandling.test_error_in_overload.<locals>.bar  r   r(   c                     | j          d }|S )Nc                     d S r"   r#   rH   s    r&   implzNTestCapturedErrorHandling.test_error_in_overload.<locals>.ol_bar.<locals>.impl  r   r(   )some_invalid_attr)r$   r#  s     r&   r   z@TestCapturedErrorHandling.test_error_in_overload.<locals>.ol_bar  s      Kr(   ignore	new_style	old_styleCAPTURED_ERRORSvoid(int64)c                      |            d S r"   r#   r$   r   s    r&   rz   z=TestCapturedErrorHandling.test_error_in_overload.<locals>.foo  s    CFFFFFr(   z+object has no attribute 'some_invalid_attr')r   warningscatch_warningssimplefilterr   NumbaPendingDeprecationWarningAttributeErrorr+   r   r*   r   r,   r-   r.   )r/   r   style	err_classr1   rz   r2   r   s          @r&   test_error_in_overloadz0TestCapturedErrorHandling.test_error_in_overload  sA   	 	 	 
#	 	 
	 $&& 	C 	C!("("GI I I '2>%B&163E%F%H 	C 	C y$%6>> C C**955 #m,,# # # # -,## # # # # # # # # # # # # # #
  MHMM(C0@,A,ABBBC C C C C C C C C C C C C C C	C	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	CsZ   AD<C:B9	-C:9B==C: B=-C:.D:C>>DC>DDDc                    d| d}t           j                                        }|                    |           t	          j        t          j        dd|gt          j        t          j        |          }|	                                \  }}|j
        dk    r-t          d|j
        d|                                d	          ||fS )
Nzif 1:
            z

            z-Wallz-c)stdoutstderrenvr   zprocess failed with code z: stderr follows

)r   environcopyupdate
subprocessPopensys
executablePIPEcommunicate
returncodeAssertionErrordecode)r/   runcoder7  codeproc_envpopenouterrs           r&   _run_in_separate_processz2TestCapturedErrorHandling._run_in_separate_process  s       :??$$ #.'4!F(2(2%-/ / /
 $$&&Sq   .-2-=-=-=szz||||"M N N NCxr(   c                    ddl m} d}ddi}|                     ||          \  }}|                     ||                                           ddi}|                     ||          \  }}|                     d|                                           ddi}|                     ||          \  }}|                     d|                                           d S )	Nr   )_old_style_deprecation_msgz
        import numba
        NUMBA_CAPTURED_ERRORSr'   r/  r&  )numba.core.configrM  rK  r,   rD  r   )r/   rM  rF  r7  _outrJ  s         r&   $test_old_style_deprecation_on_importz>TestCapturedErrorHandling.test_old_style_deprecation_on_import  s    @@@@@@
 '411$<<	c0#**,,??? '+11$<<	c93::<<HHH '411$<<	c93::<<HHHHHr(   c                    t          j        dt          j                   d t	                    d             }|                     t          j                  5 }|                     t          j                  5  t          d          fd            }d d d            n# 1 swxY w Y   | 	                    dt          |j         d         j                             d d d            d S # 1 swxY w Y   d S )Nalwaysc                     d S r"   r#   rH   s    r&   r   zBTestCapturedErrorHandling._test_old_style_deprecation.<locals>.bar  r   r(   c                      t          d          NzInvalid attributer0  rH   s    r&   r   zETestCapturedErrorHandling._test_old_style_deprecation.<locals>.ol_bar       !4555r(   r)  c                      |            d S r"   r#   r+  s    r&   rz   zBTestCapturedErrorHandling._test_old_style_deprecation.<locals>.foo      CFFFFFr(   zMCode using Numba extension API maybe depending on 'old_style' error-capturingr   )r,  r.  r   r/  r   assertWarnsr*   r+   r   r,   r-   messager/   r   warnsrz   r   s       @r&   _test_old_style_deprecationz5TestCapturedErrorHandling._test_old_style_deprecation	  s   h(MNNN	 	 	 
#	6 	6 
	6 fCDD 
	""6#566  m$$    %$              
 MM"EN1%-..  
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	s6    C-;B"C-"B&	&C-)B&	*6C--C14C1rN  r'  )envvarsdefaultc                    t          j        dt          j                   d t	                    d             }t          j        d          5 }|                     t          j                  5  t          d          fd            }d d d            n# 1 swxY w Y   | 	                    t          |          dd	
           d d d            d S # 1 swxY w Y   d S )NrT  c                     d S r"   r#   rH   s    r&   r   zDTestCapturedErrorHandling.test_old_style_no_deprecation.<locals>.bar2  r   r(   c                 *    t          j        d          rW  )r   r+   rH   s    r&   r   zGTestCapturedErrorHandling.test_old_style_no_deprecation.<locals>.ol_bar5  s    $%8999r(   Trecordr)  c                      |            d S r"   r#   r+  s    r&   rz   zDTestCapturedErrorHandling.test_old_style_no_deprecation.<locals>.foo;  r[  r(   r    There should not be any warningsmsg)r,  r.  r   r/  r   r-  r*   r+   r   assertEqualr   r^  s       @r&   test_old_style_no_deprecationz7TestCapturedErrorHandling.test_old_style_no_deprecation+  s   
 	h(MNNN	 	 	 
#	: 	: 
	: $D111 	EU""6#566  m$$    %$              
 SZZ!C  E E E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es6    C1BCB	CB	 (CCCr&  c                    t          j        dt          j                   d t	                    d             }t          j        d          5 }|                     t                    5  t          d          fd            }d d d            n# 1 swxY w Y   | 	                    t          |          dd	
           d d d            d S # 1 swxY w Y   d S )NrT  c                     d S r"   r#   rH   s    r&   r   zATestCapturedErrorHandling.test_new_style_no_warnings.<locals>.barI  r   r(   c                      t          d          rW  rX  rH   s    r&   r   zDTestCapturedErrorHandling.test_new_style_no_warnings.<locals>.ol_barL  rY  r(   Trf  r)  c                      |            d S r"   r#   r+  s    r&   rz   zATestCapturedErrorHandling.test_new_style_no_warnings.<locals>.fooR  r[  r(   r   ri  rj  )r,  r.  r   r/  r   r-  r*   r0  r   rl  r   r^  s       @r&   test_new_style_no_warningsz4TestCapturedErrorHandling.test_new_style_no_warningsB  s   
 	h(MNNN	 	 	 
#	6 	6 
	6 $D111 	EU"">22  m$$    %$              
 SZZ!C  E E E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es6   C,BCB	CB	(CCCN)r4   r5   r6   __doc__r3  rK  rR  r`  r   run_test_in_subprocesstest_old_style_deprecation"test_default_old_style_deprecationrm  rr  r#   r(   r&   r  r    sD        C C C:  *I I I4  0"!@!@(+6" " "!"# "#*)H)H()4* * *!*# *#& %X$(+6  E E E( %X$(+6  E E E E Er(   r  __main__)4rs  r>  r<  numpyr=   r   r,  r   r   r   r   
numba.corer   numba.experimentalr   numba.extendingr   r	   r
   r   numba.core.compilerr   numba.core.untyped_passesr   r   r   numba.core.typed_passesr   r   r   r   numba.core.compiler_machineryr   numba.core.types.functionsr   r   numba.tests.supportr   r   r   r   r   r   unittestr   r8   rC   r   r  r  r4   mainr#   r(   r&   <module>r     s-    


         				  " " " " " " " " " "       ( ( ( ( ( (1 1 1 1 1 1 1 1 1 1 1 1 , , , , , ,6 6 6 6 6 6 6 6 6 6F F F F F F F F F F F F 5 5 5 5 5 5 D D D D D D> > > > > > > > > > > > > > > > ; ; ; ; ;h&7 ; ; ;&7 7 7 7 7x0 7 7 7q7 q7 q7 q7 q7H- q7 q7 q7hrE rE rE rE rE) rE rE rEj? ? ? ? ?h6G ? ? ?_E _E _E _E _EX _E _E _ED zHMOOOOO r(   