Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_cmd_line.cpython-35.opt-2.pyc



���]P�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
dd�ZGdd�dej�Zdd	�Zed
kr�e�dS)�N)�
script_helper)�spawn_python�kill_python�assert_python_ok�assert_python_failurecCs"t|�}|j�}||fS)N)r�wait)�p�data�
returncode�r�2/opt/alt/python35/lib64/python3.5/test_cmd_line.py�_kill_python_and_exit_codesr
c@sAeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zejejjd�dd��Zejejdkd�dd��Zejejd kd!�d"d#��Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#d8d9�Z$d:d;�Z%eje&j'd<kd=�d>d?��Z(d@dA�Z)dBdC�Z*dDdE�Z+dFdG�Z,dHdI�Z-dJdK�Z.dLdM�Z/eje0j1�dN�dOdP��Z2dQS)R�CmdLineTestcCstd�td�dS)N�.z< .)r)�selfrrr�test_directoriess
zCmdLineTest.test_directoriescCs[t|�\}}}|j|dkp3|jd��|jd|�|jd|�dS)N�s
s	Traceback)r�
assertTrue�endswith�assertNotIn)rZcmd_line�rc�out�errrrr�verify_valid_flags"zCmdLineTest.verify_valid_flagcCs|jd�|jd�dS)Nz-Oz-OO)r)rrrr�
test_optimize!s
zCmdLineTest.test_optimizecCs|jd�dS)Nz-S)r)rrrr�test_site_flag%szCmdLineTest.test_site_flagcCs)td�\}}}|jd|�dS)Nz-hsusage)r�assertIn)rrrrrrr�
test_usage(szCmdLineTest.test_usagecCsvdtjdd�jd�}xOdD]G}t|�\}}}|j|j|��|j|j|��q'WdS)NzPython %d.%d��ascii�-V�	--version)r r!)�sys�version_info�encoderZassertFalse�
startswithr)r�versionZswitchrrrrrr�test_version,s
 
zCmdLineTest.test_versioncCsNtd�\}}}|jd|�td�\}}}|jd|�dS)Nz-vsstack overflowz-vv)rr)rrrrrrr�test_verbose3szCmdLineTest.test_verbosecCsTdd�}|�}|j|i�|dd�}|j|ddddi�dS)	NcWsFtjdf|}|d7}tj|�}t|j�d�}|S)Nz-E�-c� import sys; print(sys._xoptions)r)r)r*)r"�
executable�
subprocess�check_output�eval�
splitlines)�argsr�optsrrr�get_xoptions=s

z/CmdLineTest.test_xoptions.<locals>.get_xoptionsz-Xaz	-Xb=c,d=e�aT�bzc,d=e)�assertEqual)rr2r1rrr�
test_xoptions<s
		zCmdLineTest.test_xoptionscs��fdd�}d}|d|�\}}}�j|j�d��j|d�|ddd|�\}}}�j|j�d	�ttd
�r��j|d�n�j|d�dS)Ncs�tjg}|j|�tj}tj|d|d|�}|j�\}}|jj�|j	j�|j
}�j|d�|||fS)N�stdout�stderrr)r"r+�extendr,�PIPE�Popen�communicater7�closer8r
r5)r0�cmdr:rrrr)rrr�
run_pythonMs
	

	z1CmdLineTest.test_showrefcount.<locals>.run_pythonz import sys; print(sys._xoptions)z-cs{}rz-XZshowrefcounts{'showrefcount': True}�gettotalrefcounts^\[\d+ refs, \d+ blocks\])r5�rstrip�hasattrr"�assertRegex)rr?�coderrrr)rr�test_showrefcountLszCmdLineTest.test_showrefcountcCs>td�tdd�tddd�tdddd�dS)Nz-mZ
fnord43520xyzZrunpy�timeitz-n�1)rr)rrrr�test_run_modulehs

zCmdLineTest.test_run_modulecCs�tddddd�}|jjd�|jjd�t|�}|j|jd�dk�|j|jd
�dk�dS)
Nz-iz-mrFz-nrGsTimer
sexit()
s1 loop�s__main__.Timer���rJ)r�stdin�writerr�find)rrr	rrr�test_run_module_bug1764407tsz&CmdLineTest.test_run_module_bug1764407cCs(td�tdd�tdd�dS)Nz-czraise Exception�pass)rr)rrrr�
test_run_codes

zCmdLineTest.test_run_codezneed support.FS_NONASCIIcCs3dtjjttjj�f}td|�dS)Nzassert(ord(%r) == %s)z-c)�test�support�FS_NONASCII�ordr)rZcommandrrr�test_non_ascii�szCmdLineTest.test_non_ascii�win32z Windows has a native unicode APIcCs�d}tjj�}d|d<d|d}tjtjd|gdtjdtjd	|�}|j	�\}}|j
d
kr�d}n1|j
dkr�d
}ntd|j
|f��|j|�s�td||f��dS)Ns��C�LC_ALLsimport locale; print(ascii("s""), locale.getpreferredencoding())z-cr7r8�envrIs3Unable to decode the command from the command line:rs'\xff' z Unknown exit code: %s, output=%az%a doesn't start with %a)
�os�environ�copyr,r;r"r+r:�STDOUTr<r
�AssertionErrorr%)rZundecodablerYrDrr7r8�patternrrr�test_undecodable_code�s 
			z!CmdLineTest.test_undecodable_code�darwinztest specific to Mac OS Xcs?�fdd�}djd�}||�d}||�dS)Ncs�|jdd�}t|�jd�d}tjj�}d|d<tjtj	dd|fd	tj
d
|�}|j�\}}�j||��j|j
d�dS)Nzutf-8�surrogateescapers
rWrXz-cz%import sys; print(ascii(sys.argv[1]))r7rYr)�decoderr$rZr[r\r,r;r"r+r:r<r5r
)�textZdecoded�expectedrYrr7r8)rrrr-�s
		z/CmdLineTest.test_osx_utf8.<locals>.check_outputue:é, euro:€, non-bmp:􏿿zutf-8s�é��)r$)rr-rdr)rr�
test_osx_utf8�s

zCmdLineTest.test_osx_utf8cCs�x�d
D]�}d|}tdd|�\}}}|dkrD|n|}|j|dd|�d|}tdd|�\}}}|dkr�|n|}|j|j�dd	|�qWdS)Nr7r8z6import os, sys; sys.%s.buffer.write(b'x'); os._exit(0)z-uz-c�xzbinary %s not unbufferedz0import os, sys; sys.%s.write('x\n'); os._exit(0)ztext %s not line-buffered)r7r8)rr5�strip)r�streamrDrrrr	rrr�test_unbuffered_output�s
z"CmdLineTest.test_unbuffered_outputcCstd}tdd|�}|jjd�|jj�t|�\}}|j|d�|j|jd�|�dS)Nz/import sys; sys.stdout.write(sys.stdin.read(1))z-uz-crgr)rrKrL�flushr
r5rr%)rrDrr	rrrr�test_unbuffered_input�s
z!CmdLineTest.test_unbuffered_inputcCs�dd}dd}|tj|}d}tdd|d|�\}}}|j|jd�|�|j|jd�|�dS)	NZABCDE�dZFGHIJz�if 1:
            import sys
            path = ":".join(sys.path)
            path = path.encode("ascii", "backslashreplace")
            sys.stdout.buffer.write(path)z-Sz-c�
PYTHONPATHr)rZ�pathseprrr$)rZpath1Zpath2�pathrDrrrrrr�test_large_PYTHONPATH�s

z!CmdLineTest.test_large_PYTHONPATHcCsVd}td|dd�\}}}td|dd�\}}}|j||�dS)Nz�if 1:
            import sys
            path = ":".join(sys.path)
            path = path.encode("ascii", "backslashreplace")
            sys.stdout.buffer.write(path)z-crn�Z
__isolatedF)rr5)rrDZrc1Zout1Zerr1Zrc2Zout2Zerr2rrr� test_empty_PYTHONPATH_issue16309�s
z,CmdLineTest.test_empty_PYTHONPATH_issue16309cCs�x�dD]�}dd�tjj�j�D�}||d<tjtjdgdtjd	tjd
tj	d|�}d}|j
jt|�j
d�d
�|j
jd�t|�}t|�j
|d�}|j||�qWdS)Nr�latin-1�utf-8cSs.i|]$\}}|jd�s||�qS)�PYTHON)r%)�.0�key�valuerrr�
<dictcomp>s		z<CmdLineTest.test_displayhook_unencodable.<locals>.<dictcomp>ZPYTHONIOENCODINGz-irKr7r8rYua=é b=� c=𐀀 d=􏿿s
sexit()
�backslashreplace)rrtru)rZr[r\�itemsr,r;r"r+r:r]rKrLrr$r�reprr)r�encodingrYrrdr	�escapedrrr�test_displayhook_unencodables
"
				#z(CmdLineTest.test_displayhook_unencodablecCs�tjd���}tjjd�}|j|jd	��|j�|jd�t	j
tjd|fd|dt	j
��}|j�\}}WdQRXWdQRX|j|j�|�dS)
Nzwb+�ASCII�abc�defrz-crKr7)r�r�)�tempfile�NamedTemporaryFilerZ�linesepr$rL�joinrk�seekr,r;r"r+r:r<r5rA)rrDrerK�sep�procr7r8rrr�check_input&s

 zCmdLineTest.check_inputcCs|jdd�dS)Nz-import sys; print(repr(sys.stdin.readline()))s'abc\n')r�)rrrr�test_stdin_readline2szCmdLineTest.test_stdin_readlinecCs|jdd�dS)Nzprint(repr(input()))s'abc')r�)rrrr�test_builtin_input9szCmdLineTest.test_builtin_inputcCstd}td|�\}}}tjdkrP|jd|�|jd|�n |jd|�|jd|�dS)Nz�if 1:
            import sys
            print(1)
            print(2)
            print(3, file=sys.stderr)
            print(4, file=sys.stderr)z-crVs1
2
s3
4s1
2
s3
4)rr"�platformr5)rrDrrrrrr�test_output_newline?szCmdLineTest.test_output_newlinecCsHtdd�\}}}|j|jdd�d�|jd|�dS)Nz-c�'r�ignore�SyntaxErrorr)rrCrcr5)rrrrrrr�test_unmached_quotePszCmdLineTest.test_unmached_quotecCsNd}td|�\}}}|jd|�|j|jdd�d�dS)Nz�if 1:
            import os, sys, test.support
            test.support.SuppressCrashReport().__enter__()
            sys.stdout.write('x')
            os.close(sys.stdout.fileno())z-crrr�z"Exception ignored in.*
OSError: .*)rr5rCrc)rrDrrrrrr�test_stdout_flush_at_shutdownWs
z)CmdLineTest.test_stdout_flush_at_shutdowncCs2d}td|�\}}}|jd|�dS)Nzimport sys; sys.stdout.close()z-cr)rr5)rrDrrrrrr�test_closed_stdoutdszCmdLineTest.test_closed_stdout�posixztest needs POSIX semanticsc
s�djd��}�fdd�}tjtjdd|gdtjdtjd	tjd
|�}|j�\}}|jtj	j
|�d�|j|jd�dS)
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)�streamscsOd�krtjd�d�kr2tjd�d�krKtjd�dS)NrKrr7rIr8r)rZr=r)r�rr�preexecus

z+CmdLineTest._test_no_stdio.<locals>.preexecz-Ez-crKr7r8�
preexec_fnr�*)�formatr,r;r"r+r:r<r5rQrRZstrip_python_stderrr
)rr�rDr�rrrr)r�r�_test_no_stdioms				zCmdLineTest._test_no_stdiocCs|jdg�dS)NrK)r�)rrrr�
test_no_stdin�szCmdLineTest.test_no_stdincCs|jdg�dS)Nr7)r�)rrrr�test_no_stdout�szCmdLineTest.test_no_stdoutcCs|jdg�dS)Nr8)r�)rrrr�test_no_stderr�szCmdLineTest.test_no_stderrcCs|jdddg�dS)NrKr7r8)r�)rrrr�test_no_std_streams�szCmdLineTest.test_no_std_streamscCs%|jd�g}tjjdd�dkrQttj�}|d=d|d<ni}xRtd�D]D}d}td||�\}}}|j|d	�|j|�qdWt	t
|��}|jt|�d
ddj
|��d
}td|�\}}}|j|d	�|jd|�dS)Nz-RZPYTHONHASHSEED�randomrGZ
__cleanenv�zprint(hash("spam"))z-crrI�msgz83 runs produced an identical random hash  for "spam": {}z<import sys; print("random is", sys.flags.hash_randomization)srandom is 1)rrZr[�get�dict�rangerr5�append�sorted�setZ
assertGreater�lenr�r)rZhashesrY�irDrrrrrr�test_hash_randomization�s(


z#CmdLineTest.test_hash_randomizationcCsitjj}|jtjj|�t|d��'}tdd|�tdd|�WdQRXt|�dS)N�wz
import sys�filezdel sys.modules['__main__'])rQrRZTESTFNZ
addCleanup�unlink�open�printr)r�filenameZscriptrrr�test_del___main__�szCmdLineTest.test_del___main__cCs"tdd�\}}}|jd|�|j|j�jd�d�|jd|�tddd�\}}}|jd|�|j|j�jd�d�|jd|�tdddd�\}}}|jd|�|jd|�|j|j�jd�d�|jd|�dS)	Nz-Ez-zsUnknown option: -zrIrZwithoutz-asUnknown option: -a)rrr5r/�countr)rrrrrrr�test_unknown_options�sz CmdLineTest.test_unknown_optionsz6Cannot run -I tests when PYTHON env vars are required.cCsY|jd�|jd�tddddd�\}}}|j|j�d�tjj���}tjj	|d�}tjj	|d	�}t
|d
��}|jd�WdQRXt
|d
��!}|jd�|jd
�WdQRX|jt
jt
jtj|gd|dt
j�t
jtjd|gd|�}|j|j�d�WdQRXdS)Nz-Iz-IEsz-czSfrom sys import flags as f; print(f.no_user_site, f.ignore_environment, f.isolated)Zdummyvarrrs1 1 1zuuid.pyzmain.pyr�z)raise RuntimeError('isolated mode test')
zimport uuid
zprint('ok')
�cwdr8sok)rrr5rhrQrRZtemp_cwdrZrpr�r�rLZassertRaisesr,�CalledProcessErrorr-r"r+�DEVNULL)rrrrZtmpdirZfake�main�frrr�test_isolatedmode�s*

	

	zCmdLineTest.test_isolatedmodeN)3�__name__�
__module__�__qualname__rrrrrr'r(r6rErHrNrP�unittestZ
skipUnlessrQrRrSrUZskipIfr"r�r`rfrjrlrqrsr�r�r�r�r�r�r�r�rZ�namer�r�r�r�r�r�r�r�rZ interpreter_requires_environmentr�rrrrrsL		$!' 

	'rcCs!tjjt�tjj�dS)N)rQrRZrun_unittestrZ
reap_childrenrrrr�	test_main�sr��__main__)Ztest.supportrQr�rZ�shutilr"r,r�rZtest.support.script_helperrrrrr
ZTestCaserr�r�rrrr�<module>s"��