
    daf                     H   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	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mZmZmZmZmZmZmZ ej4                  Zg dZdZefdZed	fd
Z G d dej>                        Z d Z!e"dk(  r ejF                          yy)    N)support)import_helper)	os_helper)make_pkgmake_scriptmake_zip_pkgmake_zip_scriptassert_python_okassert_python_failurespawn_pythonkill_python)test1test2test3a  # Script may be run with optimisation enabled, so don't rely on assert
# statements being executed
def assertEqual(lhs, rhs):
    if lhs != rhs:
        raise AssertionError('%r != %r' % (lhs, rhs))
def assertIdentical(lhs, rhs):
    if lhs is not rhs:
        raise AssertionError('%r is not %r' % (lhs, rhs))
# Check basic code execution
result = ['Top level assignment']
def f():
    result.append('Lower level reference')
f()
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check population of magic variables
assertEqual(__name__, '__main__')
from importlib.machinery import BuiltinImporter
_loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__)
print('__loader__==%a' % _loader)
print('__file__==%a' % __file__)
print('__cached__==%a' % __cached__)
print('__package__==%r' % __package__)
# Check PEP 451 details
import os.path
if __package__ is not None:
    print('__main__ was located through the import system')
    assertIdentical(__spec__.loader, __loader__)
    expected_spec_name = os.path.splitext(os.path.basename(__file__))[0]
    if __package__:
        expected_spec_name = __package__ + "." + expected_spec_name
    assertEqual(__spec__.name, expected_spec_name)
    assertEqual(__spec__.parent, __package__)
    assertIdentical(__spec__.submodule_search_locations, None)
    assertEqual(__spec__.origin, __file__)
    if __spec__.cached is not None:
        assertEqual(__spec__.cached, __cached__)
# Check the sys module
import sys
assertIdentical(globals(), sys.modules[__name__].__dict__)
if __spec__ is not None:
    # XXX: We're not currently making __main__ available under its real name
    pass # assertIdentical(globals(), sys.modules[__spec__.name].__dict__)
from test import test_cmd_line_script
example_args_list = test_cmd_line_script.example_args
assertEqual(sys.argv[1:], example_args_list)
print('sys.argv[0]==%a' % sys.argv[0])
print('sys.path[0]==%a' % sys.path[0])
# Check the working directory
import os
print('cwd==%a' % os.getcwd())
c                 H    t        | ||      }t        j                          |S N)r   	importlibinvalidate_caches)
script_dirscript_basenamesource	to_returns       4/root/Python-3.12.4/Lib/test/test_cmd_line_script.py_make_test_scriptr   P   s"    J@I!       c                 N    t        | |||||      }t        j                          |S r   )r   r   r   )zip_dirzip_basenamepkg_namer   r   depthr   s          r   _make_test_zip_pkgr"   U   s+    WlHo#U,I!r   c                      e Zd Z	 d@dZdddZdddZd Zd Zej                  dAd       Z
dAd	ZdAd
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&ej                  d%        Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z: e;jx                  e=j|                  j                  d9      d:       e;j                  eAj                  j                  d;      xr9  e=j                  d<      j                   e=j                  d=      j                  k(  d>      d?               ZFy)BCmdLineTestNc
                 &   t         dkD  r"t        d|z         t        t        |             | j                  |d       d|z  }
d|z  }d|z  }d|z  }d|z  }|	t	        j
                         }	d	|	z  }t         dkD  r7t        d
       t        |       t        |       t        |       t        |       | j                  |
j                  d      |       | j                  |j                  d      |       | j                  |j                  d      |       | j                  |j                  d      |       t        j                  j                  s!| j                  |j                  d      |       | j                  |j                  d      |       y )Nr   zOutput from test script %r:r   z__loader__==%az__file__==%az__package__==%rzsys.argv[0]==%azsys.path[0]==%azcwd==%azExpected output:utf-8)verboseprintreprassertEqualosgetcwdassertInencodesysflags	safe_path)selfscript_name	exit_codedataexpected_fileexpected_argv0expected_path0expected_packageexpected_loaderexpected_cwdprinted_loaderprinted_fileprinted_packageprinted_argv0printed_path0printed_cwds                   r   _check_outputzCmdLineTest._check_output]   sV    Q;/+=>$t*A&)O;%5+.>>)N:)N:99;L,.Q;$%,/"- +n++G4d;l))'2D9o,,W5t<m**73T:yy""MM-..w7>k((148r   cwdc                    t        |t              r|g}g t        j                         ||t        }
t        |
d|d|	\  }}}| j                  ||||z   ||||||	       y )NF
__isolated__cwd)
isinstancestrr   !optim_args_from_interpreter_flagsexample_argsr
   rB   )r2   script_exec_argsr6   r7   r8   r9   r:   rD   cmd_line_switchesenv_varsrun_argsrcouterrs                 r   _check_scriptzCmdLineTest._check_script|   s     &, 01JW>>@ J&J)9J<HJ'%s
6>
C 	+RsM)>+_c	Cr   c                &   t        |t              r|f}nt        |      }||z   }t        |d|d|\  }}}	t        dkD  r1t        d|        t        t        |	             t        d|z         | j                  |j                  d      |	       y )NFrF   r   zOutput from test script zExpected output: %rr&   )	rI   rJ   tupler   r'   r(   r)   r-   r.   )
r2   rM   expected_msgrD   rN   rO   rP   rQ   rR   rS   s
             r   _check_import_errorzCmdLineTest._check_import_error   s    &, 02$%56$'77,%s
6>
C Q;,-=q,ABC$s)',67l))'2C8r   c                     t        dd      \  }}}t        t        j                  j                        j                  d      }| j                  ||       y )N-czprint(__loader__)r&   )r
   r)   r   	machineryBuiltinImporterr.   r-   )r2   rQ   rR   rS   expecteds        r   test_dash_c_loaderzCmdLineTest.test_dash_c_loader   sD    '.ABC	++;;<CCGLh$r   c                 B   t               }	 |j                  j                  d       |j                  j                          t	        |      }t        t        j                  j                        j                  d      }| j                  ||       y # t	        |      }w xY w)Ns   print(__loader__)
r&   )r   stdinwriteflushr   r)   r   r[   r\   r.   r-   )r2   prR   r]   s       r   test_stdin_loaderzCmdLineTest.test_stdin_loader   ss     N	!GGMM01GGMMOa.C	++;;<CCGLh$ a.Cs   5B Bc              #     K   |r(t        dt        j                        }|j                  }n't        dt        j                        }|j
                  }	 	 |j                  d      }|dk(  rn|j                          (| t        |       |j                          y # t        |       |j                          w xY ww)Nz-i)stderr   s   >>> )
r   
subprocessPIPErf   STDOUTstdoutreadreadliner   close)r2   separate_stderrrc   rf   r5   s        r   interactive_pythonzCmdLineTest.interactive_python   s     T*//:AXXFT**;*;<AXXF
	{{1~7?!	 
 GNLLN NLLNs   AB>-B B>B;;B>c                 *   | j                  |      5 }|j                  j                  d       |j                  j                          | j	                  d|j
                  j                         j                                d d d        y # 1 sw Y   y xY w)Ns   print('foo')
s   foo)rp   r`   ra   rb   r*   rk   rm   strip)r2   ro   rc   s      r   check_repl_stdout_flushz#CmdLineTest.check_repl_stdout_flush   so    $$_5 	BGGMM+,GGMMOVQXX%6%6%8%>%>%@A	B 	B 	Bs   A.B		Bc                    | j                  |      5 }|j                  j                  d       |j                  j                          |r|j                  n|j
                  }| j                  d|j                                | j                  d|j                                | j                  d|j                                d d d        y # 1 sw Y   y xY w)Ns   1/0
s
   Traceback s   File "<stdin>"s   ZeroDivisionError)rp   r`   ra   rb   rf   rk   r-   rm   )r2   ro   rc   rf   s       r   check_repl_stderr_flushz#CmdLineTest.check_repl_stderr_flush   s    $$_5 	CGGMM(#GGMMO!0QXXahhFMM-):;MM+V__->?MM.0AB	C 	C 	Cs   B0CCc                 $    | j                          y r   rs   r2   s    r   test_repl_stdout_flushz"CmdLineTest.test_repl_stdout_flush       $$&r   c                 &    | j                  d       y NTrw   rx   s    r   &test_repl_stdout_flush_separate_stderrz2CmdLineTest.test_repl_stdout_flush_separate_stderr       $$T*r   c                 $    | j                          y r   ru   rx   s    r   test_repl_stderr_flushz"CmdLineTest.test_repl_stderr_flush   rz   r   c                 &    | j                  d       y r|   r   rx   s    r   &test_repl_stderr_flush_separate_stderrz2CmdLineTest.test_repl_stderr_flush_separate_stderr   r~   r   c           
          t        j                         5 }t        |d      }| j                  ||||d t        j
                  j                  |       d d d        y # 1 sw Y   y xY w)Nscript)r;   r   temp_dirr   rT   r   r[   SourceFileLoaderr2   r   r3   s      r   test_basic_scriptzCmdLineTest.test_basic_script   sa    ! 	8Z+JAK{K)4(22CC,6  8	8 	8 	8   =AA$c           	      f   t        j                         5 }| j                  t        j                  j                  |      |       t        |d      }t        j                  j                  |      }| j                  ||||d t        j                  j                         d d d        y # 1 sw Y   y xY w)Nr   )r   temp_cwd
assertTruer+   pathisabsr   basenamerT   r   r[   r   )r2   r   r3   relative_names       r   test_script_abspathzCmdLineTest.test_script_abspath   s     ! 	EZOOBGGMM*5zB+JAKGG,,[9M}k=)4(22CCE	E 	E 	Es   B	B''B0c           	      L   t        j                         5 }t        |d      }t        j                  |d       t        j                  |       t        j                  |      }| j                  ||||d t        j                  j                         d d d        y # 1 sw Y   y xY w)Nr   Tdoraiser   r   r   
py_compilecompiler+   remover   make_legacy_pycrT   r   r[   SourcelessFileLoaderr2   r   r3   pyc_files       r   test_script_compiledz CmdLineTest.test_script_compiled   s    ! 	IZ+JAK{D9IIk"$44[AHx'T(22GGI	I 	I 	I   A<BB#c           	          t        j                         5 }t        |d      }| j                  ||||dt        j
                  j                         d d d        y # 1 sw Y   y xY w)N__main__ r   r   s      r   test_directoryzCmdLineTest.test_directory   s^    ! 	EZ+J
CKz;
)2(22CCE	E 	E 	E   ;AA"c           	      L   t        j                         5 }t        |d      }t        j                  |d       t        j                  |       t        j                  |      }| j                  ||||dt        j                  j                         d d d        y # 1 sw Y   y xY w)Nr   Tr   r   r   r   s       r   test_directory_compiledz#CmdLineTest.test_directory_compiled  s    ! 	IZ+J
CK{D9IIk"$44[AHz8Z)2(22GGI	I 	I 	Ir   c                     t        j                         5 }d|z  }| j                  ||       d d d        y # 1 sw Y   y xY w)N"can't find '__main__' module in %r)r   r   rX   )r2   r   msgs      r   test_directory_errorz CmdLineTest.test_directory_error  s?    ! 	6Z6CC$$Z5	6 	6 	6s   6?c           	          t        j                         5 }t        |d      }t        |d|      \  }}| j	                  ||||dt
        j                         d d d        y # 1 sw Y   y xY w)Nr   test_zipr   )r   r   r   r	   rT   	zipimportzipimporter)r2   r   r3   zip_namerun_names        r   test_zipfilezCmdLineTest.test_zipfile  se    ! 	6Z+J
CK!0Z!UHhx8Xr(446	6 	6 	6s   AAA(c           	      6   t        j                         5 }t        |d      }t        j                  |dt        j
                  j                        }t        |d|      \  }}| j                  ||||dt        j                         d d d        y # 1 sw Y   y xY wNr   T)r   invalidation_moder   r   )r   r   r   r   r   PycInvalidationMode	TIMESTAMPr	   rT   r   r   r2   r   r3   compiled_namer   r   s         r   test_zipfile_compiled_timestampz+CmdLineTest.test_zipfile_compiled_timestamp  s    ! 	6Z+J
CK&..T","@"@"J"JLM "1Z!WHhx8Xr(446	6 	6 	6   A1BBc           	      6   t        j                         5 }t        |d      }t        j                  |dt        j
                  j                        }t        |d|      \  }}| j                  ||||dt        j                         d d d        y # 1 sw Y   y xY wr   )r   r   r   r   r   r   CHECKED_HASHr	   rT   r   r   r   s         r   "test_zipfile_compiled_checked_hashz.CmdLineTest.test_zipfile_compiled_checked_hash!  s    ! 	6Z+J
CK&..T","@"@"M"MOM "1Z!WHhx8Xr(446	6 	6 	6r   c           	      6   t        j                         5 }t        |d      }t        j                  |dt        j
                  j                        }t        |d|      \  }}| j                  ||||dt        j                         d d d        y # 1 sw Y   y xY wr   )r   r   r   r   r   r   UNCHECKED_HASHr	   rT   r   r   r   s         r   $test_zipfile_compiled_unchecked_hashz0CmdLineTest.test_zipfile_compiled_unchecked_hash+  s    ! 	6Z+J
CK&..T","@"@"O"OQM "1Z!WHhx8Xr(446	6 	6 	6r   c                     t        j                         5 }t        |d      }t        |d|      \  }}d|z  }| j	                  ||       d d d        y # 1 sw Y   y xY w)Nnot_mainr   r   )r   r   r   r	   rX   )r2   r   r3   r   r   r   s         r   test_zipfile_errorzCmdLineTest.test_zipfile_error5  s^    ! 	4Z+J
CK!0Z!UHh6AC$$Xs3		4 	4 	4s   4AAc           
      (   t        j                         5 }t        j                  j	                  |d      }t        |       t        |d      }| j                  ddg|||dt        j                  j                  |       d d d        y # 1 sw Y   y xY w)Ntest_pkgr   -mtest_pkg.scriptrC   r   r   r+   r   joinr   r   rT   r   r[   r   r2   r   pkg_dirr3   s       r   test_module_in_packagez"CmdLineTest.test_module_in_package<  s    ! 	/Zggll:z:GW+GX>K&78+{):(22CC#-  /		/ 	/ 	/   A*BBc                     t        j                         5 }t        |ddd      \  }}| j                  ddg|||dt        j
                  ||       d d d        y # 1 sw Y   y xY w)Nr   r   r   r   r   
PYTHONPATHrD   r   r   r"   rT   r   r   r2   r   r   r   s       r   !test_module_in_package_in_zipfilez-CmdLineTest.test_module_in_package_in_zipfileF  sq    ! 	DZ!3J
JX`!aHh&78(H):y7L7L*2
  D	D 	D 	Dr   c                     t        j                         5 }t        |dddd      \  }}| j                  ddg|||dt        j
                  ||	       d d d        y # 1 sw Y   y xY w)
Nr   r   r      )r!   r   ztest_pkg.test_pkg.scriptztest_pkg.test_pkgr   r   r   s       r   $test_module_in_subpackage_in_zipfilez0CmdLineTest.test_module_in_subpackage_in_zipfileM  sv    ! 	DZ!3J
JX`hi!jHh&@A8X)+>(44*2
  D	D 	D 	Dr   c           
      (   t        j                         5 }t        j                  j	                  |d      }t        |       t        |d      }| j                  ddg|||dt        j                  j                  |       d d d        y # 1 sw Y   y xY w)Nr   r   r   rC   r   r   s       r   test_packagezCmdLineTest.test_packageU  s    ! 	/Zggll:z:GW+GZ@Kj1;*J
(22CC#-  /		/ 	/ 	/r   c           
         t        j                         5 }t        j                  j	                  |d      }t        |       t        |d      }t        j                  |d      }t        j                  |       t        j                  |      }| j                  ddg|||dt        j                  j                  |       d d d        y # 1 sw Y   y xY w)Nr   r   Tr   r   rC   )r   r   r+   r   r   r   r   r   r   r   r   r   rT   r   r[   r   )r2   r   r   r3   r   r   s         r   test_package_compiledz!CmdLineTest.test_package_compiled_  s    ! 
	/Zggll:z:GW+GZ@K&..{DIMIIk"$44[AHj18'Z(22GG#-  /
	/ 
	/ 
	/s   B+C		Cc                     t        j                         5 }t        j                  j	                  |d      }t        |       d}| j                  ddg||       d d d        y # 1 sw Y   y xY w)Nr   z7'test_pkg' is a package and cannot be directly executedr   rC   r   r   r+   r   r   r   rX   )r2   r   r   r   s       r   test_package_errorzCmdLineTest.test_package_errorl  sf    ! 	NZggll:z:GW*C$$dJ%7*$M	N 	N 	Ns   AA""A+c                 2   t        j                         5 }t        j                  j	                  |d      }t        |       t        j                  j	                  |d      }t        |       d}| j                  ddg||       d d d        y # 1 sw Y   y xY w)Nr   r   z^Cannot use package as __main__ module; 'test_pkg' is a package and cannot be directly executedr   rC   r   )r2   r   r   main_dirr   s        r   test_package_recursionz"CmdLineTest.test_package_recursiont  s    ! 	NZggll:z:GWww||GZ8HX*C $$dJ%7*$M	N 	N 	Ns   A/BBc                 2   t        j                         5 }t        j                  |      5  t        j                  j                  |d      }t        |d       t        |d      }t        ddgt        ddi\  }}}t        d	kD  rt        t        |             d
dz  }| j                  |j                  d      |       | j                  ||||||dt         j"                  j$                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   z1import sys; print('init_argv0==%r' % sys.argv[0])r   r   r   rG   Fr   zinit_argv0==%rr&   )r   r   
change_cwdr+   r   r   r   r   r
   rL   r'   r(   r)   r-   r.   rB   r   r[   r   )r2   r   r   r3   rQ   rR   rS   r]   s           r   test_issue8202zCmdLineTest.test_issue8202  s    ! 	IZ%%:6 I'',,z:>"UV/B/6Gi,ichiCQ;$s)$+d2hoog6<"";C#.Z#,#6#6#G#GII	I 	II I	I 	Is#   DCD0DD
	DDc                    t        j                         5 }t        j                  |      5  t        ddd      5 }|j	                  d       t        ddd	      \  }}}t        d
kD  rt        t        |             ddz  }| j                  |j                  d      |       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   rZ   wr&   encodingr5   z2import sys; print("sys.path[0]==%r" % sys.path[0])F)rG   r   zsys.path[0]==%rr   )r   r   r   openra   r
   r'   r(   r)   r-   r.   )r2   r   frQ   rR   rS   r]   s          r   "test_issue8202_dash_c_file_ignoredz.CmdLineTest.test_issue8202_dash_c_file_ignored  s     ! 
	AZ%%:6 	A$g6 A!GGFO#3DL#($*LBS {d3i(025HMM(//'":C@A	A
	A 
	AA A	A 	A
	A 
	As:   CCA'B;"C*C;C CC	CCc                    t        j                         5 }t        |d      }t        j                  |      5  t	        ddd      5 }|j                  d       t        ddgt        dd	i\  }}}| j                  ||||||d
t        j                  j                         d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Notherr   r   r   r&   r   r5   rG   Fr   )r   r   r   r   r   ra   r
   rL   rB   r   r[   r   )r2   r   r3   r   rQ   rR   rS   s          r   "test_issue8202_dash_m_file_ignoredz.CmdLineTest.test_issue8202_dash_m_file_ignored  s     ! 		LZ+J@K%%:6 L$g6 L!GGFO#3D' $FL $F?D$FLBS&&{B&1;
B&/&9&9&J&JL	LL		L 		LL LL L		L 		Ls;   #CCAB:!C)C:C?CC	CCc                 B   t        j                         5 }t        j                  j	                  |d      }t        |ddd      5 }|j                  d       |j                  d       t        d      D ]  }|j                  d	        |j                  d       d d d        t        j                  |
      5  t        |      \  }}}d d d        | j                  d       | j                  d       d d d        y # 1 sw Y   dxY w# 1 sw Y   BxY w# 1 sw Y   y xY w)Nzissue20884.pyr   latin1
)r   newlinez#coding: iso-8859-1
z"""
   zQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r   r   )r   r   r+   r   r   r   ra   ranger   r
   r*   )r2   r   r3   r   _rQ   rR   rS   s           r   test_issue20884zCmdLineTest.test_issue20884  s     ! 	'Z'',,z?CKk34H !A/0 r +AGGM*+ ! %%:6 =/<C=S#&S#&	' 	'! != =	' 	's<   0DAC=D8D	,D=D	D	D	DDc              '     K   t        j                         5 }t        j                  |      5  t        j                  j                  |d      }t        |g|  | d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY ww)Nr   r   )r   r   r   r+   r   r   r   )r2   argsr   r   s       r   setup_test_pkgzCmdLineTest.setup_test_pkg  sq     ! 	Z$$*5	ggll:z:GW$t$M		 	 	 	 	 	s3   BA<1A0A<'	B0A9	5A<<BBc                     t        dg|ddi\  }}}t        dkD  rt        t        |             | j	                  |d       |S )Nr   rG   Fr   )r   r'   r(   r)   r*   )r2   r   rQ   rR   rS   s        r   check_dash_m_failurez CmdLineTest.check_dash_m_failure  sD    ,TKDKUKCQ;$s)Q
r   c                     | j                         5 }t        |dd      } | j                  dgt         }| j	                  d|       d d d        y # 1 sw Y   y xY w)Nr   z+if __name__ == '__main__': raise ValueErrorztest_pkg.others
   ValueError)r   r   r   rL   r-   )r2   r   r3   rS   s       r   test_dash_m_error_code_is_onez)CmdLineTest.test_dash_m_error_code_is_one  s_       " 	.g+GW,Y[K+$++,<L|LCMM--		. 	. 	.s   7AAc                     d}|D ]e  \  }}| j                  |      5  t        d|      \  }}}| j                  |d       | j                  ||       | j	                  d|       d d d        g y # 1 sw Y   rxY w)N))builtinss   No code object available)z
builtins.xs=   Error while finding module specification.*ModuleNotFoundError)zbuiltins.x.ys]   Error while finding module specification.*ModuleNotFoundError.*No module named.*not a package)r   s=   No module named.*is a package and cannot be directly executed)zimportlib.nonexistents   No module named)z	.unittests#   Relative module names not supportedr   r   	   Traceback)subTestr   r*   assertRegexassertNotIn)r2   testsnameregexrQ   r   rS   s          r   test_dash_m_errorszCmdLineTest.test_dash_m_errors  s    

 ! 	4KD%d# 424>
As  Q'  e,  s3	4 4	44 4s   AA..A7	c                    t        j                         5 }t        j                  |      5  t        j                  d       t        dd      5  	 d d d        | j                  d      }| j                  |d       | j                  d|       | j                  d|       d d d        d d d        y # 1 sw Y   axY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   ztest_pkg/__init__.pycwbsG   Error while finding module specification.*ImportError.*bad magic numbers   is a packager  )	r   r   r   r+   mkdirr   r   r  r  r2   r   rS   s      r   test_dash_m_bad_pyczCmdLineTest.test_dash_m_bad_pyc  s    ! 	0Z$$*5	0HHZ -t4 ++J7CS23 _c2\3/	0 	0 	0 		0 	0 	0 	0s;   C"B<B0AB<C0B95B<<C	CCc                 6   t        j                         5 }t        j                  |      5  t        dd      5  	 d d d        | j	                  d      }| j                  d|       d d d        d d d        y # 1 sw Y   =xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   z
asyncio.pyr
  s>   Try using 'asyncio' instead of 'asyncio.py' as the module name)r   r   r   r   r   r-   r  s      r   *test_hint_when_triying_to_import_a_py_filez6CmdLineTest.test_hint_when_triying_to_import_a_py_file  s    ! 	FZ$$*5	F lD) ++L9CMM @ADF	F 	F 	F 	F 	F 	F 	Fs8   BBA7+B&B7B <BB	BBc                    t         t        t        t        f}|D ]  }|j                  }dj                  |      }| j                  |      5  | j                  |      5 }| j                  d      }| j                  |j                  d      |       | j                  d|       | j                  d|       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nz%raise {0}('Exception in __init__.py')r   asciis   Exception in __init__.pyr  )ImportErrorAttributeError	TypeError
ValueError__name__formatr  r   r   r-   r.   )r2   
exceptions	exceptioninitr   rS   s         r   test_dash_m_init_tracebackz&CmdLineTest.test_dash_m_init_traceback  s     ">9jI
# 	1I!**I:AA)LDi( 1''-118//
;i..w7=93?lC01 1 1	11 1 1 1s%   
CAC3CCCC	c                     | j                         5 }d}t        |d|       | j                  d      }| j                  d|       | j                  d|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nz1raise ImportError('Exception in __main__ module')r   r   s   ImportErrors   Exception in __main__ moduler  )r   r   r   r-   )r2   r   mainrS   s       r   test_dash_m_main_tracebackz&CmdLineTest.test_dash_m_main_traceback  sq      " 	-gFDgz48++J7CMM.#.MM93?MM,,	- 	- 	-s   AA11A:c                     t        j                  d      }t        j                         5 }t	        |d|      }t        |      \  }}}|j                  d      j                  d      }| j                  t        |      d       | j                  |d   j                  d             | j                  |d   j                  d	             | j                  |d
   j                  d             d d d        y # 1 sw Y   y xY w)Nz|            try:
                raise ValueError
            except:
                raise NameError from None
            r   r  r      r   	Tracebackr   z  File    	NameError)textwrapdedentr   r   r   r   decodesplitr*   lenr   
startswithr2   r   r   r3   exitcoderk   rf   texts           r   test_pep_409_verbiagez!CmdLineTest.test_pep_409_verbiage  s      "  ! 	=Z+J&IK'<['I$Hff==)//5DSY*OODG..{;<OODG..y9:OODG..{;<	= 	= 	=s   CC44C=c                 6   t         j                  r6t        j                  dvr$t	        j
                  t         j                        }n2t         j                  rt         j                  }n| j                  d       d}t        t	        j                         |      }| j                  t         j                  |       t        |      \  }}}| j                  t        |      |j                         j!                  d      d|d|       | j                  d|       y )N)win32darwin
emscriptenwasizneed os_helper.TESTFN_NONASCIIzprint(ascii(__file__))
r  zstdout=z stderr=r   )r   TESTFN_UNDECODABLEr/   platformr+   fsdecodeTESTFN_NONASCIIskipTestr   r,   
addCleanupunlinkr
   r*   r  rstripr&  )r2   r  r   r3   rQ   rk   rf   s          r   test_non_asciizCmdLineTest.test_non_ascii-  s    
 ((LL II;;y;;<D&&,,DMM:; ,'		T6B	((+6-k:FF+MMO""7+%+V4	6 	Br   c                    t        j                  d      }t        j                         5 }t	        |d|      }t        |      \  }}}|j                  d      }| j                  |j                         d       d d d        y # 1 sw Y   y xY w)Nz            import sys
            error = None
            try:
                raise ValueError('some text')
            except ValueError as err:
                error = err

            if error:
                sys.exit(error)
            r   r  z	some text)	r$  r%  r   r   r   r   r&  r*   r:  r*  s           r   )test_issue20500_exit_with_exception_valuez5CmdLineTest.test_issue20500_exit_with_exception_valueE  s}     
" 
 ! 	9Z+J&IK'<['I$Hff==)DT[[]K8		9 	9 	9s   ABB
c                 $   d}t        j                         5 }t        |d|      }t        |      \  }}}t	        j
                  t	        j                  |      d      j                         }| j                  d|       d d d        y # 1 sw Y   y xY w)Nz
1 + 1 = 2
r   r  z
    ^^^^^
)	r   r   r   r   ioTextIOWrapperBytesIOrl   r-   r*  s           r   *test_syntaxerror_unindented_caret_positionz6CmdLineTest.test_syntaxerror_unindented_caret_positionW  s{    ! 	1Z+J&IK'<['I$Hff##BJJv$6@EEGDMM/40	1 	1 	1s   A&BBc                 <   t        j                  d      }t        j                         5 }t	        |d|      }t        |      \  }}}t        j                  t        j                  |      d      j                         }| j                  d|       d}t	        |d|      }t        |      \  }}}t        j                  t        j                  |      d      j                         }| j                  d|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nz;            if True:
                1 + 1 = 2
            r   r  z
    1 + 1 = 2
    ^^^^^
zif True:
    1 + 1 = 2
)r$  r%  r   r   r   r   r?  r@  rA  rl   r-   r  r*  s           r   (test_syntaxerror_indented_caret_positionz4CmdLineTest.test_syntaxerror_indented_caret_position`  s     "  ! 	@Z+J&IK'<['I$Hff##BJJv$6@EEGDMM8$?$  ,J&IK'<['I$Hff##BJJv$6@EEGDT4(MM8$?!	@ 	@ 	@s   CDDc                     d}t        j                         5 }t        |d|      }t        |      \  }}}| j	                  |j                         dd  g d       d d d        y # 1 sw Y   y xY w)Nzfoo = f"""{}
foo"""
r   )s       foo = f"""{}s                  ^s;   SyntaxError: f-string: valid expression required before '}'r   r   r   r   r*   
splitlinesr2   r   r   r3   r+  rk   rf   s          r   #test_syntaxerror_multi_line_fstringz/CmdLineTest.test_syntaxerror_multi_line_fstringw  so    )! 
	Z+J&IK'<['I$Hff!!#BC(
	 
	 
	   AA""A+c                     d}t        j                         5 }t        |d|      }t        d|      \  }}}| j	                  |j                         dd  g d       d d d        y # 1 sw Y   y xY w)Nzfoo = """\q"""
r   z-WerrorrG  )s       foo = """\q"""s             ^^^^^^^^s)   SyntaxError: invalid escape sequence '\q'rH  rJ  s          r   3test_syntaxerror_invalid_escape_sequence_multi_linez?CmdLineTest.test_syntaxerror_invalid_escape_sequence_multi_line  sv    $! 	Z+J&IK'<;($Hff !!#BC(	 	 	s   AA##A,c                     d}t        j                         5 }t        |d|      }t        |      \  }}}| j	                  |j                         dd  ddg       d d d        y # 1 sw Y   y xY w)Nz?x = ' ' nothing to see here
';import os;os.system('echo pwnd')
r   s	       x = '2   SyntaxError: source code cannot contain null bytesrH  rJ  s          r   test_syntaxerror_null_bytesz'CmdLineTest.test_syntaxerror_null_bytes  su    U! 	Z+J&IK'<['I$Hff!!#BC( I	 	 	rL  c                     ddg}t        j                         5 }|D ]C  }t        |d|      }t        |      \  }}}| j	                  |j                         dd  ddg       E 	 d d d        y # 1 sw Y   y xY w)Nz
'''
multilinestring 
'''z
f'''
multilinestring 
'''r   rP  s       multilinestringrQ  rH  )r2   scriptsr   r   r3   r   rf   s          r   /test_syntaxerror_null_bytes_in_multiline_stringz;CmdLineTest.test_syntaxerror_null_bytes_in_multiline_string  s    24TU! 		Z! /
HfM4[A1f  %%',.M		 		 		s   A	A,,A5c                    t        j                  d      }d | _        t        j                         5 }t        j                         5 }t        |d|      }t        d||      }t        |      j                         j                         }| j                  |d   |       | j                  ||       t        d||      }t        |      j                         j                         }| j                  ||       t        d||      }t        |      j                         j                         }| j                  |||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc            import sys
            for entry in sys.path:
                print(entry)
            r   z-EsrC   r   z-I)r$  r%  maxDiffr   r   r   r   r   r&  rI  r*   r  )	r2   r   work_dirr   r3   rc   out_by_name
out_by_dirout_by_dir_isolateds	            r   -test_consistent_sys_path_for_direct_executionz9CmdLineTest.test_consistent_sys_path_for_direct_execution  s@     "  ! 	KXy/A/A/C 	Kz+J
FKK UKX>A%a.//1<<>K[^Z8X{3UJH=A$Q..0;;=JZ5T:8<A"-a."7"7"9"D"D"F0*kJ	K 	K 	K 	K 	K 	Ks$   EC9E?EE	EE%c                    t        j                  d      }d | _        t        j                         5 }t
        j                  j                  |d      }t        j                  |       t        |d|      }t        dd|      }t        |      j                         j                         }| j                  |d   |       | j                  ||       t        dd|      }t        |      j                         j                         }| j                  ||       t!        dd|      \  }}	}
|
j                         j                         }| j#                  d	|d
          d d d        y # 1 sw Y   y xY w)NrW  
script_pkgr   z-smzscript_pkg.__main__rC   r   z-ImzNo module named script_pkg)r$  r%  rX  r   r   r+   r   r   r  r   r   r   r&  rI  r*   r  r   r-   )r2   r   rY  r   r3   rc   out_by_moduleout_by_packager+  rk   rf   traceback_liness               r   -test_consistent_sys_path_for_module_executionz9CmdLineTest.test_consistent_sys_path_for_module_execution  sA     "  ! 	MXh=JHHZ +J
FKK U$9xHA'N113>>@M]1-x8Z7ULh?A(^224??AN^];'<|($Hff %mmo88:OMM68KL)	M 	M 	Ms   D+E%%E.c                 <   d}| j                  t        j                  j                  |             t	        |dt
        j                  t
        j                        }|j                         \  }}| j                  d|       | j                  |j                  d       y )Nznonexistingscript.pyT)r,  rk   rf   z: can't open file r   )assertFalser+   r   existsr   rh   ri   communicater-   assertNotEqual
returncode)r2   r   procrR   rS   s        r   test_nonexisting_scriptz#CmdLineTest.test_nonexisting_script  sw    
 (/0F#-??#-??4 ##%S*C0DOOQ/r   z	/dev/fd/0zrequires /dev/fd platformfreebsdz/devz/dev/fdz.Requires fdescfs mounted on /dev/fd on FreeBSDc                 b   d}t        j                         5 }t        |d|      }t        |d      5 }t	        d|j                          dddd|j                         f	      }|j                         \  }}| j                  |d
       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nz print("12345678912345678912345")z	script.pyrz/dev/fd/Tr   r   r   )	close_fdspass_fdss   12345678912345678912345
)r   r   r   r   r   filenorh  r*   )r2   r   rY  r3   fprc   rR   rS   s           r   test_script_as_dev_fdz!CmdLineTest.test_script_as_dev_fd   s     4! 	DX+Hk6JKk3' D2 8BIIK=!9TUVWXYZ[][d[d[fTgh==?S  &BCD	D 	DD D	D 	Ds#   B%ABB%B"	B%%B.r   )F)Gr  
__module____qualname__rB   rT   rX   r^   rd   
contextlibcontextmanagerrp   rs   ru   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r-  r;  r=  rB  rE  rK  rN  rR  rU  r]  rd  rl  unittest
skipUnlessr+   r   rg  skipIfr/   r4  r)  statst_devrt   r   r   r$   r$   \   s    <@9D 59C  599 %
%  &BC'+'+8
EIEI6
66664/DD//N	NI"AL'"  .4(0F1-=$ 09$1@.
K>#MJ0 X46QRX__S\\,,Y7 IRWWV_++wrwwy/A/H/HHEG
DG S
Dr   r$   c                  ,    t        j                          y r   )r   reap_childrenr~  r   r   tearDownModuler    s    r   r   )$rw  r   importlib.machineryr   ry  r/   r+   os.pathr   rh   r?  r$  testr   test.supportr   r   test.support.script_helperr   r   r   r	   r
   r   r   r   r'   rL   test_sourcer   r"   TestCaser$   r  r  r  r~  r   r   <module>r     s         
 	    	   & "H H H //*3j ;F  *r
D(## r
Dl zHMMO r   