B
    u9a_x  ã               @   s¶   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	m
Z
mZmZmZ eedƒZdd„ ZG dd„ dejƒZe eƒ d	¡G d
d„ dejƒƒZdd„ Zedkr²eƒ  dS )é    N)Úsupport)Úspawn_pythonÚkill_pythonÚassert_python_okÚassert_python_failureÚ interpreter_requires_environmentZgettotalrefcountc             C   s   t | ƒ}|  ¡ }||fS )N)r   Úwait)ÚpÚdataÚ
returncode© r   ú#/usr/lib/python3.7/test_cmd_line.pyÚ_kill_python_and_exit_code   s    r   c               @   sö  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	e
 eƒ d¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Ze
 ejd¡dd„ ƒZe
 ejdkd¡dd „ ƒZe
 ejd!kp¸ejd"¡d#d$„ ƒZd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z d1d2„ Z!d3d4„ Z"d5d6„ Z#d7d8„ Z$d9d:„ Z%d;d<„ Z&e
 e'j(d=kd>¡d?d@„ ƒZ)dAdB„ Z*dCdD„ Z+dEdF„ Z,dGdH„ Z-dIdJ„ Z.dKdL„ Z/dMdN„ Z0e
 eƒ dO¡dPdQ„ ƒZ1dRdS„ Z2dTdTdUœdVdW„Z3dXdY„ Z4did[d\„Z5d]d^„ Z6d_d`„ Z7dadb„ Z8dcdd„ Z9e
 ejdkde¡dfdg„ ƒZ:dhS )jÚCmdLineTestc             C   s   t dƒ t dƒ d S )NÚ.z< .)r   )Úselfr   r   r   Útest_directories   s    zCmdLineTest.test_directoriesc             C   sB   t |Ž \}}}|  |dkp"| d¡¡ |  d|¡ |  d|¡ d S )Nó    ó   
s	   Traceback)r   Ú
assertTrueÚendswithÚassertNotIn)r   Zcmd_lineÚrcÚoutÚerrr   r   r   Úverify_valid_flag!   s    zCmdLineTest.verify_valid_flagc             C   s   |   d¡ |   d¡ d S )Nz-Oz-OO)r   )r   r   r   r   Útest_optimize'   s    
zCmdLineTest.test_optimizec             C   s   |   d¡ d S )Nz-S)r   )r   r   r   r   Útest_site_flag+   s    zCmdLineTest.test_site_flagc             C   s   t dƒ\}}}|  d|¡ d S )Nz-hs   usage)r   ÚassertIn)r   r   r   r   r   r   r   Ú
test_usage.   s    zCmdLineTest.test_usagec             C   sX   dt jd d…   d¡}x:dD ]2}t|ƒ\}}}|  | |¡¡ |  | |¡¡ qW d S )NzPython %d.%dé   Úascii)z-Vz	--versionz-VV)ÚsysÚversion_infoÚencoder   ZassertFalseÚ
startswithr   )r   ÚversionZswitchr   r   r   r   r   r   Útest_version2   s
    
zCmdLineTest.test_versionc             C   s8   t dƒ\}}}|  d|¡ t dƒ\}}}|  d|¡ d S )Nz-vs   stack overflowz-vv)r   r   )r   r   r   r   r   r   r   Útest_verbose9   s    zCmdLineTest.test_verbosez6Cannot run -E tests when PYTHON env vars are required.c             C   s:   dd„ }|ƒ }|   |i ¡ |ddƒ}|   |dddœ¡ d S )Nc              W   s4   t jdf|  } | d7 } t | ¡}t| ¡ d ƒ}|S )Nz-E)z-cz import sys; print(sys._xoptions)r   )r"   Ú
executableÚ
subprocessÚcheck_outputÚevalÚ
splitlines)Úargsr   Úoptsr   r   r   Úget_xoptionsE   s
    
z/CmdLineTest.test_xoptions.<locals>.get_xoptionsz-Xaz	-Xb=c,d=eTzc,d=e)ÚaÚb)ÚassertEqual)r   r0   r/   r   r   r   Útest_xoptionsB   s
    	
zCmdLineTest.test_xoptionsc                s‚   ‡ fdd„}d}|d|ƒ\}}}ˆ   | ¡ d¡ ˆ   |d¡ |ddd|ƒ\}}}ˆ   | ¡ d	¡ trrˆ  |d
¡ nˆ   |d¡ d S )Nc                 sd   t jg}| | ¡ tj}tj|||d}| ¡ \}}|j ¡  |j	 ¡  |j
}ˆ  |d¡ |||fS )N)ÚstdoutÚstderrr   )r"   r)   Úextendr*   ÚPIPEÚPopenÚcommunicater5   Úcloser6   r   r3   )r.   Úcmdr8   r	   r   r   r   )r   r   r   Ú
run_pythonU   s    


z1CmdLineTest.test_showrefcount.<locals>.run_pythonz import sys; print(sys._xoptions)z-cs   {}r   z-XZshowrefcounts   {'showrefcount': True}s   ^\[\d+ refs, \d+ blocks\])r3   ÚrstripÚPy_DEBUGÚassertRegex)r   r=   Úcoder   r   r   r   )r   r   Útest_showrefcountT   s    zCmdLineTest.test_showrefcountc             C   s0   t dƒ t ddƒ t dddƒ tddddƒ d S )Nz-mZfnord43520xyzZrunpyÚtimeitz-nÚ1)r   r   )r   r   r   r   Útest_run_modulep   s    
zCmdLineTest.test_run_modulec             C   s\   t dddddƒ}|j d¡ |j d¡ t|ƒ}|  | d¡d	k¡ |  | d
¡d	k¡ d S )Nz-iz-mrC   z-nrD   s   Timer
s   exit()
s   1 loopéÿÿÿÿs   __main__.Timer)r   ÚstdinÚwriter   r   Úfind)r   r	   r
   r   r   r   Útest_run_module_bug1764407|   s    z&CmdLineTest.test_run_module_bug1764407c             C   s    t dƒ t ddƒ tddƒ d S )Nz-czraise ExceptionÚpass)r   r   )r   r   r   r   Útest_run_code‡   s    
zCmdLineTest.test_run_codezneed support.FS_NONASCIIc             C   s"   dt jtt jƒf }td|ƒ d S )Nzassert(ord(%r) == %s)z-c)r   ÚFS_NONASCIIÚordr   )r   Zcommandr   r   r   Útest_non_ascii   s    zCmdLineTest.test_non_asciiÚwin32z Windows has a native unicode APIc             C   s¤   d}t j ¡ }d|d< d|d< d| d }tjtjd|gtjtj|d	}| 	¡ \}}|j
d
krdd}n"|j
dkrtd}ntd|j
|f ƒ‚| |¡s td||f ƒ‚d S )Nó   ÿÚCÚLC_ALLÚ0ZPYTHONCOERCECLOCALEs   import locale; print(ascii("s"   "), locale.getpreferredencoding())z-c)r5   r6   Úenvé   s3   Unable to decode the command from the command line:r   s   '\xff' z Unknown exit code: %s, output=%az%a doesn't start with %a)ÚosÚenvironÚcopyr*   r9   r"   r)   r8   ÚSTDOUTr:   r   ÚAssertionErrorr%   )r   ZundecodablerU   rA   r	   r5   r6   Úpatternr   r   r   Útest_undecodable_code›   s"    




z!CmdLineTest.test_undecodable_codeÚdarwinz%test specific to Mac OS X and Androidc                s.   ‡ fdd„}d  d¡}||ƒ d}||ƒ d S )Nc                sv   |   dd¡}t|ƒ d¡d }tj ¡ }d|d< tjtj	dd| ftj
|d	}| ¡ \}}ˆ  ||¡ ˆ  |jd
¡ d S )Nzutf-8Úsurrogateescaper!   r   rR   rS   z-cz%import sys; print(ascii(sys.argv[1])))r5   rU   r   )Údecoder!   r$   rW   rX   rY   r*   r9   r"   r)   r8   r:   r3   r   )ÚtextZdecodedÚexpectedrU   r	   r5   r6   )r   r   r   r+   Á   s    
z7CmdLineTest.test_osx_android_utf8.<locals>.check_outputu   e:Ã©, euro:â‚¬, non-bmp:ô¿¿zutf-8s   ÿÃ©Ãÿí €)r$   )r   r+   ra   r   )r   r   Útest_osx_android_utf8¾   s
    
z!CmdLineTest.test_osx_android_utf8c             C   sŠ   x„dD ]|}d| }t dd|ƒ\}}}|dkr0|n|}|  |dd| ¡ d| }t dd|ƒ\}}}|dkrl|n|}|  |dd	| ¡ qW d S )
N)r5   r6   z6import os, sys; sys.%s.buffer.write(b'x'); os._exit(0)z-uz-cr6   ó   xzbinary %s not unbufferedz.import os, sys; sys.%s.write('x'); os._exit(0)ztext %s not unbuffered)r   r3   )r   ÚstreamrA   r   r   r   r
   r   r   r   Útest_unbuffered_outputß   s    
z"CmdLineTest.test_unbuffered_outputc             C   sT   d}t dd|ƒ}|j d¡ |j ¡  t|ƒ\}}|  |d¡ |  | d¡|¡ d S )Nz/import sys; sys.stdout.write(sys.stdin.read(1))z-uz-crd   r   )r   rG   rH   Úflushr   r3   r   r%   )r   rA   r	   r
   r   r   r   r   Útest_unbuffered_inputï   s    
z!CmdLineTest.test_unbuffered_inputc             C   sX   d}d}|t j | }d}tdd||d\}}}|  | d¡|¡ |  | d¡|¡ d S )NAô  ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEAô  FGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJFGHIJz¨if 1:
            import sys
            path = ":".join(sys.path)
            path = path.encode("ascii", "backslashreplace")
            sys.stdout.buffer.write(path)z-Sz-c)Ú
PYTHONPATHr!   )rW   Úpathsepr   r   r$   )r   Zpath1Zpath2ÚpathrA   r   r   r   r   r   r   Útest_large_PYTHONPATHù   s    z!CmdLineTest.test_large_PYTHONPATHc             C   s<   d}t d|dd\}}}t d|dd\}}}|  ||¡ d S )Nz¨if 1:
            import sys
            path = ":".join(sys.path)
            path = path.encode("ascii", "backslashreplace")
            sys.stdout.buffer.write(path)z-cÚ )ri   F)Z
__isolated)r   r3   )r   rA   Zrc1Zout1Zerr1Zrc2Zout2Zerr2r   r   r   Ú test_empty_PYTHONPATH_issue16309  s    
z,CmdLineTest.test_empty_PYTHONPATH_issue16309c             C   s’   xŒdD ]„}t j ¡ }||d< tjtjdgtjtjtj|d}d}|j	 
t|ƒ d¡d ¡ |j	 
d¡ t|ƒ}t|ƒ |d	¡}|  ||¡ qW d S )
N)r!   zlatin-1zutf-8ZPYTHONIOENCODINGz-i)rG   r5   r6   rU   u   a=Ã© b=í²€ c=ð€€ d=ô¿¿r!   r   s   exit()
Úbackslashreplace)rW   rX   rY   r*   r9   r"   r)   r8   rZ   rG   rH   r!   r$   r   Úreprr   )r   ÚencodingrU   r	   ra   r
   Zescapedr   r   r   Útest_displayhook_unencodable  s    

z(CmdLineTest.test_displayhook_unencodablec          
   C   sŠ   t  d¡f}tj d¡}| | d¡¡ | ¡  | d¡ t	j
tjd|f|t	jd}| ¡ \}}W d Q R X W d Q R X |  | ¡ |¡ d S )Nzwb+ÚASCII)s   abcs   defr   z-c)rG   r5   )ÚtempfileZNamedTemporaryFilerW   Úlinesepr$   rH   Újoinrg   Úseekr*   r9   r"   r)   r8   r:   r3   r>   )r   rA   rb   rG   ÚsepÚprocr5   r6   r   r   r   Úcheck_input+  s    

 zCmdLineTest.check_inputc             C   s   |   dd¡ d S )Nz-import sys; print(repr(sys.stdin.readline()))s   'abc\n')rz   )r   r   r   r   Útest_stdin_readline7  s    zCmdLineTest.test_stdin_readlinec             C   s   |   dd¡ d S )Nzprint(repr(input()))s   'abc')rz   )r   r   r   r   Útest_builtin_input>  s    zCmdLineTest.test_builtin_inputc             C   sT   d}t d|ƒ\}}}tjdkr8|  d|¡ |  d|¡ n|  d|¡ |  d|¡ d S )Nz’if 1:
            import sys
            print(1)
            print(2)
            print(3, file=sys.stderr)
            print(4, file=sys.stderr)z-crP   s   1
2
s   3
4s   1
2
s   3
4)r   r"   Úplatformr3   )r   rA   r   r   r   r   r   r   Útest_output_newlineD  s    
zCmdLineTest.test_output_newlinec             C   s4   t ddƒ\}}}|  | dd¡d¡ |  d|¡ d S )Nz-cú'r!   ÚignoreÚSyntaxErrorr   )r   r@   r`   r3   )r   r   r   r   r   r   r   Útest_unmached_quoteU  s    zCmdLineTest.test_unmached_quotec             C   sD   d}t d|ƒ\}}}|  d|¡ |  d|¡ |  | dd¡d¡ d S )Nzµif 1:
            import os, sys, test.support
            test.support.SuppressCrashReport().__enter__()
            sys.stdout.write('x')
            os.close(sys.stdout.fileno())z-cr   éx   r!   r€   z"Exception ignored in.*
OSError: .*)r   r3   r@   r`   )r   rA   r   r   r   r   r   r   Útest_stdout_flush_at_shutdown\  s    z)CmdLineTest.test_stdout_flush_at_shutdownc             C   s$   d}t d|ƒ\}}}|  d|¡ d S )Nzimport sys; sys.stdout.close()z-cr   )r   r3   )r   rA   r   r   r   r   r   r   Útest_closed_stdoutj  s    zCmdLineTest.test_closed_stdoutÚposixztest needs POSIX semanticsc                sl   dj ˆ d}‡ fdd„}tjtjdd|gtjtjtj|d}| ¡ \}}|  t 	|¡d¡ |  |j
d	¡ d S )
Nz»if 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                  s:   dˆ krt  d¡ dˆ kr$t  d¡ dˆ kr6t  d¡ d S )NrG   r   r5   rV   r6   r    )rW   r;   r   )r‡   r   r   Úpreexec{  s    

z+CmdLineTest._test_no_stdio.<locals>.preexecz-Ez-c)rG   r5   r6   Z
preexec_fnr   é*   )Úformatr*   r9   r"   r)   r8   r:   r3   r   Zstrip_python_stderrr   )r   r‡   rA   rˆ   r	   r   r   r   )r‡   r   Ú_test_no_stdios  s    zCmdLineTest._test_no_stdioc             C   s   |   dg¡ d S )NrG   )r‹   )r   r   r   r   Útest_no_stdinŒ  s    zCmdLineTest.test_no_stdinc             C   s   |   dg¡ d S )Nr5   )r‹   )r   r   r   r   Útest_no_stdout  s    zCmdLineTest.test_no_stdoutc             C   s   |   dg¡ d S )Nr6   )r‹   )r   r   r   r   Útest_no_stderr’  s    zCmdLineTest.test_no_stderrc             C   s   |   dddg¡ d S )NrG   r5   r6   )r‹   )r   r   r   r   Útest_no_std_streams•  s    zCmdLineTest.test_no_std_streamsc             C   s.  |   d¡ g }tj dd¡dkr:ttjƒ}|d= d|d< ni }x>tdƒD ]2}d}td|f|Ž\}}}|  |d	¡ | |¡ qHW t	t
|ƒƒ}| jt|ƒd
d |¡d d}td|dd\}}}|  d|¡ td|dd\}}}|  d|¡ td|dd\}}}|  d|¡ tdd|dd\}}}|  d|¡ d S )Nz-RÚPYTHONHASHSEEDZrandomrD   Z
__cleanenvé   zprint(hash("spam"))z-cr   rV   z83 runs produced an identical random hash  for "spam": {})Úmsgz<import sys; print("random is", sys.flags.hash_randomization)rm   )r   s   random is 1rT   s   random is 0)r   rW   rX   ÚgetÚdictÚranger   r3   ÚappendÚsortedÚsetZassertGreaterÚlenrŠ   r   )r   ZhashesrU   ÚirA   r   r   r   r   r   r   Útest_hash_randomization˜  s2    



z#CmdLineTest.test_hash_randomizationc          	   C   sN   t j}|  t j|¡ t|dƒ}td|d td|d W d Q R X t|ƒ d S )NÚwz
import sys)Úfilezdel sys.modules['__main__'])r   ZTESTFNZ
addCleanupÚunlinkÚopenÚprintr   )r   ÚfilenameZscriptr   r   r   Útest_del___main__½  s    zCmdLineTest.test_del___main__c             C   sÐ   t ddƒ\}}}|  d|¡ |  | ¡  d¡d¡ |  d|¡ t ddd\}}}|  d|¡ |  | ¡  d¡d¡ |  d|¡ t dddd\}}}|  d|¡ |  d|¡ |  | ¡  d¡d¡ |  d|¡ d S )	Nz-Ez-zs   Unknown option: -zrV   r   )Zwithoutz-as   Unknown option: -a)r   r   r3   r-   Úcountr   )r   r   r   r   r   r   r   Útest_unknown_optionsÈ  s    z CmdLineTest.test_unknown_optionsz6Cannot run -I tests when PYTHON env vars are required.c          
   C   sþ   |   d¡ |   d¡ tddddd\}}}|  | ¡ d¡ t ¡ ²}tj |d¡}tj |d	¡}t	|d
ƒ}| 
d¡ W d Q R X t	|d
ƒ}| 
d¡ | 
d¡ W d Q R X | jtjtjtj|g|tjd tjtjd|g|d}|  | ¡ d¡ W d Q R X d S )Nz-Iz-IEsz-czSfrom sys import flags as f; print(f.no_user_site, f.ignore_environment, f.isolated)rm   )Zdummyvars   1 1 1zuuid.pyzmain.pyrœ   z)raise RuntimeError('isolated mode test')
zimport uuid
zprint('ok')
)Úcwdr6   )r¥   s   ok)r   r   r3   Ústripr   Ztemp_cwdrW   rk   rv   rŸ   rH   ZassertRaisesr*   ZCalledProcessErrorr+   r"   r)   ZDEVNULL)r   r   r   r   ZtmpdirZfakeÚmainÚfr   r   r   Útest_isolatedmodeÚ  s*    





zCmdLineTest.test_isolatedmodec          
   C   sX   xRdD ]J\}}t ||||d}d|› d}| j|d td|f|Ž W d Q R X qW d S )N))rm   r   )rD   rV   )ra   rV   )Ú2r    )ÚPYTHONDEBUGÚPYTHONOPTIMIZEÚPYTHONDONTWRITEBYTECODEÚPYTHONVERBOSEzØimport sys; sys.stderr.write(str(sys.flags)); sys.exit(not (
                    sys.flags.debug == sys.flags.optimize ==
                    sys.flags.dont_write_bytecode == sys.flags.verbose ==
                    z
                )))Zenvar_valuez-c)r”   ÚsubTestr   )r   Úvaluerb   Úenv_varsrA   r   r   r   Útest_sys_flags_setõ  s    zCmdLineTest.test_sys_flags_setT)Úcheck_exitcodeÚxdevc            G   s†   t tjƒ}| dd ¡ | dd ¡ | dd ¡ |rDtjddf|˜}ntjf|˜}tj|tjtj	d|d}|r||  
|jd|¡ |j ¡ S )	NÚPYTHONWARNINGSÚPYTHONDEVMODEÚPYTHONMALLOCz-XZdevT)r5   r6   Úuniversal_newlinesrU   r   )r”   rW   rX   Úpopr"   r)   r*   Úrunr8   rZ   r3   r   r5   r>   )r   r³   r´   r.   rU   ry   r   r   r   Úrun_xdev
  s    
zCmdLineTest.run_xdevc          	   C   sp  d}| j d|dd}|  |d¡ |   d|¡}|  |d¡ d}trFd}nd	}|   d|¡}|  ||¡ |   d
d|¡}|  |d|› ¡ |   dd|¡}|  |d|› ¡ |   dd|¡}|  |d|› ¡ ydd l}W n tk
râ   Y nJX d}t ¡  | j d|dd}W d Q R X t ¡ rd}nd}|  ||¡ ydd l}W n tk
rN   Y nX d}|   d|¡}|  |d¡ d S )Nz%import sys; print(sys.flags.dev_mode)z-cF)r´   ÚFalseÚTruez\import warnings; print(' '.join('%s::%s' % (f[0], f[2].__name__) for f in warnings.filters))zdefault::Warningz—default::Warning default::DeprecationWarning ignore::DeprecationWarning ignore::PendingDeprecationWarning ignore::ImportWarning ignore::ResourceWarningz-bzdefault::BytesWarning z-bbzerror::BytesWarning z-Werrorzerror::Warning r   z<import _testcapi; print(_testcapi.pymem_getallocatorsname()))r³   Úpymalloc_debugÚmalloc_debugz5import faulthandler; print(faulthandler.is_enabled()))	r»   r3   r?   Ú	_testcapiÚImportErrorr   ZSuppressCrashReportÚwith_pymallocÚfaulthandler)r   rA   r   Úexpected_filtersrÀ   Z
alloc_namerÃ   r   r   r   Ú	test_xdev  sF    

zCmdLineTest.test_xdevFc             C   sx   |r
d}nd}|d7 }t jd|dd|f}ttjƒ}| dd ¡ ||d< tj|tjtj	d	|d
}|  
|jd|¡ |j ¡ S )Nz}import sys; from test.support 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-Wz-bbz-cr¶   rµ   T)r5   r6   r¸   rU   r   )r"   r)   r”   rW   rX   r¹   r*   rº   r8   rZ   r3   r   r5   r>   )r   Zcmdline_optionZenvvarÚuse_pywarningrA   r.   rU   ry   r   r   r   Úcheck_warnings_filtersX  s    
z"CmdLineTest.check_warnings_filtersc             C   sH   d}t s|d7 }|  dd¡}|  ||¡ | jdddd}|  ||¡ d S )Nz9error::BytesWarning once::UserWarning always::UserWarningz‡ default::DeprecationWarning ignore::DeprecationWarning ignore::PendingDeprecationWarning ignore::ImportWarning ignore::ResourceWarningzonce::UserWarningzalways::UserWarningT)rÆ   )r?   rÇ   r3   )r   rÄ   r   r   r   r   Útest_warnings_filter_precedencel  s    z+CmdLineTest.test_warnings_filter_precedencec             C   s€   d}t tjƒ}| dd ¡ |d k	r,||d< n| dd ¡ tjd|f}tj|tjtj	d|d}|  
|j ¡ |¡ |  
|jd¡ d S )Nz<import _testcapi; print(_testcapi.pymem_getallocatorsname())r¶   r·   z-cT)r5   r6   r¸   rU   r   )r”   rW   rX   r¹   r"   r)   r*   rº   r8   rZ   r3   r5   r>   r   )r   Úenv_varÚnamerA   rU   r.   ry   r   r   r   Úcheck_pythonmalloc  s    

zCmdLineTest.check_pythonmallocc          
   C   sŒ   t  ¡ }|rtrdnd}d}ntr&dnd}d}d |fd|fddg}|rP| d¡ x6|D ].\}}| j||d	 |  ||¡ W d Q R X qVW d S )
Nr¾   Úpymallocr¿   ÚmallocÚdebug)rÍ   rÍ   )r¿   r¿   ))rÌ   rÌ   )r¾   r¾   )rÉ   rÊ   )r   rÂ   r?   r7   r¯   rË   )r   rÌ   Zdefault_nameZdefault_name_debugZtestsrÉ   rÊ   r   r   r   Útest_pythonmalloc’  s     zCmdLineTest.test_pythonmallocc             C   sž   d}t tjƒ}| dd ¡ tjd|f}tj|tjd|d}|  	|j
 ¡ d¡ |  	|jd|¡ d|d< tj|tjd|d}|  	|j
 ¡ d	¡ |  	|jd|¡ d S )
Nz%import sys; print(sys.flags.dev_mode)r¶   z-cT)r5   r¸   rU   r¼   r   rD   r½   )r”   rW   rX   r¹   r"   r)   r*   rº   r8   r3   r5   r>   r   )r   rA   rU   r.   ry   r   r   r   Útest_pythondevmode_env¬  s    




z"CmdLineTest.test_pythondevmode_envz!bpo-32457 only applies on Windowsc             C   sb   t jddf}tj t j¡\}}|d | }tj|tj|d}|  |j	d|¡ |  |j
 ¡ d¡ d S )Nz-czprint(0)z\.\.\.\)r5   r)   r   ó   0)r"   r)   rW   rk   Úsplitr*   rº   r8   r3   r   r5   r¦   )r   r.   ÚprefixZexer)   ry   r   r   r   Útest_argv0_normalization¾  s    
z$CmdLineTest.test_argv0_normalizationN)F);Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r'   r(   ÚunittestÚskipIfr   r4   rB   rE   rJ   rL   Z
skipUnlessr   rM   rO   r"   r}   r]   Z
is_androidrc   rf   rh   rl   rn   rr   rz   r{   r|   r~   r‚   r„   r…   rW   rÊ   r‹   rŒ   r   rŽ   r   r›   r¢   r¤   r©   r²   r»   rÅ   rÇ   rÈ   rË   rÏ   rÐ   rÔ   r   r   r   r   r      sd   		" 
	%;
r   z6Cannot run -I tests when PYTHON env vars are required.c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚIgnoreEnvironmentTestc             K   s   d  |¡}tdd|f|ŽS )Nz@import sys; sys.stderr.write(str(sys.flags)); sys.exit(not ({}))z-Ez-c)rŠ   r   )r   Z	predicater±   rA   r   r   r   Úrun_ignoring_varsÎ  s    
z'IgnoreEnvironmentTest.run_ignoring_varsc             C   s   d}| j d |¡|d d S )NZshould_be_ignoredz'{}' not in sys.path)ri   )rÛ   rŠ   )r   rk   r   r   r   Útest_ignore_PYTHONPATHÖ  s    z,IgnoreEnvironmentTest.test_ignore_PYTHONPATHc             C   s   | j ddd d S )Nz!sys.flags.hash_randomization == 1rT   )r   )rÛ   )r   r   r   r   Útest_ignore_PYTHONHASHSEEDÛ  s    z0IgnoreEnvironmentTest.test_ignore_PYTHONHASHSEEDc             C   s   d}| j |ddddd d S )Nz…
            (sys.flags.debug == sys.flags.optimize ==
             sys.flags.dont_write_bytecode == sys.flags.verbose == 0)
        rD   )r«   r¬   r­   r®   )rÛ   )r   Zexpected_outcomer   r   r   Útest_sys_flags_not_setß  s    z,IgnoreEnvironmentTest.test_sys_flags_not_setN)rÕ   rÖ   r×   rÛ   rÜ   rÝ   rÞ   r   r   r   r   rÚ   Ê  s   rÚ   c               C   s   t  tt¡ t  ¡  d S )N)r   Zrun_unittestr   rÚ   Zreap_childrenr   r   r   r   Ú	test_mainî  s    rß   Ú__main__)rW   r*   r"   Z	sysconfigrt   rØ   Ztestr   Ztest.support.script_helperr   r   r   r   r   Úhasattrr?   r   ZTestCaser   rÙ   rÚ   rß   rÕ   r   r   r   r   Ú<module>   s*   
     3
"