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_code_module.cpython-35.opt-1.pyc



��Yf��@s�dZddlZddlZddlmZddlmZddlmZddlm	Z	e	j
d�ZGdd	�d	ej�Z
ed
kr�ej�dS)zCTest InteractiveConsole and InteractiveInterpreter from code module�N)�dedent)�	ExitStack)�mock)�support�codec@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestInteractiveConsolecCstj�|_|j�dS)N)rZInteractiveConsole�console�mock_sys)�self�r�:/opt/alt/python35/lib64/python3.5/test/test_code_module.py�setUpszTestInteractiveConsole.setUpcCs�t�}|j|j�|jtjddd��|_|jtjd��|_|jtjd��|_tjddt	j
dt	j
�}|j|�|_t
jt
j
kr�|jj
|j_d	S)
z.Mock system environment for InteractiveConsolez
code.inputZcreateTzcode.sys.stdoutzcode.sys.stderrzcode.sys�wraps�specN)rZ
addCleanup�close�
enter_contextrZpatch�infunc�stdout�stderrr�sys�sysmod�
excepthook�__excepthook__)r
�stackZprepatchrrrr	s	!zTestInteractiveConsole.mock_syscCs9td�|j_|jj�|j|jjd�dS)N�Finishedz>>> )�EOFErrorr�side_effectr�interact�assertEqualrZps1)r
rrr�test_ps1 s
zTestInteractiveConsole.test_ps1cCs9td�|j_|jj�|j|jjd�dS)Nrz... )rrrrrrrZps2)r
rrr�test_ps2%s
zTestInteractiveConsole.test_ps2cCsoddtd�g|j_|jj�x@t|jj�D] }ddj|d�kr;Pq;Wt	d��dS)Nz	'antioch'�rZantioch�zno console stdout)
rrrrr�listr�method_calls�join�AssertionError)r
�callrrr�test_console_stderr*s
z*TestInteractiveConsole.test_console_stderrcCsfdtd�g|j_|jj�x:|jjD] }ddj|d�kr2Pq2Wtd��dS)NZ	undefinedr�	NameErrorr!r"zNo syntax error from console)	rrrrrrr$r%r&)r
r'rrr�test_syntax_error3s
z(TestInteractiveConsole.test_syntax_errorcCsQdtd�g|j_tj�}||j_|jj�|j	|j
�dS)Nzraise ValueError('')r)rrrrZMockrrrrZ
assertTrueZcalled)r
�hookrrr�test_sysexcepthook<s
z)TestInteractiveConsole.test_sysexcepthookcCs�td�|j_|jjdd�|jt|jj�d�|jjd}|j|dd
ig�|jj	�td�|j_|jjdd�|jt|jj�d	�dS)NrZbannerZFoo�r�write�Foo
r!r")r/)
rrrrrr�lenrr$Z
reset_mock)r
Zbanner_callrrr�test_bannerDs
z"TestInteractiveConsole.test_bannercCsgdtd�g|j_|jj�djdd�|jjD��}td�}|j	||�dS)Nz(raise ValueError('') from AttributeErrorrr!css"|]}dj|d�VqdS)r!r"N)r%)�.0r'rrr�	<genexpr>Vsz7TestInteractiveConsole.test_cause_tb.<locals>.<genexpr>z�
        AttributeError

        The above exception was the direct cause of the following exception:

        Traceback (most recent call last):
          File "<console>", line 1, in <module>
        ValueError
        )
rrrrrr%rr$r�assertIn)r
�output�expectedrrr�
test_cause_tbRs
"	z$TestInteractiveConsole.test_cause_tbcCsgdtd�g|j_|jj�djdd�|jjD��}td�}|j	||�dS)Nztry: ham
except: eggs
rr!css"|]}dj|d�VqdS)r!r"N)r%)r2r'rrrr3fsz9TestInteractiveConsole.test_context_tb.<locals>.<genexpr>ah
        Traceback (most recent call last):
          File "<console>", line 1, in <module>
        NameError: name 'ham' is not defined

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "<console>", line 2, in <module>
        NameError: name 'eggs' is not defined
        )
rrrrrr%rr$rr4)r
r5r6rrr�test_context_tbbs
"
	z&TestInteractiveConsole.test_context_tbN)
�__name__�
__module__�__qualname__r
r	rr r(r*r,r1r7r8rrrrrs		r�__main__)�__doc__rZunittest�textwrapr�
contextlibrrZtestr�
import_modulerZTestCaserr9�mainrrrr�<module>si