Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_traceback.cpython-34.pyo

�
g fGG�@sqdZddlmZddlZddlZddlZddlmZmZm	Z	ddlm
Z
mZmZddl
Z
Gdd�dej�ZGdd	�d	ej�Zd
ZdZejdeje�eje�f�ZGd
d�d�ZGdd�deej�ZGdd�deej�ZGdd�dej�Zdd�Zedkrme�ndS)zTest cases for traceback module�)�StringION)�run_unittest�Error�captured_output)�TESTFN�unlink�cpython_onlyc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�SyntaxTracebackCasescCsSy|�Wn5|k
rB}ztj||�SWYdd}~Xn
Xtd��dS)Nzcall did not raise exception)�	traceback�format_exception_only�
ValueError)�self�func�exc�value�r�8/opt/alt/python34/lib64/python3.4/test/test_traceback.py�get_exception_formats
#z)SyntaxTracebackCases.get_exception_formatcCstddd�dS)Nzdef fact(x):
	return x!
�?�exec)�compile)r
rrr�syntax_error_with_caretsz,SyntaxTracebackCases.syntax_error_with_caretcCstddd�dS)Nz1 +
rr)r)r
rrr�syntax_error_with_caret_2sz.SyntaxTracebackCases.syntax_error_with_caret_2cCstddd�dS)Nz def spam():
  print(1)
 print(2)rr)r)r
rrr�syntax_error_bad_indentationsz1SyntaxTracebackCases.syntax_error_bad_indentationcCstddd�dS)NuPython = "Ṕýţĥòñ" +rr)r)r
rrr�!syntax_error_with_caret_non_ascii"sz6SyntaxTracebackCases.syntax_error_with_caret_non_asciicCstddd�dS)Nz	 print(2)rr)r)r
rrr�syntax_error_bad_indentation2%sz2SyntaxTracebackCases.syntax_error_bad_indentation2cCsj|j|jt�}|jt|�d�|j|dj�dk�|jd|d�|j|djd�|djd��|j|j	t�}|jd|d�|j|dj
d�d�|j|djd�|djd��|j|jt�}|jd|d�|j|dj
d�d�|j|djd�|djd��dS)	N��z	return x!�^��!�
�+)rr�SyntaxError�assertEqual�len�
assertTrue�strip�assertIn�findr�countr)r
�errrrr�
test_caret(s 	*	*	zSyntaxTracebackCases.test_caretcCsUtdd�}tjt|�}|jt|�d�|j|dj�d�dS)N�error�x.py��
bad syntax�r)r.r/Nr0)r#r
rr$r%r')r
rr+rrr�test_nocaret<sz!SyntaxTracebackCases.test_nocaretcCs
|j|jt�}|jt|�d�|j|dj�d�|jd|d�|j|djd�|djd��|j|jt�}|jt|�d�|j|dj�d�|jd|d�|j|djd�|djd��dS)Nrrzprint(2)rr�)�p)	rr�IndentationErrorr$r%r'r(r)r)r
r+rrr�test_bad_indentationBs	*	z)SyntaxTracebackCases.test_bad_indentationcCs5t�}tj|j|�}|j|dg�dS)NzKeyboardInterrupt
)�KeyboardInterruptr
r�	__class__r$)r
�eZlstrrr�test_base_exceptionQs	z(SyntaxTracebackCases.test_base_exceptioncCs�Gdd�dt�}tj||��}|jt|�d�d|j}|jd
kri|j}ndj|j|jg�}|j|dd	||f�dS)Nc@seZdZdd�ZdS)zESyntaxTracebackCases.test_format_exception_only_bad__str__.<locals>.XcSsdddS)Nrrr)r
rrr�__str__YszMSyntaxTracebackCases.test_format_exception_only_bad__str__.<locals>.X.__str__N)�__name__�
__module__�__qualname__r;rrrr�XXsr?rz<unprintable %s object>�__main__�builtins�.rz%s: %s
)z__main__zbuiltins)�	Exceptionr
rr$r%r<r=�join)r
r?r+Z	str_valueZstr_namerrr�%test_format_exception_only_bad__str__Ws
z:SyntaxTracebackCases.test_format_exception_only_bad__str__cCs)tjdd�}|j|dg�dS)NzNone
)r
rr$)r
r+rrr�test_without_exceptiondsz+SyntaxTracebackCases.test_without_exceptionc	sbddl}ddl�ddl�ddl}�j�jddgd�jd�j�}|j�\}}t	|d�j
�d�����fdd�}|d	d
dd�x�dD]�}|dkr�d
}n|dkr�d}nd}|dj|�||d�|dj|�||d�|dj|�||d�q�W|ddd
d�dS)Nrz-cz&import sys; print(sys.stdout.encoding)�stdout�stderr�asciics`z�ttdd|�}|jdj||��|j��j�jtgd�jd�j�}|j	�\}}|j
��j�}Wdtt�X|j
�d�}|j
��}	dj|	�}
dj|	�}�jd	||d
dj|d
|���j|dj|
�d
j|d|
���j|d|kdj|d|��dS)N�w�encodingzq{0}if 1:
                    import traceback;
                    raise RuntimeError('{1}')
                    rGrH�backslashreplacezraise RuntimeError('{0}')zRuntimeError: {0}zline %srz)Invalid line number: {0!r} instead of {1}rz.Invalid traceback line: {0!r} instead of {1!r}r1z-Invalid error message: {0!r} instead of {1!r})�openr�write�format�close�Popen�
executable�PIPE�STDOUT�communicate�decode�
splitlinesr�encoder(r&�endswith)Z
firstlines�message�charset�lineno�output�processrGrHZencoded_messageZ
message_asciiZerr_lineZerr_msg)�output_encodingr
�
subprocess�sysrr�do_testxs0
		z7SyntaxTracebackCases.test_encoded_file.<locals>.do_test�Zfoor1�
iso-8859-1�utf-8�GBKu丂儀uhé hoz# coding: {0}
rz#!shebang
# coding: {0}
�z 	
# coding: {0}
z0
# coding: GBK
)zasciirdrerf)�tempfilerar`�osrQrRrSrTrU�strrWrO)	r
rhrir^rGrHrbr[�textr)r_r
r`rar�test_encoded_filehs,0		#
		

z&SyntaxTracebackCases.test_encoded_fileN)r<r=r>rrrrrrr,r2r6r:rErFrlrrrrr	
s
r	c@smeZdZdd�Zeddd��Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�TracebackFormatTestscCstd��dS)NZblah)�KeyError)r
rrr�some_exception�sz#TracebackFormatTests.some_exceptionNcCsddlm}y|j�Wntk
r#tj�\}}}|dk	r_||j�nddjtj	|��}t
�}|||�|j�}td��}	tj
|�WdQXt
�}
tj
|d|
�td��}tj�WdQXtj�}t
�}
tjd|
�Yn
Xtd��|j||�|j|	j�|
j��|j|j�|
j��|j||
j��|j�}|jt|�d�|d}|d
d�\}}|j|jd
��|j|jd��|j|jd��dS)Nr)�traceback_printz#Traceback (most recent call last):
rcrH�filez&unable to create test traceback stringrgr�	Tracebackz  Filez	    raise���)�	_testcapirprornra�exc_info�tb_nextrDr
�	format_tbr�getvaluer�print_tb�	print_exc�
format_excrr$rWr%r&�
startswith)r
Zcleanup_funcrp�type_r�tbZ
traceback_fmtZfile_Z
python_fmtZtbstderrZtbfileZ	excstderrZexcfmtZexcfileZtb_linesZbanner�locationZsource_linerrr�check_traceback_format�sB
	
		
z+TracebackFormatTests.check_traceback_formatcCs|j�dS)N)r�)r
rrr�test_traceback_format�sz*TracebackFormatTests.test_traceback_formatcCsdd�}|j|�dS)NcSs|jj�dS)N)�tb_frame�clear)r~rrr�
cleanup_tb�szRTracebackFormatTests.test_traceback_format_with_cleared_frames.<locals>.cleanup_tb)r�)r
r�rrr�)test_traceback_format_with_cleared_frames�sz>TracebackFormatTests.test_traceback_format_with_cleared_framesc
Cs�td��}tjtjd��WdQXt�}tjtjd�d|�|j|j�|j��tjtjd��}|j|j�dj	|��dS)NrHrrqrc)
rr
�print_stackra�	_getframerr$rx�format_stackrD)r
ZststderrZstfileZstfmtrrr�test_stack_format�s	z&TracebackFormatTests.test_stack_formatcCs�dd�}td��}|�WdQX|jj}|j|j�j�dd�dt|dfddt|d	fd
g�dS)NcSstj�dS)N)r
r�rrrr�prn�sz2TracebackFormatTests.test_print_stack.<locals>.prnrHrz)  File "%s", line %d, in test_print_stackr1z	    prn()z  File "%s", line %d, in prnrz    traceback.print_stack()���)r�__code__�co_firstlinenor$rxrW�__file__)r
r�rHr\rrr�test_print_stack�s
z%TracebackFormatTests.test_print_stackcCsadd�}|�}|jj}|j|dd�dt|dfdt|dfg�dS)NcSs
tj�S)N)r
r�rrrr�fmtsz3TracebackFormatTests.test_format_stack.<locals>.fmtrz>  File "%s", line %d, in test_format_stack
    result = fmt()
zA  File "%s", line %d, in fmt
    return traceback.format_stack()
rrs)r�r�r$r�)r
r��resultr\rrr�test_format_stacks	z&TracebackFormatTests.test_format_stack)r<r=r>rorr�r�r�r�r�r�rrrrrm�s,

rmzG
The above exception was the direct cause of the following exception:

zF
During handling of the above exception, another exception occurred:

z(%s|%s)c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�BaseExceptionReportingTestscCsNt|t�r|Sy|�Wn)tk
rI}z	|SWYdd}~XnXdS)N)�
isinstancerC)r
Zexception_or_callabler9rrr�
get_exceptionsz)BaseExceptionReportingTests.get_exceptioncCsdddS)Nrrr)r
rrr�zero_div%sz$BaseExceptionReportingTests.zero_divcCs_|j�}|j|djd��|jd|d�|j|d	jd�|d
�dS)Nr1z  Filez1/0 # In zero_divrr�ZeroDivisionError���rs���r�)rWr&r|r()r
�msg�linesrrr�check_zero_div(sz*BaseExceptionReportingTests.check_zero_divcCs�yddWn+tk
r9}z|}WYdd}~XnX|j|�j�}|jt|�d�|j|djd��|j|djd��|jd|d�|j|djd	��dS)
Nrrrrrz  Filez1/0 # Markerrr1r�)r��
get_reportrWr$r%r&r|r()r
�_r9r�rrr�test_simple.sz'BaseExceptionReportingTests.test_simplecs��fdd���fdd�}tj�j|��}�jt|�d��j|dt��j|d��jd|d	�dS)
NcsCy�j�Wn.tk
r>}zt|�WYdd}~XnXdS)N)r�r�rn)r9)r
rr�inner_raise;sz;BaseExceptionReportingTests.test_cause.<locals>.inner_raisecs��dS)Nrr)r�rr�outer_raise@sz;BaseExceptionReportingTests.test_cause.<locals>.outer_raiser1rrzinner_raise() # Markerr)�
boundaries�splitr�r$r%�
cause_messager�r()r
r��blocksr)r�r
r�
test_cause:sz&BaseExceptionReportingTests.test_causecs��fdd���fdd�}tj�j|��}�jt|�d��j|dt��j|d��jd|d	�dS)
Ncs-y�j�Wntk
r(t�YnXdS)N)r�r�rnr)r
rrr�Is
z=BaseExceptionReportingTests.test_context.<locals>.inner_raisecs��dS)Nrr)r�rrr�Nsz=BaseExceptionReportingTests.test_context.<locals>.outer_raiser1rrzinner_raise() # Markerr)r�r�r�r$r%�context_messager�r()r
r�r�r)r�r
r�test_contextHsz(BaseExceptionReportingTests.test_contextcCs�y"y
t�Wntd�YnXWn+tk
rO}z|}WYdd}~XnX|j|�j�}|jt|�d�|j|djd��|j|djd��|jd|d�|j|djd	��dS)
Nrrrrrz  FilezZeroDivisionError from Nonerr1r�)	rCr�r�rWr$r%r&r|r()r
r�r9r�rrr�test_context_suppressionVs
z4BaseExceptionReportingTests.test_context_suppressioncs��fdd���fdd�}tj�j|��}�jt|�d��j|dt��j|d��jd|d	�dS)
Ncsfy�j�Wn+tk
r;}z|}WYdd}~XnXytWntk
rat|�YnXdS)N)r�r�Zxyzzy�	NameErrorrn)Z_er9)r
rrr�hs
zGBaseExceptionReportingTests.test_cause_and_context.<locals>.inner_raisecs��dS)Nrr)r�rrr�qszGBaseExceptionReportingTests.test_cause_and_context.<locals>.outer_raiser1rrzinner_raise() # Markerr)r�r�r�r$r%r�r�r()r
r�r�r)r�r
r�test_cause_and_contextes	z2BaseExceptionReportingTests.test_cause_and_contextcs��fdd���fdd�}tj�j|��}�jt|�d��j|dt��jd|d��jd	|d��jd
|d��j|d�dS)Ncs~yIy�j�Wn4tk
rG}z|}t|�WYdd}~XnXWn.tk
ry}z||�WYdd}~XnXdS)N)r�r�rn)r9�z)r
rrr�zs zEBaseExceptionReportingTests.test_cause_recursive.<locals>.inner_raisecs��dS)Nrr)r�rrr��szEBaseExceptionReportingTests.test_cause_recursive.<locals>.outer_raiser1rzraise KeyError from erz1/0zinner_raise() # Markerr)	r�r�r�r$r%r�r(ZassertNotInr�)r
r�r�r)r�r
r�test_cause_recursiveys	z0BaseExceptionReportingTests.test_cause_recursivecCsndd�}|j|�j�}|j|dd�dd�}|j|�j�}|j|dd�dS)	NcSstdd��dS)Nrcrrg�hello)rcrrgr�)r#rrrrr9�szFBaseExceptionReportingTests.test_syntax_error_offset_at_eol.<locals>.erz	        ^cSstd�dS)Nzx = 5 | 4 |)rrrrrr9�sz              ^rsrs)r�rWr$)r
r9r�rrr�test_syntax_error_offset_at_eol�sz;BaseExceptionReportingTests.test_syntax_error_offset_at_eolN)
r<r=r>r�r�r�r�r�r�r�r�r�r�rrrrr�sr�c@seZdZdd�ZdS)�PyExcReportingTestscCs�|j|�}djtjt|�||j��}td��#}tjt|�||j�WdQX|j|j	�|�|S)NrcrH)
r�rDr
�format_exception�type�
__traceback__r�print_exceptionr$rx)r
r9�sZsiorrrr��s!"zPyExcReportingTests.get_reportN)r<r=r>r�rrrrr��sr�c@s"eZdZedd��ZdS)�CExcReportingTestsc	CsHddlm}|j|�}td��}||�WdQX|j�S)Nr)�exception_printrH)rtr�r�rrx)r
r9r�r�rrrr��s
zCExcReportingTests.get_reportN)r<r=r>rr�rrrrr��sr�c@s(eZdZdd�Zdd�ZdS)�MiscTracebackCasesc	s��fdd�}�fdd��dd��y|�Wntj�\}}}YnX|jjjj}|jt|j�d�tj|�|jt|j�d�dS)	Ncs��dS)Nrr)�middlerr�outer�sz,MiscTracebackCases.test_clear.<locals>.outercs��dS)Nrr)�innerrrr��sz-MiscTracebackCases.test_clear.<locals>.middlecSsd}dddS)Nrrr)�irrrr��sz,MiscTracebackCases.test_clear.<locals>.innerrr)	rarurvr�r$r%�f_localsr
�clear_frames)r
r�r}rr~Zinner_framer)r�r�r�
test_clear�s
zMiscTracebackCases.test_clearcCsedd�}|�}|jj}|j|d	d�t|dddft|dddfg�dS)
NcSs
tj�S)N)r
�
extract_stackrrrr�extract�sz6MiscTracebackCases.test_extract_stack.<locals>.extractr�test_extract_stackzresult = extract()rr�z return traceback.extract_stack()rs)r�r�r$r�)r
r�r�r\rrrr��s	z%MiscTracebackCases.test_extract_stackN)r<r=r>r�r�rrrrr��sr�cCstt�dS)N)rr<rrrr�	test_main�sr�r@)�__doc__�iorraZunittest�reZtest.supportrrrrrrr
ZTestCaser	rmr�r�r�escaper�r�r�r�r�r�r<rrrr�<module>s(�c%�(