
    daf                        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mZmZmZmZ ej                   s ej"                  d      d Z G d dej&                        Z ej*                   e       d	       G d
 dej&                               Z G d dej&                        Zd Zedk(  r ej4                          yy)    N)support)	os_helper)spawn_pythonkill_pythonassert_python_okassert_python_failure interpreter_requires_environmentztest module requires subprocessc                 @    t        |       }| j                         }||fS N)r   wait)pdata
returncodes      -/root/Python-3.12.4/Lib/test/test_cmd_line.py_kill_python_and_exit_coder      s!    q>DJ    c                   t   e Zd Zd Zd Zej                  d        Zej                  d        Zej                  d        Z	ej                  d        Z
d Zd Zej                  d	        Zd
 Z ej                    e       d      d        Zd Zej                  d        Zd Zd Zd Zd Z ej2                  ej6                  d      d        Z ej2                  ej6                  d      d        Z ej                   ej>                  dk(  d      d        Z  ej                   ej>                  dk(  d      d        Z! ej2                  ej>                  dk(  xs ejD                  d      d        Z#d Z$d Z%d Z&d  Z' ej                   ejP                  jR                  d!      d"        Z*d# Z+d$ Z,d% Z-d& Z.d' Z/d( Z0d) Z1d* Z2 ej                   e3jh                  d+k7  d,       ej                   ej>                  d-k(  d.      d/               Z5d0 Z6d1 Z7d2 Z8d3 Z9d4 Z:d5 Z;ej                  d6        Z< ej                    e       d7      d8        Z=d9 Z>d: Z?d;d;d<d=Z@ej                  d>        ZAdId?ZBd@ ZCdA ZDdB ZEdC ZF ej2                  ej>                  dk(  dD      dE        ZGej                  dF        ZHdG ZIyH)JCmdLineTestc                 0    t        d       t        d       y )N.z< .)r   selfs    r   test_directorieszCmdLineTest.test_directories   s    c"e$r   c                     t        |      \  }}}| j                  |dk(  xs |j                  d             | j                  d|       | j                  d|       |S )Nr      
s	   Traceback)r   
assertTrueendswithassertNotIn)r   cmd_linercouterrs        r   verify_valid_flagzCmdLineTest.verify_valid_flag"   sU    '1Cs
9cll5&9:s+s+
r   c                 2   | j                  d       | j                  d       | j                  d      }|j                         }| j                  d|d          | j                  d|       | j                  d|       | j	                  t        |      d       y )	Nz-hz-?z--help   usager   
   PYTHONHOME   -X dev2   )r#   
splitlinesassertInr   
assertLesslenr   r!   liness      r   	test_helpzCmdLineTest.test_help)   s~    t$t$$$X. ha),C(E
B'r   c                 J    | j                  d      }| j                  d|       y )Nz
--help-envr&   r#   r*   r   r!   s     r   test_help_envzCmdLineTest.test_help_env4   s     $$\2mS)r   c                 J    | j                  d      }| j                  d|       y )Nz--help-xoptionsr'   r1   r2   s     r   test_help_xoptionszCmdLineTest.test_help_xoptions9   s!    $$%67i%r   c                     | j                  d      }|j                         }| j                  d|d          | j                  d|       | j                  d|       dj                  |dd        j	                  d       y )	Nz
--help-allr%   r   r&   r'   r      ascii)r#   r)   r*   joindecoder-   s      r   test_help_allzCmdLineTest.test_help_all>   sk    $$\2 ha)mS)i% 	qr""7+r   c                 H    | j                  d       | j                  d       y )Nz-Oz-OOr#   r   s    r   test_optimizezCmdLineTest.test_optimizeJ   s    t$u%r   c                 &    | j                  d       y )N-Sr=   r   s    r   test_site_flagzCmdLineTest.test_site_flagN   s    t$r   c                     dt         j                  d d z  j                  d      }dD ]Q  }t        |      \  }}}| j	                  |j                  |             | j                  |j                  |             S y )NzPython %d.%d   r8   )z-Vz	--versionz-VV)sysversion_infoencoder   assertFalse
startswithr   )r   versionswitchr    r!   r"   s         r   test_versionzCmdLineTest.test_versionQ   so    !C$4$4Ra$88@@I. 	5F+F3LBSS^^G45OOCNN734	5r   c                     t        d      \  }}}| j                  d|       t        d      \  }}}| j                  d|       y )Nz-vs   stack overflowz-vv)r   r   r   r    r!   r"   s       r   test_verbosezCmdLineTest.test_verboseY   sF     (-C*C0'.C*C0r   z6Cannot run -E tests when PYTHON env vars are required.c                 x    d } |       }| j                  |i         |dd      }| j                  |ddd       y )Nc                      t         j                  df| z   } | dz  } t        j                  |       }t	        |j                         d         }|S )N-E)-c import sys; print(sys._xoptions)r   )rD   
executable
subprocesscheck_outputevalr)   )argsr!   optss      r   get_xoptionsz/CmdLineTest.test_xoptions.<locals>.get_xoptionse   sM     NND)D0D>>D))$/C(+,DKr   z-Xaz	-Xb=c,d=eTzc,d=e)ab)assertEqual)r   rZ   rY   s      r   test_xoptionszCmdLineTest.test_xoptionsb   sA    	 ~r"E;/T89r   c                 \     fd}d} |d|      \  }}} j                  |j                         d        j                  |d        |dddd|      \  }}} j                  |j                         d	       t        j                  r j	                  |d
       y  j                  |d       y )Nc                  l   t         j                  g}|j                  |        t        j                  }t        j
                  |||      }|j                         \  }}|j                  j                          |j                  j                          |j                  }j                  |d       |||fS )Nstdoutstderrr   )rD   rT   extendrU   PIPEPopencommunicaterb   closerc   r   r]   )rX   cmdre   r   r!   r"   r    r   s          r   
run_pythonz1CmdLineTest.test_showrefcount.<locals>.run_pythonu   s     >>"CJJt??D  T$?A}}HCHHNNHHNNBR#sC<r   rS   rR   s   {}r   -I-Xshowrefcounts   {'showrefcount': True}s   ^\[-?\d+ refs, \d+ blocks\])r]   rstripr   Py_DEBUGassertRegex)r   rj   coder    r!   r"   s   `     r   test_showrefcountzCmdLineTest.test_showrefcountt   s    	  2!$-Cu-c"!$ndDIC'@A S"ABS#&r   c                     h d}|D ][  \  }}dd| ddg}| j                  |      5  t        | }| j                  |j                  j	                  d      |       d d d        ] y # 1 sw Y   hxY w)N>   z=onFrozenImporterz=offSourceFileLoader ru   =ru   rl   frozen_modulesrR   z,import os; print(os.__spec__.loader, end="")utf-8)subTestr   rp   r!   r:   )r   testsrawexpectedri   ress         r   test_xoption_frozen_modulesz'CmdLineTest.test_xoption_frozen_modules   s    
 # 	DMC>#/GICc" D&,  !8(CD D	DD Ds   4A&&A/	c                 h    t        d       t        dd       t        ddd       t        dddd       y )N-mfnord43520xyzrunpytimeit-n1r   r   r   s    r   test_run_modulezCmdLineTest.test_run_module   s2     	d#dO4 	dG_=xs3r   c                 0   t        ddddd      }|j                  j                  d       |j                  j                  d       t        |      }| j	                  |j                  d      d	k7         | j	                  |j                  d
      d	k7         y )N-ir   r   r   r   s   Timer
   exit()
s   1 loops   __main__.Timer)r   stdinwriter   r   find)r   r   r   s      r   test_run_module_bug1764407z&CmdLineTest.test_run_module_bug1764407   st     tXtS9	j!	k"1~		),23		"34:;r   c                     t         j                  j                  t              j	                  d      }t        j                  |      5  t        ddd       t        ddd       d d d        y # 1 sw Y   y xY w)Ntestr   unittestztest/test_longexp.pyz./test/test_longexp.py)ospathdirname__file__removesuffixr   
change_cwdr   )r   projectlibpaths     r   test_relativedir_bug46421z%CmdLineTest.test_relativedir_bug46421   sb     2??G!!.1 	IT:/EFT:/GH	I 	I 	Is   A,,A5c                 J    t        d       t        dd       t        dd       y )NrR   zraise Exceptionpassr   r   s    r   test_run_codezCmdLineTest.test_run_code   s!     	d#d$56v&r   zneed os_helper.FS_NONASCIIc                 x    dt         j                  dt        t         j                        d}t        d|       y )Nzassert(ord(z) == )rR   )r   FS_NONASCIIordr   )r   commands     r   test_non_asciizCmdLineTest.test_non_ascii   s,      ++S1F1F-GIw'r   c                     t         j                  }d| d}t        d|      }| j                  |j                  j                         t        |      j                  d             y )Nz# coding: latin1
print(ascii('z'))rR   r8   )r   r   r   r]   r!   rn   r8   rF   )r   chri   r   s       r   test_codingzCmdLineTest.test_coding   sS     ""/t37tS))59+;+;G+DEr   win32z Windows has a native unicode APIc                    d}t         j                  j                         }d|d<   d|d<   d|z   dz   }t        j                  t
        j                  d|gt        j                  t        j                  |	      }|j                         \  }}|j                  d
k(  rd}n-|j                  dk(  rd}nt        d|j                  d|      |j                  |      st        |d|      y )N   CLC_ALL0PYTHONCOERCECLOCALEs   import locale; print(ascii("s   "), locale.getencoding())rR   )rb   rc   envr7   s3   Unable to decode the command from the command line:r   s   '\xff' zUnknown exit code: z	, output=z doesn't start with )r   environcopyrU   rf   rD   rT   re   STDOUTrg   r   AssertionErrorrH   )r   undecodabler   rq   r   rb   rc   patterns           r   test_undecodable_codez!CmdLineTest.test_undecodable_code   s     jjooH%(!"*+.)) 	 ^^T4(??:+<+< <<1
 MG\\Q "G !q||U[!\]]  ) vw!OPP *r   c           	      >  
 d

fd}
fd}
fd}dj                  d      }d}||g}|||fD ]`  }| j                  |      5  |D ]=  } ||      }	| j                  |	j                  j	                         t        |             ? 	 d d d        b y # 1 sw Y   mxY w)	Nz;import sys, os; s=os.fsencode(sys.argv[1]); print(ascii(s))c                 x    t         j                  d| g}t        j                  |t        j                  d      S )NrR   Trb   textrD   rT   rU   runre   argri   rq   s     r   run_defaultz6CmdLineTest.test_invalid_utf8_arg.<locals>.run_default  s,    >>4s3C>>#jooDIIr   c                     t         j                  d| g}t        t        j                        }d|d<   t        j                  |t
        j                  d|      S )NrR   r   r   T)rb   r   r   )rD   rT   dictr   r   rU   r   re   )r   ri   r   rq   s      r   run_c_localez7CmdLineTest.test_invalid_utf8_arg.<locals>.run_c_locale  sJ    >>4s3Crzz"CCM>>#joo'+6 6r   c                 |    t         j                  ddd| g}t        j                  |t        j                  d      S )Nrl   utf8rR   Tr   r   r   s     r   run_utf8_modez8CmdLineTest.test_invalid_utf8_arg.<locals>.run_utf8_mode  s0    >>4tSAC>>#jooDIIr      e:é, euro:€, non-bmp:􏿿r}   s   é)run_cmd)rF   r~   r]   rb   rn   r8   )r   r   r   r   
valid_utf8invalid_utf8	test_argsr   r   procrq   s             @r   test_invalid_utf8_argz!CmdLineTest.test_invalid_utf8_arg  s     M	J	6	J ?EEgN
( 	  .	#\=A 	GGg. G$ GC"3<D$$T[[%7%7%95:FGG G	GG Gs   ABB	darwinz%test specific to Mac OS X and Androidc                    dj                  d      }d}|j                  dd      }t        |      j                  d      dz   }t        j                  j                         }d|d<   t        j                  t        j                  d	||ft        j                  |
      }|j                         \  }}| j                  ||       | j                  |j                  d       y )Nr   r}   z%import sys; print(ascii(sys.argv[1]))surrogateescaper8   r   r   r   rR   )rb   r   r   )rF   r:   r8   r   r   r   rU   rf   rD   rT   re   rg   r]   r   )	r   r   rq   decodedr   r   r   rb   rc   s	            r   test_osx_android_utf8z!CmdLineTest.test_osx_android_utf8.  s     9??H6++g'89>((1E9jjoo H^^T4.?? *q)r   c                     t        j                  d      }t        j                  d|g}t	        j
                  |t        j                  t        j                  dd      }| j                  |j                  d       y )Nz
            import sys
            out = sys.stdout
            print(out.isatty(), out.write_through, out.line_buffering)
            err = sys.stderr
            print(err.isatty(), err.write_through, err.line_buffering)
        rR   T)rb   rc   r   checkz#False False False
False False True
)	textwrapdedentrD   rT   rU   r   re   r]   rb   )r   rq   rX   r   s       r   %test_non_interactive_output_bufferingz1CmdLineTest.test_non_interactive_output_bufferingD  sb        d+~~d:??%/__4tM.	/r   c                     dD ]l  }d|z  }t        dd|      \  }}}|dk(  r|n|}| j                  |dd|z         d|z  }t        dd|      \  }}}|dk(  r|n|}| j                  |dd	|z         n y )
Nra   z6import os, sys; sys.%s.buffer.write(b'x'); os._exit(0)-urR   rc      xzbinary %s not unbufferedz.import os, sys; sys.%s.write('x'); os._exit(0)ztext %s not unbufferedr   r]   )r   streamrq   r    r!   r"   r   s          r   test_unbuffered_outputz"CmdLineTest.test_unbuffered_outputS  s    * 	LFLD+D$=LBS H,3#DT4)Cf)LMDD+D$=LBS H,3#DT4)AF)JK	Lr   c                    d}t        dd|      }|j                  j                  d       |j                  j                          t	        |      \  }}| j                  |d       | j                  |j                  d      |       y )Nz/import sys; sys.stdout.write(sys.stdin.read(1))r   rR   r   r   )r   r   r   flushr   r]   r   rH   )r   rq   r   r   r    s        r   test_unbuffered_inputz!CmdLineTest.test_unbuffered_inputc  sg    AtT*	d	-a0bQ-t4r   c                     d}d}|t         j                  z   |z   }d}t        dd||      \  }}}| j                  |j	                  d      |       | j                  |j	                  d      |       y )N  ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE  FGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJif 1:
            import sys
            path = ":".join(sys.path)
            path = path.encode("ascii", "backslashreplace")
            sys.stdout.buffer.write(path)r@   rR   
PYTHONPATHr8   )r   pathsepr   r*   rF   )r   path1path2r   rq   r    r!   r"   s           r   test_large_PYTHONPATHz!CmdLineTest.test_large_PYTHONPATHm  so    rzz!E)-
 (dD379Cell7+S1ell7+S1r   z'PYTHONSAFEPATH changes default sys.pathc                 t    d}t        d|d      \  }}}t        d|d      \  }}}| j                  ||       y )Nr   rR   ry   r   F)
__isolatedr   )r   rq   rc1out1err1rc2out2err2s           r    test_empty_PYTHONPATH_issue16309z,CmdLineTest.test_empty_PYTHONPATH_issue16309|  sE    -
 +4"ET4*4%HT4 	t$r   c                    dD ]  }t         j                  j                         }||d<   t        j                  t
        j                  dgt        j                  t        j                  t        j                  |      }d}|j                  j                  t        |      j                  d      dz          |j                  j                  d       t        |      }t        |      j                  |d	      }| j                  ||        y )
N)r8   zlatin-1r}   PYTHONIOENCODINGr   )r   rb   rc   r   u   a=é b= c=𐀀 d=􏿿r8   r   r   backslashreplace)r   r   r   rU   rf   rD   rT   re   r   r   r   r8   rF   r   reprr*   )r   encodingr   r   r   r   escapeds          r   test_displayhook_unencodablez(CmdLineTest.test_displayhook_unencodable  s    5 	)H**//#C&.C"#  & oo!!((A ?DGGMM%+,,W5=>GGMM+&q>D4j''2DEGMM'4(	)r   c                    t        j                  d      5 }t        j                  j	                  d      }|j                  |j                  d             |j                          |j                  d       t        j                  t        j                  d|f|t        j                        5 }|j                         \  }}d d d        d d d        | j                  j!                         |       y # 1 sw Y   2xY w# 1 sw Y   6xY w)Nzwb+ASCII)s   abcs   defr   rR   )r   rb   )tempfileNamedTemporaryFiler   lineseprF   r   r9   r   seekrU   rf   rD   rT   re   rg   r]   rn   )r   rq   r   r   sepr   rb   rc   s           r   check_inputzCmdLineTest.check_input  s    ((/ 	45**##G,CKK!123KKMJJqM!!t,JOO5 48<!%!1!1!34	4 	(3	4 4	4 	4s$   BC?.C3C?3C<	8C??Dc                 (    | j                  dd       y )Nz-import sys; print(repr(sys.stdin.readline()))s   'abc\n'r  r   s    r   test_stdin_readlinezCmdLineTest.test_stdin_readline  s     	;	r   c                 (    | j                  dd       y )Nzprint(repr(input()))s   'abc'r  r   s    r   test_builtin_inputzCmdLineTest.test_builtin_input  s    "	r   c                     d}t        d|      \  }}}t        j                  dk(  r%| j                  d|       | j                  d|       y | j                  d|       | j                  d|       y )Nzif 1:
            import sys
            print(1)
            print(2)
            print(3, file=sys.stderr)
            print(4, file=sys.stderr)rR   r   s   1
2
s   3
4
s   1
2
s   3
4
)r   rD   platformr]   r   rq   r    r!   r"   s        r   test_output_newlinezCmdLineTest.test_output_newline  si    ) (d3C<<7"]C0]C0Y,Y,r   c                     t        dd      \  }}}| j                  |j                  dd      d       | j                  d|       y )NrR   'r8   ignoreSyntaxErrorr   )r   rp   r:   r]   rM   s       r   test_unmached_quotezCmdLineTest.test_unmached_quote  sA     -T37CGX6Fc"r   c                     d}t        d|      \  }}}| j                  d|       | j                  d|       | j                  |j                  dd      d       y )Nzif 1:
            import os, sys, test.support
            test.support.SuppressCrashReport().__enter__()
            sys.stdout.write('x')
            os.close(sys.stdout.fileno())rR   r   x   r8   r  z"Exception ignored in.*
OSError: .*)r   r]   rp   r:   r  s        r   test_stdout_flush_at_shutdownz)CmdLineTest.test_stdout_flush_at_shutdown  s\    -
 -T48Cc"b!GX6>	@r   c                 L    d}t        d|      \  }}}| j                  d|       y )Nzimport sys; sys.stdout.close()rR   r   r   r  s        r   test_closed_stdoutzCmdLineTest.test_closed_stdout  s+     0'd3Cc"r   posixztest needs POSIX semanticsvxworksz.test needs preexec support in subprocess.Popenc                 b   dj                        }fd}t        j                  t        j                  dd|gt        j
                  t        j
                  t        j
                  |      }|j                         \  }}| j                  |d       | j                  |j                  d       y )	Nzif 1:
            import os, sys
            for i, s in enumerate({streams}):
                if getattr(sys, s) is not None:
                    os._exit(i + 1)
            os._exit(42)streamsc                      d v rt        j                  d       d v rt        j                  d       d v rt        j                  d       y y )Nr   r   rb   r7   rc   rC   )r   rh   r  s   r   preexecz+CmdLineTest._test_no_stdio.<locals>.preexec  sA    '!7"7" #r   rQ   rR   )r   rb   rc   
preexec_fnr   *   )	formatrU   rf   rD   rT   re   rg   r]   r   )r   r  rq   r  r   r!   r"   s    `     r   _test_no_stdiozCmdLineTest._test_no_stdio  s    
 #F7F3 		 ^^T4.//????  ==?Sc"r*r   c                 (    | j                  dg       y )Nr   r#  r   s    r   test_no_stdinzCmdLineTest.test_no_stdin  s    WI&r   c                 (    | j                  dg       y )Nrb   r%  r   s    r   test_no_stdoutzCmdLineTest.test_no_stdout      XJ'r   c                 (    | j                  dg       y )Nrc   r%  r   s    r   test_no_stderrzCmdLineTest.test_no_stderr
  r)  r   c                 *    | j                  g d       y )N)r   rb   rc   r%  r   s    r   test_no_std_streamszCmdLineTest.test_no_std_streams  s    9:r   c                    | j                  d       g }t        j                  j                  dd      dk7  r"t	        t        j                        }|d= d|d<   ni }t        d      D ]8  }d}t        d|fi |\  }}}| j                  |d	       |j                  |       : t        t        |            }| j                  t        |      d
dj                  |             d}t        d|d      \  }}}| j                  d|       t        d|d      \  }}}| j                  d|       t        d|d      \  }}}| j                  d|       t        dd|d      \  }}}| j                  d|       y )Nz-RPYTHONHASHSEEDrandomr   
__cleanenv   zprint(hash("spam"))rR   r   r7   z83 runs produced an identical random hash  for "spam": {})msgz<import sys; print("random is", sys.flags.hash_randomization)ry   r/  s   random is 1r   s   random is 0)r#   r   r   getr   ranger   r]   appendsortedsetassertGreaterr,   r"  r*   )r   hashesr   irq   r    r!   r"   s           r   test_hash_randomizationz#CmdLineTest.test_hash_randomization  sl   t$::>>*H5Arzz"C $% #CCq 	A(D+D$>#>LBSR#MM#		
 F$3v; 117 	 	A
 N'd2FCnc*'d8LCnc*'d3GCnc*'dDMCnc*r   c                     t         j                  }| j                  t         j                  |       t	        |dd      5 }t        d|       t        d|       d d d        t        |       y # 1 sw Y   xY w)Nwr}   r   z
import sys)filezdel sys.modules['__main__'])r   TESTFN
addCleanupunlinkopenprintr   )r   filenamescripts      r   test_del___main__zCmdLineTest.test_del___main__5  se     ##	(((3(C'2 	>f,V,/f=	> 	"	> 	>s   A..A7c                    t        dd      \  }}}| j                  d|       | j                  |j                         j	                  d      d       | j                  d|       t        dd      \  }}}| j                  d|       | j                  |j                         j	                  d      d       | j                  d|       t        ddd      \  }}}| j                  d|       | j                  d|       | j                  |j                         j	                  d      d       | j                  d|       y )	NrQ   z-zs   Unknown option: -zr7   r   )withoutz-as   Unknown option: -a)r   r*   r]   r)   countr   rM   s       r   test_unknown_optionsz CmdLineTest.test_unknown_options@  s   ,T48C+S1)//0EFJc" -T4@C+S1)//0EFJc",T4FC+S1.4)//0EFJc"r   6Cannot run -I tests when PYTHON env vars are required.c                    | j                  d       | j                  d       t        dddd      \  }}}| j                  |j                         d       t	        j
                         5 }t        j                  j                  |d      }t        j                  j                  |d	      }t        |d
d      5 }|j                  d       d d d        t        |d
d      5 }|j                  d       |j                  d       d d d        | j                  t        j                  t        j                  t        j                   d|g|t        j"                         t        j                  t        j                   d|g|      }| j                  |j                         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)Nrk   z-IEPsrR   z`from sys import flags as f; print(f.no_user_site, f.ignore_environment, f.isolated, f.safe_path)ry   )dummyvars
   1 1 1 Truezuuid.pyzmain.pyr?  r}   r@  z)raise RuntimeError('isolated mode test')
zimport uuid
zprint('ok')
rQ   )cwdrc   )rQ  s   ok)r#   r   r]   stripr   temp_cwdr   r   r9   rE  r   assertRaisesrU   CalledProcessErrorrV   rD   rT   DEVNULL)r   r    r!   r"   tmpdirfakemainfs           r   test_isolatedmodezCmdLineTest.test_isolatedmodeS  s    	t$w''dS 	C
 	m4! 	1V77<<	2D77<<	2DdC'2 FaDEFdC'2 )a(() j;;(55"~~tT:%/%7%7  9 ))3>>4*F.46CSYY[%0	1 	1F F) )	1 	1s>   *AG9F.G!#F:B!G.F7	3G:G	?GGc                     dD ]Y  \  }}t        ||||      }t        t        |            }d| d| d}| j                  |      5  t	        d|fi | d d d        [ y # 1 sw Y   fxY w)N))ry   r   )r   r7   )r   r7   )2rC   )PYTHONDEBUGPYTHONOPTIMIZEPYTHONDONTWRITEBYTECODEPYTHONVERBOSEzimport sys; sys.stderr.write(str(sys.flags)); sys.exit(not (
                    sys.flags.debug == sys.flags.optimize ==
                    sys.flags.verbose ==
                    z:
                    and sys.flags.dont_write_bytecode == z
                )))envar_valuerR   )r   intboolr~   r   )r   valuer   env_varsdont_write_bytecoderq   s         r   test_sys_flags_setzCmdLineTest.test_sys_flags_seto  s    I 	9OE8!$(-#	H #&d5k"2
 J ::M9N O  %0 9 t8x89 9%	9$9 9s   A  A)	c                 d   t               }dddddd|d fg}|D ]~  \  }}}|dnd| d	}d
| d}d|g}|i nd|i}	||u rddg|d d n|
dd| g|d d | j                  ||      5  t        j                         5  t	        |i |	 d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)N)NNN)fooNrj  )Nbarrk  )rj  rk  rk  )rj  ry   Nrj  zis Nonez== ""z,import sys; sys.exit(not sys.pycache_prefix r   rR   PYTHONPYCACHEPREFIXrl   pycache_prefixr   zpycache_prefix=)envvalopt)objectr~   r   rS  r   )
r   NO_VALUEcasesro  rp  r   
exp_clauserq   rX   r   s
             r   test_set_pycache_prefixz#CmdLineTest.test_set_pycache_prefix  s    8   !Hd#
 &+ 	3!FC&.&6d8*A<NJA*QOD$<D"-BF,KCh "23Ra OC5"9:RaV5 3'') 3$d2c233 3	33 33 3s$   &B&;BB&B#B&&B/	T)check_exitcodexdevc                   t        t        j                        }|j                  dd        |j                  dd        |j                  dd        |rt        j
                  ddg|}nt        j
                  g|}t        j                  |t        j                  t        j                  d|      }|r| j                  |j                  d|       |j                  j                         S )	NPYTHONWARNINGSPYTHONDEVMODEPYTHONMALLOCrl   devTrb   rc   universal_newlinesr   r   )r   r   r   poprD   rT   rU   r   re   r   r]   r   rb   rn   )r   rv  rw  rX   r   r   s         r   run_xdevzCmdLineTest.run_xdev  s    2:: $'&%NND%7$7DNN*T*D~~d%/__%/%6%615"%	'
 T__a6{{!!##r   c                 r   d}| j                  d|d      }| j                  |d       | j                  d|      }| j                  |d       d}t        j                  rd}nd	}| j                  d|      }| j                  ||       | j                  d
d|      }| j                  |d|        | j                  dd|      }| j                  |d|        | j                  dd|      }| j                  |d|        	 dd l}d}t        j
                         5  | j                  d|d      }d d d        t        j                         rd}nd}| j                  ||       	 dd l}d}| j                  d|      }| j                  |d       y # 1 sw Y   `xY w# t        $ r Y Cw xY w# t        $ r Y y w xY w)N%import sys; print(sys.flags.dev_mode)rR   F)rw  FalseTruez\import warnings; print(' '.join('%s::%s' % (f[0], f[2].__name__) for f in warnings.filters))zdefault::Warningzdefault::Warning default::DeprecationWarning ignore::DeprecationWarning ignore::PendingDeprecationWarning ignore::ImportWarning ignore::ResourceWarningz-bzdefault::BytesWarning -bbzerror::BytesWarning z-Werrorzerror::Warning r   <import _testcapi; print(_testcapi.pymem_getallocatorsname()))rv  pymalloc_debugmalloc_debugz5import faulthandler; print(faulthandler.is_enabled()))	r  r]   r   ro   	_testcapiSuppressCrashReportwith_pymallocImportErrorfaulthandler)r   rq   r!   expected_filtersr  
alloc_namer  s          r   	test_xdevzCmdLineTest.test_xdev  s    7mmD$Um3g&mmD$'f%> 1!: mmD$'./mmD$- 67G6HIJmmE4. 45E4FGHmmItT20@/ABC	. RD,,. FmmD$umEF$$&-
+
S*-	* KD--d+CS&)!F F	  		  		s0   F F$F* F	F'&F'*	F65F6c                    |rd}nd}|dz  }t         j                  d|dd|f}t        t        j                        }|j                  dd        ||d<   t        j                  |t        j                  t        j                  d	|
      }| j                  |j                  d|       |j                  j                         S )Nzimport sys; from test.support.import_helper import import_fresh_module; warnings = import_fresh_module('warnings', blocked=['_warnings']); zimport sys, warnings; zKprint(' '.join('%s::%s' % (f[0], f[2].__name__) for f in warnings.filters))z-Wr  rR   rz  ry  Tr}  r   )rD   rT   r   r   r   r  rU   r   re   r   r]   r   rb   rn   )r   cmdline_optionenvvaruse_pywarningrq   rX   r   r   s           r   check_warnings_filtersz"CmdLineTest.check_warnings_filters  s    ZD ,D > 	?neT4H2::& &~~d%/__%/%6%615"%	'
 	!T2{{!!##r   c                     d}t         j                  s|dz  }| j                  dd      }| j                  ||       | j                  ddd      }| j                  ||       y )Nz9error::BytesWarning once::UserWarning always::UserWarningz default::DeprecationWarning ignore::DeprecationWarning ignore::PendingDeprecationWarning ignore::ImportWarning ignore::ResourceWarningzonce::UserWarningzalways::UserWarningT)r  )r   ro   r  r]   )r   r  r!   s      r   test_warnings_filter_precedencez+CmdLineTest.test_warnings_filter_precedence  s    2  "; < ))*=*?A./))*=*?8< * > 	./r   c                    d}t        t        j                        }|j                  dd        |||d<   n|j                  dd        t        j
                  d|f}t        j                  |t        j                  t        j                  d|      }| j                  |j                  j                         |       | j                  |j                  d       y )Nr  rz  r{  rR   Tr}  r   )r   r   r   r  rD   rT   rU   r   re   r   r]   rb   rn   r   )r   env_varnamerq   r   rX   r   s          r   check_pythonmalloczCmdLineTest.check_pythonmalloc  s    M2::&")CGGND)d+~~d%/__%/%6%615"%	'
 	++-t4!,r   c                 L   t        j                         }|rt         j                  rdnd}d}nt         j                  rdnd}d}d |fd|fddg}|r|j                  d       |D ]3  \  }}| j	                  ||	      5  | j                  ||       d d d        5 y # 1 sw Y   @xY w)
Nr  pymallocr  mallocdebug)r  r  )r  r  ))r  r  )r  r  )r  r  )r   r  ro   rd   r~   r  )r   r  default_namedefault_name_debugr   r  r  s          r   test_pythonmalloczCmdLineTest.test_pythonmalloc*  s    ((*/6/?/?+ZL!1-4-=-=>8L!/ < () ,	
 LL  
 # 	7MGTgD9 7''67 7	77 7s   <BB#	c                 F   d}t        t        j                        }|j                  dd        t        j
                  d|f}t        j                  |t        j                  d|      }| j                  |j                  j                         d       | j                  |j                  d|       d|d<   t        j                  |t        j                  d|      }| j                  |j                  j                         d	       | j                  |j                  d|       y )
Nr  rz  rR   T)rb   r~  r   r  r   r   r  )r   r   r   r  rD   rT   rU   r   re   r]   rb   rn   r   )r   rq   r   rX   r   s        r   test_pythondevmode_envz"CmdLineTest.test_pythondevmode_envD  s    62::&d+~~d:??153@++-w7!T2"O~~d:??153@++-v6!T2r   z!bpo-32457 only applies on Windowsc                 t   t         j                  ddf}t        j                  j	                  t         j                        \  }}|dz   |z   }t        j                  |t
        j                  |      }| j                  |j                  d|       | j                  |j                  j                         d       y )NrR   zprint(0)z\.\.\.\)rb   rT   r      0)rD   rT   r   r   splitrU   r   re   r]   r   rb   rR  )r   rX   prefixexerT   r   s         r   test_argv0_normalizationz$CmdLineTest.test_argv0_normalizationV  s     ~~tZ/ggmmCNN3m+c1
~~d:??)35!T2**,d3r   c                 :   t         j                  ddg}t        j                  |t        j                  t        j                  d      }d}| j                  |j                  j                  |      |j                         | j                  |j                  d       y )Nrk   z--unknown-optionT)rb   rc   r   z'unknown option --unknown-option
usage: r   )
rD   rT   rU   r   re   r   rc   rH   assertNotEqualr   )r   rX   r   err_msgs       r   test_parsing_errorzCmdLineTest.test_parsing_errorb  sp    &89~~d%/__%/__#') =..w7EDOOQ/r   c                    d}t        ddd|       t        ddd|       t        ddd|       t        ddd|d       t        d|d	       t        d|d
       d }t        d|      }t        j                         }| j	                   ||      ||f       t        ddd|      }| j	                   ||      d       t        ddd|      }| j	                   ||      d       t        ddd|      }| j	                   ||      d       t        d|d      }| j	                   ||      d       t        d|d      }| j	                   ||      d       t        ddd|d      }| j	                   ||      d       y )NzMimport sys; print(sys.flags.int_max_str_digits, sys.get_int_max_str_digits())rl   int_max_str_digitsrR   zint_max_str_digits=foozint_max_str_digits=1004000)PYTHONINTMAXSTRDIGITSrj  100c                     | j                   j                         j                  d      }t        d |j	                         D              S )Nr}   c              3   2   K   | ]  }t        |        y wr   )rc  ).0r<  s     r   	<genexpr>zGCmdLineTest.test_int_max_str_digits.<locals>.res2int.<locals>.<genexpr>{  s     5AQ5s   )r!   rR  r:   tupler  )r   r!   s     r   res2intz4CmdLineTest.test_int_max_str_digits.<locals>.res2inty  s3    ''--/((1C5555r   zint_max_str_digits=0)r   r   zint_max_str_digits=4000)  r  zint_max_str_digits=100000)順 r  r   zint_max_str_digits=6000)p  r  )r   r   rD   get_int_max_str_digitsr]   )r   rq   r  r   current_maxs        r   test_int_max_str_digitsz#CmdLineTest.test_int_max_str_digitsm  s}   ^d$8$Ed$<dDId$<dDId$8$4:	< 	dDFdDF	6 tT*002['ABt%;T4Hv.t%>dK|4t%@$M'78tTEv.tTH|4+T4"(
 	|4r   N)F)J__name__
__module____qualname__r   r#   r   cpython_onlyr/   r3   r5   r;   r>   rA   rK   rN   r   skipIfr	   r^   rr   r   r   r   r   r   
skipUnlessr   r   r   r   rD   r  r   r   
is_androidr   r   r   r   r   flags	safe_pathr   r   r  r  r
  r  r  r  r  r   r  r#  r&  r(  r+  r-  r=  rI  rM  r[  rh  ru  r  r  r  r  r  r  r  r  r  r   r   r   r   r      s   % ( ( * * & & 	, 	,&% 5 51 X__57MO:O: '> D D
4	<I' X..0LM( N( X..0LMF NF X__S\\W,79Q9QB X__S\\W,79(G9(GT X#,,(2 #""%LN*N*(/L 52 X__SYY((>@%@%")$
4-"#@# X__RWW')EFX__S\\Y.IK+K G+0'((;#+J	# # #$ X__57MO1O149.34 .2 $& 9* 9*v$*0*-"743$ X0<>4>4 0 0"5r   r   rN  c                   $    e Zd Zd Zd Zd Zd Zy)IgnoreEnvironmentTestc                 @    dj                  |      }t        dd|fi |S )Nz@import sys; sys.stderr.write(str(sys.flags)); sys.exit(not ({}))rQ   rR   )r"  r   )r   	predicaterf  rq   s       r   run_ignoring_varsz'IgnoreEnvironmentTest.run_ignoring_vars  s*    
 RXXYbcdD=H==r   c                 L    d}| j                  dj                  |      |       y )Nshould_be_ignoredz'{}' not in sys.pathr   )r  r"  )r   r   s     r   test_ignore_PYTHONPATHz,IgnoreEnvironmentTest.test_ignore_PYTHONPATH  s+    "5<<TB*. 	 	0r   c                 *    | j                  dd       y )Nz!sys.flags.hash_randomization == 1r   r4  r  r   s    r   test_ignore_PYTHONHASHSEEDz0IgnoreEnvironmentTest.test_ignore_PYTHONHASHSEED  s    B.1 	 	3r   c                 6    d}| j                  |ddddd       y )Nz
            (sys.flags.debug == sys.flags.optimize ==
             sys.flags.dont_write_bytecode ==
             sys.flags.verbose == sys.flags.safe_path == 0)
        r   )r^  r_  r`  ra  PYTHONSAFEPATHr  )r   expected_outcomes     r   test_sys_flags_not_setz,IgnoreEnvironmentTest.test_sys_flags_not_set  s1    
 	$' 	 	
r   N)r  r  r  r  r  r  r  r  r   r   r  r    s    >0
3
r   r  c                       e Zd Zd Zd Zd Zy)SyntaxErrorTestsc                 6   t        j                  t        j                  dg|t         j                  t         j                        }| j                  |j                  d       | j                  |j                  d        | j                  d|j                         y )N-)inputrb   rc   r   s   
SyntaxError)	rU   r   rD   rT   re   r  r   rc   r*   )r   rq   r   s      r   check_stringzSyntaxErrorTests.check_string  sf    ~~s~~s34%/__Z__NDOOQ/DKK.&4r   c                 &    | j                  d       y )Ns   (1+2+3r  r   s    r   test_tokenizer_error_with_stdinz0SyntaxErrorTests.test_tokenizer_error_with_stdin  s    )$r   c                 &    | j                  d       y )Ns   '\u1f'r  r   s    r   *test_decoding_error_at_the_end_of_the_linez;SyntaxErrorTests.test_decoding_error_at_the_end_of_the_line  s    *%r   N)r  r  r  r  r  r  r  r   r   r  r    s    5%&r   r  c                  ,    t        j                          y r   )r   reap_childrenr  r   r   tearDownModuler    s    r   __main__)r   rU   rD   r   r   r   r   r   test.supportr   test.support.script_helperr   r   r   r   r	   has_subprocess_supportSkipTestr   TestCaser   r  r  r  r  r  rY  r  r   r   <module>r     s   
 
  
     " 
 %%
(

=
>>r5(## r5j 13IK!
H-- !
K!
H&x(( & zHMMO r   