
    X-PhsB                    l   d Z ddlmZ ddlZddlZddlZddl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 ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 g dZ3ej4        dk    re35                    d           ej4        dk    re35                    d           dZ6dZ7d4d Z8ej9        d5d#            Z: G d$ d%e.          Z; G d& d'e;          Z< G d( d)e;          Z= G d* d+e;          Z>d6d0Z?d7d3Z@dS )8z6Test cases for building an C extension and running it.    )annotationsN)Iterator)Any)build)CompileError)Options)mypyc_output_dirtest_temp_dir)DataDrivenTestCase)assert_module_equivalenceperform_file_operations)construct_groups)
emitmodule)Errors)CompilerOptions)test_data_prefix)check_serialization_roundtrip)ICODE_GEN_BUILTINSTESTUTIL_PATHMypycDataSuiteassert_test_outputfudge_dir_mtimesshow_cuse_custom_builtins)"zrun-async.testzrun-misc.testzrun-functions.testzrun-integers.testzrun-i64.testzrun-i32.testzrun-i16.testzrun-u8.testrun-floats.testzrun-math.testzrun-bools.testzrun-strings.testzrun-bytes.testzrun-tuples.testzrun-lists.testzrun-dicts.testzrun-sets.testzrun-primitives.testzrun-loops.testzrun-exceptions.testzrun-imports.testzrun-classes.testzrun-traits.testzrun-generators.testzrun-generics.testrun-multimodule.testzrun-bench.testrun-mypy-sim.testrun-dunders.testzrun-dunders-special.testzrun-singledispatch.testzrun-attrs.testzrun-python37.testzrun-python38.test)   
   zrun-match.testr      zrun-python312.testzfrom setuptools import setup
from mypyc.build import mypycify

setup(name='test_run_output',
      ext_modules=mypycify({}, separate={}, skip_cgen_input={!r}, strip_asserts=False,
                           multi_file={}, opt_level='{}'),
)
r   script_namestrscript_args	list[str]returnboolc                   t           j                                        }d| i}	 	 | t           j        d<   |t           j        dd<   t          | d          5 }t	          |                                |           ddd           n# 1 swxY w Y   |t           _        n# |t           _        w xY wn># t          $ r1}|j        dk    rt          ||j        dk    p|j        du cY d}~S d}~ww xY wdS )a  Run a setup script in a somewhat controlled environment.

    This is adapted from code in distutils and our goal here is that is
    faster to not need to spin up a python interpreter to run it.

    We had to fork it because the real run_setup swallows errors
    and KeyboardInterrupt with no way to recover them (!).
    The real version has some extra features that we removed since
    we weren't using them.

    Returns whether the setup succeeded.
    __file__r      NrbinterruptedT)	sysargvcopyopenexecread
SystemExitcodeKeyboardInterrupt)r#   r%   	save_argvgfes         S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/test/test_run.py	run_setupr<   ^   s>    I	[!A-	!%CHQK&CHQRRLk4(( "AQVVXXq!!!" " " " " " " " " " " " " " " !CHHyCH    H - - - 6]""#*v{,afn,,,,,,- 4sS   0B #B8B BB BB B. B**B. .
C)8&C$C)$C)targetIterator[None]c              #     K   t          j                    }t          j        |            	 d V  t          j        |           d S # t          j        |           w xY w)N)osgetcwdchdir)r=   dirs     r;   chdir_managerrD      sR      
)++CHV
s   A Ac                  J    e Zd ZdZeZeZdZdZdZ	dZ
ddZdd	ZddZddZdS )TestRunz1Test cases that build a C extension and run code.TFtestcaser   r'   Nonec                    t          t          j                            | j        t
                    |          5  t          d          5  |                     |           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 )Ntmp)r   r@   pathjoindata_prefixr   rD   run_case_inner)selfrG   s     r;   run_casezTestRun.run_case   s     T-=?Q R RT\]]	* 	*%  	* 	* )))		* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s5   B	A+B+A/	/B2A/	3BB
Bc                L   t           j                            t                    st          j        t                     d                    |j                  }t          ddd          5 }|                    |           d d d            n# 1 swxY w Y   t          ddd          5 }|                    |           d d d            n# 1 swxY w Y   t          j
        t          d           d}|                     ||           |                                }|g gk    rg }|D ]|}t          t          d	           t          j        d
           |dz  }t#          d          5  t%          |           d d d            n# 1 swxY w Y   |                     ||           }d S )N
	native.pywutf-8encodingzinterpreted.pyztestutil.pyr+   g      ?z..)r@   rK   isdirWORKDIRmkdirrL   inputr1   writeshutilcopyfiler   run_case_step
find_stepsr   timesleeprD   r   )rO   rG   textr9   stepsteps
operationss          r;   rN   zTestRun.run_case_inner   sE   w}}W%% 	HWyy((+sW555 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"C'::: 	aGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	}5558T***##%%RD==E 	/ 	/J Wb))) JsOOOAIDt$$ 4 4'
3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4x....	/ 	/s6   *BBB)CCC&FF		F	incremental_stepintc                B   j                             dd          odj        v }t                      }d|_        d|_        d|_        t          j        d d         |_	        d|_
        d|_        d|_        | j        |_        ddi|j        d<   t!          j        d	d
d           }|g}d
g}d	g}g }	j        D ]g\  }
}t&          j                            |
t,                    }
t&          j                            |
                              d          r	|
                    d          r|
                    d          d                             t&          j        d          }|                    |           |                    t!          j        |
|d                      |	                    |
           |                    |
           t=          j        |
t&          j                             t&          j        !                    |
          |dz                        i|D ]%}d|j        "                    |j#        i           d<   &| j        r.| $                    d                     j%                  |          nd}tM          ||tO          |          dk              }	 tQ          | j)        | j        | j*                  }tW          j,        ||||d          }t[          |          }tW          j.        ||||          \  }}}|j/        r|0                                 J d            nN# tb          $ rA}|j2        D ]*}tg          ti          |j5        j6                             +J d            d }~ww xY w|dk    rto          |           tq          t&          j9        :                    dd                    }tq          t&          j9        :                    dd                    }t&          j        ;                    t&          j                             tx          d                    }t{          |dd          5 }|>                    t~          @                    |||| j)        ||                     d d d            n# 1 swxY w Y   t          |ddg          sGj                             d          rt          |           t          t                     J d             t          jE        d!k    rd"nd#}t          jF        d$|           st          jF        d%|           sJ d&}t&          j        G                    |          s;t&          j                             t          d'd&          }t=          jI        ||           t&          j9        I                                }|rd(nd)|d*<   j                             d+          }|rj|d,k    r%t          jK        d,d-t          jL        |g|.           n5|d/k    r%t          jK        d/d0t          jL        |g|.           n
J d1            J d2            t          jM        t          jL        |gt          jN        t          jO        |3          } t          j        d4k    r| P                    d56           | Q                                d         R                    d7          }!|!                    d8t'          jS                     t&          j         d8          }!|!T                                }"j                             d          rt          |           | jU        dk    rtg                       | jU        d9k    }#d:}$|#rd;}$tg          d<| jU         |$            |#rst          jE                            d=          sTtg                       t          jE        d>k    rd,}nd/}tg          d?| d@           tg          dA           tg          dB           t          t                     |rtg          dC           tg          |!           nS|dk    r
dD}%jV        }&n!dE| dF}%jW        :                    |g           }&|&sfdG|"D             }"t          |"|%|&           |dk    r|j        r|dk    rd:nt          |dz
            }jZ        :                    |dz
            }'|'t          dH|z   |'|j\        j]                   j^        :                    |dz
            }(|(t          dI|z   |(|j\        j_                   | jU        dk    sJ d S )JNz--benchF	BenchmarkT   follow_importserrorzunchecked.*rS   nativeotherz.py.r   z_interpreted.pymypycrR   r+   )
multi_fileseparatestrict_dunder_typing)sourcesoptionscompiler_optionsgroupsalt_lib_path)rx   errorsry   zCompile errorMYPYC_OPT_LEVELMYPYC_DEBUG_LEVELzsetup.pyrT   rU   rV   	build_extz	--inplacez--mypyc-showczCompilation failedwin32pydsoz	native.*.znative.z	driver.pydriver10MYPYC_RUN_BENCHdebuggerlldbz--)envgdbz--argszUnsupported debuggerzaTest can't pass in debugging mode. (Make sure to pass -s to pytest to interact with the debugger))stdoutstderrr   r!      )timeoututf8z  File "i z (likely segmentation fault)z*** Exit status: windarwinz'hint: Use "pytest -n0 -s --mypyc-debug=z- -k <name-substring>" to run test in debuggerzFhint: You may need to build a debug version of Python first and use itz>hint: See also "Debugging Segfaults" in mypyc/doc/dev-intro.mdzTest output:zInvalid outputzInvalid output (step )c                F    g | ]}t          |j        j                  S  )fix_native_line_numberfileline).0r   rG   s     r;   
<listcomp>z)TestRun.run_case_step.<locals>.<listcomp>n  s7       SW*4NN      	recheckedstale)`config	getoptionnamer   use_builtins_fixturesshow_tracebackstrict_optionalr.   version_infopython_versionexport_typespreserve_astsallow_empty_bodiesrt   incrementalper_module_optionsr   BuildSourcefilesr@   rK   relpathr
   basename
startswithendswithsplitreplacesepappendr^   r_   rL   dirname
setdefaultmoduleget_separater\   r   lenr   rs   ru   r   parse_and_typecheckr   compile_modules_to_c
num_errorsflush_errorsr   messagesprintr   r   r   r   ri   environgetabspathrZ   r1   r]   setup_formatformatr<   r   copy_output_filesr	   platformglobisfiler   r0   
subprocess
check_call
executablePopenPIPESTDOUTwaitcommunicatedecoderA   
splitlines
returncodeoutputoutput2r   r$   expected_rechecked_modulesr   managerrechecked_modulesexpected_stale_modulesstale_modules))rO   rG   rh   benchrw   sourcerv   module_namesmodule_paths	to_deletefnrd   r   rt   ry   rx   resultr{   ircfiles_r:   r   	opt_leveldebug_level
setup_filer9   suffixdriver_pathdefault_driverr   r   procr   outlinessignalextramsgexpectedexpected_recheckedexpected_stales)    `                                       r;   r`   zTestRun.run_case_step   s	   )))U;;\x}@\))(,%!%"&!$!1"1"!5# $%)""m 6Fw4O"=1";$??( z#} 	  
	a 
	aHB]33Bw##..w77 aBKK<N<N axx}}Q'//<<##D)))u0T4@@AAA  $$$##B'''BGLL1D1DdM^F^$_$_``` 	U 	UFPTG&11&-DDWMM }Ddii779IJJJ 	 "'8S5F5F5JKK	*.?%)%>     
  3!1   F G__F&;)9&QW  MB   .##%%%-o---.  	* 	* 	*
 R R,T8=(-PPQQQQ)/)))	* q  )"---
'8!<<==	"*..)<a@@AAW__RW\\':%F%FGG
*cG444 	GG## (FDOYP[   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 k;%?@@ 	/((99 v.///..... ,'11ty-V--..O$)<Nf<N<N2O2OOOO!w~~k** 	5  W\\*:HkRRNK444joo(-!63?,,Z88 	6!!%vtS^[&QWZ[[[[[U""%uh&TZ]^^^^^44444Q   ^[)?$	
 
 
 w&&IIbI!!!!!##A&--f55 @29;; @ @ @*MM$$&&?$$_55 	6NNN?aGGG_+FE 76>do>u>>??? 
Xcl55e<< 
X<8++%HH$Huhuuu   ^___VWWW.///  	B.!!!&MMMM1$$&#?A.>AAA#+//0@"EE    [c   x3AAAaG$7+q00RRc:JQ:N6O6OF!)!D!H!HIY\]I]!^!^!-)&(*<fn>^   &<@@AQTUAUVVN))f$nfn6R   !######s+   "B
L- -
M87<M33M8>8RR	Rprogram_textr$   r   c                0   d}t          j        |                    |          |t           j                  }|s4t          j        |                    d          |t           j                  }|r't	          j        |                    d                    S dS )Nz# separate{}: (\[.*\])$)flagsr   r+   T)researchr   	MULTILINEastliteral_evalgroup)rO   r   rh   templatems        r;   r   zTestRun.get_separate  s    -Ihoo&677R\ZZZ 	Q	(//"--|2<PPPA 	#AGGAJJ///4r   N)rG   r   r'   rH   )rG   r   rh   ri   r'   rH   )r   r$   rh   ri   r'   r   )__name__
__module____qualname____doc__r   r
   	base_pathoptional_outrs   rt   ru   rP   rN   r`   r   r   r   r;   rF   rF      s        ;;EILJH * * * *!/ !/ !/ !/F$ $ $ $B     r   rF   c                  "    e Zd ZdZdZdZddgZdS )TestRunMultiFilezRun the main multi-module tests in multi-file compilation mode.

    In multi-file mode each module gets compiled into a separate C file,
    but all modules (C files) are compiled together.
    T_multir   r   N)r   r   r   r   rs   test_name_suffixr   r   r   r;   r  r    s0          J#%89EEEr   r  c                  "    e Zd ZdZdZdZddgZdS )TestRunSeparateaY  Run the main multi-module tests in separate compilation mode.

    In this mode there are multiple compilation groups, which are compiled
    incrementally. Each group is compiled to a separate C file, and these C
    files are compiled separately.

    Each compiled module is placed into a separate compilation group, unless
    overridden by a special comment. Consider this example:

      # separate: [(["other.py", "other_b.py"], "stuff")]

    This puts other.py and other_b.py into a compilation group named "stuff".
    Any files not mentioned in the comment will get single-file groups.
    T	_separater   r   N)r   r   r   r   rt   r  r   r   r   r;   r  r    s0          H"#%89EEEr   r  c                  "    e Zd ZdZdZdZddgZdS )TestRunStrictDunderTypingz(Run the tests with strict dunder typing.T_dunder_typingr   r   N)r   r   r   r   ru   r  r   r   r   r;   r  r    s+        22'!23EEEr   r  messagefnamdeltari   c                    t           j                                      t          j        dfd|           } t          j        dfd|           } | S )ap  Update code locations in test case output to point to the .test file.

    The description of the test case is written to native.py, and line numbers
    in test case output often are relative to native.py. This translates the
    line numbers to be relative to the .test file that contains the test case
    description, and also updates the file name to the .test file name.

    Args:
        message: message to update
        fnam: path of the .test file
        delta: line number of the beginning of the test case in the .test file

    Returns updated message (or original message if we couldn't find anything).
    znative\.py:([0-9]+):c                X    dt          |                     d                    z   fz  S )Nz%s:%d:r+   ri   r   r   r  r  s    r;   <lambda>z(fix_native_line_number.<locals>.<lambda>  s&    8tS__u=T6U+U r   z"native.py", line ([0-9]+),c                X    dt          |                     d                    z   fz  S )Nz"%s", line %d,r+   r  r  s    r;   r  z(fix_native_line_number.<locals>.<lambda>  s'    "dC

OOe,C%DD r   )r@   rK   r   r   sub)r  r  r  s    ``r;   r   r     sp     7D!!Df!U!U!U!U!UW^ G f&DDDDD G
 Nr   
target_dirrH   c                    	 t          j        |            n# t          $ r Y d S w xY wt          j        d          D ]}t	          j        ||            t          j                            d|  d           d S )Nzbuild/*.[ch]z
Generated files: z (for first failure only)

)	r@   r[   OSErrorr   r^   r0   r.   r   r]   )r  r  s     r;   r   r     s    
    	
 	.)) & &D*%%%%JT:TTTUUUUUs    
%%)r#   r$   r%   r&   r'   r(   )r=   r$   r'   r>   )r  r$   r  r$   r  ri   r'   r$   )r  r$   r'   rH   )Ar   
__future__r   r   
contextlibr   os.pathr@   r   r^   r   r.   rb   collections.abcr   typingr   mypyr   mypy.errorsr   mypy.optionsr   mypy.test.configr	   r
   mypy.test.datar   mypy.test.helpersr   r   mypyc.buildr   mypyc.codegenr   mypyc.errorsr   mypyc.optionsr   mypyc.test.configr   mypyc.test.test_serializationr   mypyc.test.testutilr   r   r   r   r   r   r   r   r   r   r   rZ   r<   contextmanagerrD   rF   r  r  r  r   r   r   r   r;   <module>r-     s\   < < " " " " " " 



       				      



  $ $ $ $ $ $             $ $ $ $ $ $             < < < < < < < < - - - - - - P P P P P P P P ( ( ( ( ( ( $ $ $ $ $ $       ) ) ) ) ) ) . . . . . . G G G G G G                 #	 #	 #	J w	LL!"""w	LL%&&&        F        n   D	: 	: 	: 	: 	:w 	: 	: 	:: : : : :g : : :*4 4 4 4 4 4 4 4   6V V V V V Vr   