Your IP : 216.73.217.129


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



���]ڡ�@s(ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZGdd�de�ZGdd�de�ZGdd�de�ZGd	d
�d
ej�ZGdd�dej�Zed
kr$ej�dS)�N)
�TESTFN�captured_stderr�check_impl_detail�check_warnings�cpython_only�
gc_collect�run_unittest�
no_tracing�unlink�
import_modulec@seZdZdd�ZdS)�NaiveExceptioncCs
||_dS)N)�x)�selfr
�r�4/opt/alt/python35/lib64/python3.5/test_exceptions.py�__init__szNaiveException.__init__N)�__name__�
__module__�__qualname__rrrrrrsrc@s"eZdZdZdd�ZdS)�SlottedNaiveExceptionr
cCs
||_dS)N)r
)rr
rrrrszSlottedNaiveException.__init__N)r
)rrr�	__slots__rrrrrrsrc@seZdZdd�ZdS)�BrokenStrExceptioncCstd��dS)Nzstr() is broken)�	Exception)rrrr�__str__szBrokenStrException.__str__N)rrrrrrrrrsrc@sYeZdZdd�Zdd�Zdd�Zdd�Zed	d
��Zdd�Z	e
jej
d
kd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zed!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+edIdJ��Z,edKdL��Z-edMdN��Z.edOdP��Z/edQdR��Z0dSdT�Z1dUdV�Z2dWdX�Z3dYS)Z�ExceptionTestscCs�y|d��Wn1|k
rC}zt|�}WYdd}~XnXy|d��Wn1|k
r�}zt|�}WYdd}~XnX|j||�|j|j|�dS)NZspam)�str�assertEqualr)r�exc�excname�errZbuf1Zbuf2rrr�raise_catch szExceptionTests.raise_catchcGCs�|jtd�|jtttd�|jtd�ttd�}|j�ttd�}tj	}z6yddl
}|jd�Wntk
r�YnXWd|t_	|j�tt�X|jt
d�|jt
td	d�|jtd
�|jttd�|jtd�g}|jt|jd
�|jtd�i}|jt|jd�|jtd�|jtd�|jtd�y
t}Wntk
r�YnX|jtd�d}xtd�D]}||7}q�W|jtd�|jtd�|jtd�ytd�Wntk
r7YnX|jtd�|jtd�ytddd�Wntk
r�YnX|j d�|jt!d �|jt"d!�|jt"tj#d�|jt$d"�ygfWnt$k
r�YnX|jt%d#�|jt%t&d)�|jt'd&�ydd}Wnt'k
rJYnX|jt(d'�ydd}Wn%t(k
r�}zWYdd}~XnX|jt)d(�dS)*N�AttributeErrorZundefined_attribute�EOFError�w�rr��OSErrorzthis file does not exist�ImportErrorZundefined_module�
IndexError�
�KeyError�key�KeyboardInterrupt�MemoryError�	NameError�
OverflowError���RuntimeError�RecursionError�SyntaxErrorz/
�IndentationError�TabErrorz"try:
	1/0
    	1/0
finally:
 pass
z<string>�execzTabError not raised�SystemError�
SystemExit�	TypeError�
ValueError���ZeroDivisionErrorr�StopAsyncIterationi)*r r!�assertRaises�getattr�sysr"�openr�close�stdin�marshal�loadsr
r&r'�
__import__r(�__getitem__r*r,r-r.Zundefined_variabler/�ranger2r3r4r7r5r6�compile�failr8r9�exitr:r;�chrr>rr?)r�fpZ	savestdinrFr
�dummy�errr�testRaising,s�
	
		







zExceptionTests.testRaisingcs[�fdd�}d}tjjd�s7||d�d}||d�|dd�dS)	Ncsvyt|dd�WnNtk
rd}z.|j|krR�jd||jf�WYdd}~XnX�jd�dS)Nz
<fragment>r7zexpected %s, got %sz"failed to get expected SyntaxError)rKr4�msgrL)�srcrSrQ)rrr�ckmsg�s-z4ExceptionTests.testSyntaxErrorMessage.<locals>.ckmsgz\while 1:
            try:
                pass
            finally:
                continue�javaz0'continue' not supported inside 'finally' clausezHif 1:
        try:
            continue
        except:
            passz'continue' not properly in loopz	continue
)rB�platform�
startswith)rrU�sr)rr�testSyntaxErrorMessage�s


z%ExceptionTests.testSyntaxErrorMessagecsf�fdd�}|ddd�|ddd�|d	d
d�|ddd�|d
dd�dS)NcsY�jt��}t|dd�WdQRX�j|jj|��j|jj|�dS)Nz
<fragment>r7)r@r4rKr�	exception�lineno�offset)rTr\r]�cm)rrr�check�sz3ExceptionTests.testSyntaxErrorOffset.<locals>.checkzdef fact(x):
	return x!
�r)z1 +
r0�z def spam():
  print(1)
 print(2)�zPython = "Python" +�uPython = "Ṕýţĥòñ" +r)rr_r)rr�testSyntaxErrorOffset�sz$ExceptionTests.testSyntaxErrorOffsetcs�Gdd�dt��Gdd�d����fdd�}��fdd�}��fd	d
�}tjjd�s�|�|�|�dS)Nc@seZdZdd�ZdS)z9ExceptionTests.testSettingException.<locals>.BadExceptioncSstd��dS)Nzcan't instantiate BadException)r2)Zself_rrrr�szBExceptionTests.testSettingException.<locals>.BadException.__init__N)rrrrrrrr�BadException�srec@seZdZdS)z=ExceptionTests.testSettingException.<locals>.InvalidExceptionN)rrrrrrr�InvalidException�srfcs�ddl}y|j�d�Wnrtk
r�}zRtj�\}}}|jj}�j|jd��j	|j
jd��WYdd}~XnX�jd�dS)Nrr0�
test_capi1ztest_exceptions.pyzExpected exception)
�	_testcapi�raise_exceptionr:rB�exc_info�tb_frame�f_coder�co_name�
assertTrue�co_filename�endswithrL)rhrr�tb�co)rerrrrg�s,z7ExceptionTests.testSettingException.<locals>.test_capi1cs�ddl}y|j�d�Wn�tk
r�}zttj�\}}}|jj}�j|jd��j	|j
jd��|jjj}�j|jd�WYdd}~XnX�j
d�dS)Nrrztest_exceptions.py�
test_capi2zExpected exception)rhrir2rBrjrkrlrrmrnrorp�f_backrL)rhrrrqrrZco2)rerrrrs�s&z7ExceptionTests.testSettingException.<locals>.test_capi2cs)ddl}�jt|j�d�dS)Nrr0)rhr@r8ri)rh)rfrrr�
test_capi3�sz7ExceptionTests.testSettingException.<locals>.test_capi3rV)rrBrWrX)rrgrsrur)rerfrr�testSettingException�sz#ExceptionTests.testSettingExceptionc
Cs<ytWntk
rYnX|jtt�|jttd��d�|jttdd��d�tddd�}|j|jd�|j|jd�|jt|�d�td	ddd
�}|j|jd�|j|jd
�|j|jd�|j|j	d�|j|j
d�|jt|�d�td	ddd�}|j|jd
�|j|jd�|j|jd�|j|j	d�|j|j
d�|jt|�d�tdd�}|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�dS)Ni�Z1001�messagez[Errno 1001] message�	�foo�barz[Errno 9] foo: 'bar'rrbr`z[WinError 3] foo: 'bar'�z[WinError 1001] foo)�WindowsErrorr.�assertIsr&rr�errno�winerror�strerror�filename�	filename2)rr#rrr�test_WindowsError�s@
z ExceptionTests.test_WindowsError�win32ztest specific to Windowsc	CsDtd�}d}|jtd|��|jj|�WdQRXdS)N�ctypeslcs�@zWindows Error 0x%x)r�assertRaisesRegexr&Z	pythonapiZPyErr_SetFromWindowsErr)rr��coderrr�test_windows_messagesz#ExceptionTests.test_windows_messagecCstfdfiftd-dd.iftd/dd0iftd1dd2iftd3dd4ddiftd5dd6ddddddddiftd7dd8dddddddd	iftd9dd:dd
dddddd	iftd;dd<dd
ddiftd=dd>dd
ddddiftd?dd@dddd
ddddiftfddddddddddddiftdAddBddddddddddddiftdDddddddFddddddddiftdGddddHddddddddddiftfdfiftdIddJddddddd diftdtd!�dddfddtd!�dddfdddd!ddd diftdKddLdddd!ddd diftdMddNdd"d d#ddd$dift	dOddPd%dift
dQddRd%difg}y>|jtdSddTdd
d&dddddddif�Wnt
k
r�YnXx�|D]�\}}}y||�}Wn(td'||fd(tj��Yq�Xt|�jjd)�s|jt|�jd*�t|�}xT|D]L}t||�}|jt|�t||�d+|||||f�qWx�tgD]�}	x�t|	jd�D]z}
|	j||
�}|	j|�}xP|D]H}tt||��}t||�}
|j||
d,||f�q�Wq�WqxWq�WdS)UN�argsr0ryr�r�r�r~r�rz�baz�quux�errnoStr�strErrorStr�filenameStrrS�textr\r]�print_file_and_line�msgStr�	linenoStr�	offsetStr�textStr�print_file_and_lineStr�ascii�ar�ordinal not in range�encoding�object�start�reason���あ�ouch�endr
rz
exc=%r, args=%r�filer�builtinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s)r0)r0)ry)ry)ryr0)ryr0)ry)ry)ry)ry)ryrz)ryrz)ryrzr�)ryrz)ryrzr�Nr�)ryrz)r�r�r�)r�r�)r0r�r�)r0r�)r�)r��r�r�r�r�)r�r��r�r�r�r�)r�r�)r�r�r�r�r�r�)r�r�r�r�r�r�)r�r�rr0r�)r�r�rr0r�)r�r�rr0r�)r�r�rr0r�)r�rr0r�)r�rr0r�)ry)ry)ry)ry)r0r�r�)r0r�)�
BaseExceptionr9r&r4�UnicodeError�UnicodeEncodeError�UnicodeDecodeError�	bytearray�UnicodeTranslateErrorrr�appendr|r.�printrB�stderr�typerrprrrrA�repr�picklerJ�HIGHEST_PROTOCOL�dumpsrG)rZ
exceptionListrr�ZexpectedrQrYZcheckArgName�value�p�protocol�newZgotZwantrrr�testAttributes
s�



zExceptionTests.testAttributesc
Cs�ytd��Wntj�d}YnXt�j|�}|j|t�|j|j|�td�j|�}|j|t�|j|j|�Gdd�dt�}|�j|�}|j||�|j|j|�dS)Nrar`�c@seZdZdS)z5ExceptionTests.testWithTraceback.<locals>.MyExceptionN)rrrrrrr�MyException�sr�)	r(rBrjr��with_traceback�assertIsInstancer�
__traceback__r)rrqrQr�rrr�testWithTraceback�sz ExceptionTests.testWithTracebackcCs_ydt�_Wn;tk
rM}z|jdt|��WYdd}~XnX|jd�dS)Nr�z!__traceback__ must be a tracebackzNo exception raised)rr�r:�assertInrrL)rrQrrr�testInvalidTraceback�s
)z#ExceptionTests.testInvalidTracebackcCsn|jttt�dd�|jttt�d�|jttt�dd�|jttt�d�dS)N�	__cause__r0�__context__)r@r:�setattrr�delattr)rrrr�testInvalidAttrs�szExceptionTests.testInvalidAttrsc	Cs]ytd��Wntj�d}YnXt�}||_d|_|j|jd�dS)Nrar`)r(rBrjrr�r)rrqrQrrr�testNoneClearsTracebackAttr�s			z*ExceptionTests.testNoneClearsTracebackAttrcCs�t�}|j|j�|j|j�t�}|j|j�|j|j�Gdd�dt�}|�}|j|j�|j|j�dS)Nc@seZdZdS)z5ExceptionTests.testChainingAttrs.<locals>.MyExceptionN)rrrrrrrr��sr�)r�assertIsNoner�r�r:r&)rrQr�rrr�testChainingAttrs�s			z ExceptionTests.testChainingAttrscCs�y
t��Wn+tk
r:}z|}WYdd}~XnX|j|j�|j|j�|j|j�t�|_d|_|j|jt�|j|j�|j|j�d|_|j|j�dS)NF)	rr�r�r�ZassertFalse�__suppress_context__r.r�rn)rrrQrrr�testChainingDescriptors�s
		z&ExceptionTests.testChainingDescriptorscCsR|jttdd�Gdd�dt�}|dd�}|j|jd�dS)Nr�r0c@seZdZdd�ZdS)z8ExceptionTests.testKeywordArgs.<locals>.DerivedExceptioncSstj|�||_dS)N)r�r�	fancy_arg)rr�rrrr�s
zAExceptionTests.testKeywordArgs.<locals>.DerivedException.__init__N)rrrrrrrr�DerivedException�sr�r��*)r@r:r�rr�)rr�r
rrr�testKeywordArgs�szExceptionTests.testKeywordArgscsH�fdd��|jt���fdd��|jt��dS)Ncs��S)Nrr)�frrr��sz/ExceptionTests.testInfiniteRecursion.<locals>.fcs(y��SWntk
r#dSYnXdS)Nr0���)r;r)�grrr��s
z/ExceptionTests.testInfiniteRecursion.<locals>.g)r@r3)rr)r�r�r�testInfiniteRecursion�sz$ExceptionTests.testInfiniteRecursioncCsL|jtt��|jttd���|jttdd���dS)Nr��b)rnrr)rrrr�test_str�szExceptionTests.test_strcCs\y
t��Wn5tk
rD}z|j|�~WYdd}~XnX|jdt��dS)NrQ)rrnZassertNotIn�locals)rrQrrr�testExceptionCleanupNames�s

z(ExceptionTests.testExceptionCleanupNamescIs�Gdd�dt��Gdd�d�}��fdd�}|��tj��}y|�Wn%�k
r�}zWYdd}~XnXd�|��|j�dkd��|��tj��}y|�Wn�k
r�YnXd�|��|j�dkd��|��tj��}y|�WnYnXd�|��|j�dkd��|��tj��}x(dgD]}y|�Wq�PYq�Xq�Wd�|��|j�dkd��|��tj��}y y|�Wnt�YnXWnmtk
r}}zMd|_d�|��td	d
�rQt�|j�dkd��WYdd}~XnX|��tj��}y|�Wn9�k
r�yz�Wd�XWn�k
r�YnXYnXd�td	d
�r�t�|��|j�dkd��Gdd�d�}|��tj��}|��|�WdQRXd�td	d
�r{t�|��|j�dkd��dS)
Nc@seZdZdd�ZdS)z=ExceptionTests.testExceptionCleanupState.<locals>.MyExceptioncSs
||_dS)N)�obj)rr�rrrr
szFExceptionTests.testExceptionCleanupState.<locals>.MyException.__init__N)rrrrrrrrr�	sr�c@seZdZdS)z7ExceptionTests.testExceptionCleanupState.<locals>.MyObjN)rrrrrrr�MyObjsr�cs�}����dS)Nr)Z	local_ref)r�r�rr�inner_raising_funcszDExceptionTests.testExceptionCleanupState.<locals>.inner_raising_funcz%srZcpythonFc@s(eZdZdd�Zdd�ZdS)z9ExceptionTests.testExceptionCleanupState.<locals>.ContextcSs|S)Nr)rrrr�	__enter__kszCExceptionTests.testExceptionCleanupState.<locals>.Context.__enter__cSsdS)NTr)r�exc_type�	exc_value�exc_tbrrr�__exit__mszBExceptionTests.testExceptionCleanupState.<locals>.Context.__exit__N)rrrr�r�rrrr�Contextjsr�)r�weakref�refrnr*r�rr)rr�r��wrrQ�ir�r)r�r�r�testExceptionCleanupStates�			
				
				-	


		
	z(ExceptionTests.testExceptionCleanupStatecsM�fdd�}ytWn,tk
rH�z|�WYdd��XnXdS)Ncs�dS)Nrr)rQrr�print_error|szIExceptionTests.test_exception_target_in_nested_scope.<locals>.print_error)Z	somethingr)rr�r)rQr�%test_exception_target_in_nested_scopeys
z4ExceptionTests.test_exception_target_in_nested_scopecCsPdd�}|�}|jt|�t�|jtj�dd�|jt|�t�|jtj�dd�|jt|�d�ytd��Wn�tk
rK|�}|jt|�t�|jtj�dt�|jt|�t�|jtj�dt�|jt|�t�~|jtj�dt�YnXdS)NcssVytd��Wn0tk
rBtj�dVtj�dVYnXtj�dVdS)NZcaughtr)r*rBrjrrrr�yield_raise�s
z:ExceptionTests.test_generator_leaking.<locals>.yield_raiserry)r�nextr*rBrjr:)rr�r�rrr�test_generator_leaking�s$	
	z%ExceptionTests.test_generator_leakingcCs{dd�}y
t�Wn%tk
r=|�}t|�YnXyt|�Wntk
r`YnX|jtj�d�dS)Ncss	dVdS)Nrrrrrr��sz1ExceptionTests.test_generator_leaking2.<locals>.g)NNN)r2r��
StopIterationrrBrj)rr��itrrr�test_generator_leaking2�s

	
z&ExceptionTests.test_generator_leaking2cCs�dd�}|�}t|�yddWnxtk
r�}zX|jtj�d|�|j|�}|jtj�d|�|j||�WYdd}~XnX|jtj�d�dS)Ncss1y	dVWn!tk
r,tj�dVYnXdS)Nr0)r>rBrjrrrrr��s	
z1ExceptionTests.test_generator_leaking3.<locals>.gr0r)NNN)r�r>r}rBrj�throwr)rr�r�rQZgen_excrrr�test_generator_leaking3�s	
#z&ExceptionTests.test_generator_leaking3cCs�dd�}|�}y
t�Wntk
r?t|�}YnX|j|t�yt|�Wn?tk
r�}z|jtj�d|�WYdd}~XnX|jtj�d�dS)Ncss7yddWn$tk
r2tj�dV�YnXdS)Nr0r)r>rBrjrrrrr��s

z1ExceptionTests.test_generator_leaking4.<locals>.gr0)NNN)r:r�r}r>rBrjr)rr�r��tprQrrr�test_generator_leaking4�s	

-z&ExceptionTests.test_generator_leaking4cs[�fdd�}|�}y
t�Wntk
rCt|�YnX�jtt|�dS)Nc3s9�jtj�dt�dV�jtj�d�dS)Nr0)NNN)r�rBrjr2rr)rrrr��sz>ExceptionTests.test_generator_doesnt_retain_old_exc.<locals>.g)r2r�r@r�)rr�r�r)rr�$test_generator_doesnt_retain_old_exc�s	

z3ExceptionTests.test_generator_doesnt_retain_old_exccsFdd���fdd�}|�t�|jtj�d�dS)Ncss	dVdS)Nr0rrrrr�
simple_gen�szIExceptionTests.test_generator_finalizing_and_exc_info.<locals>.simple_gencs6��}y
t�Wntk
r1t|�SYnXdS)N)r2r�)�gen)r�rr�run_gen�s
	

zFExceptionTests.test_generator_finalizing_and_exc_info.<locals>.run_gen)NNN)rrrBrj)rr�r)r�r�&test_generator_finalizing_and_exc_info�s
z5ExceptionTests.test_generator_finalizing_and_exc_infocs�Gdd�dt��Gdd�d�}��fdd�}|��tj��}|�}t|�||�d}�|��|j�d�dS)Nc@seZdZdd�ZdS)zFExceptionTests._check_generator_cleanup_exc_state.<locals>.MyExceptioncSs
||_dS)N)r�)rr�rrrr�szOExceptionTests._check_generator_cleanup_exc_state.<locals>.MyException.__init__N)rrrrrrrrr��sr�c@seZdZdS)z@ExceptionTests._check_generator_cleanup_exc_state.<locals>.MyObjN)rrrrrrrr��sr�c3s.y����Wn�k
r)dVYnXdS)Nrr)r�r�rr�raising_gens
zFExceptionTests._check_generator_cleanup_exc_state.<locals>.raising_gen)rr�r�r�r})rZtestfuncr�r�r�r�r)r�r�r�"_check_generator_cleanup_exc_state�s		


	z1ExceptionTests._check_generator_cleanup_exc_statecCsdd�}|j|�dS)NcSs-y|jt��Wntk
r(YnXdS)N)r�r2)r�rrr�do_throws
zGExceptionTests.test_generator_throw_cleanup_exc_state.<locals>.do_throw)r�)rr�rrr�&test_generator_throw_cleanup_exc_statesz5ExceptionTests.test_generator_throw_cleanup_exc_statecCsdd�}|j|�dS)NcSs|j�dS)N)rD)r�rrr�do_closeszGExceptionTests.test_generator_close_cleanup_exc_state.<locals>.do_close)r�)rr�rrr�&test_generator_close_cleanup_exc_statesz5ExceptionTests.test_generator_close_cleanup_exc_statecCsdd�}|j|�dS)NcSs
d}dS)Nr)r�rrr�do_delszCExceptionTests.test_generator_del_cleanup_exc_state.<locals>.do_del)r�)rr�rrr�$test_generator_del_cleanup_exc_statesz3ExceptionTests.test_generator_del_cleanup_exc_statecs#�fdd�}�j|�dS)Ncs4yt|�Wntk
r"YnX�jd�dS)Nz should have raised StopIteration)r�r�rL)r�)rrr�do_next$s

zEExceptionTests.test_generator_next_cleanup_exc_state.<locals>.do_next)r�)rr�r)rr�%test_generator_next_cleanup_exc_state#sz4ExceptionTests.test_generator_next_cleanup_exc_statecs#�fdd�}�j|�dS)Ncs7y|jd�Wntk
r%YnX�jd�dS)Nz should have raised StopIteration)�sendr�rL)r�)rrr�do_send.s

zEExceptionTests.test_generator_send_cleanup_exc_state.<locals>.do_send)r�)rrr)rr�%test_generator_send_cleanup_exc_state-sz4ExceptionTests.test_generator_send_cleanup_exc_statecsQG�fdd�d�}f�yt|���WnYnX|j�d�dS)Ncs"eZdZ�fdd�ZdS)z*ExceptionTests.test_3114.<locals>.MyObjectcstj��dS)N)rBrj)r)rQrr�__del__;sz2ExceptionTests.test_3114.<locals>.MyObject.__del__N)rrrrr)rQrr�MyObject:sr)NNN)rr)rrr)rQr�	test_31147szExceptionTests.test_3114cCs�tddddd�}|jt|�d�d|_|jt|�d�d|_d	|_|jt|�d
�d|_|jt|�d�d
|_|jt|�d�tddddd�}|jt|�d�d|_|jt|�d�d|_d	|_|jt|�d�d|_|jt|�d�d
|_|jt|�d�tdddd�}|jt|�d�d|_|jt|�d�d|_d	|_|jt|�d�d
|_|jt|�d�dS)Nr�Zxxxxxr0r�ryz8'baz' codec can't encode characters in position 1-4: foor`z<'baz' codec can't encode character '\x78' in position 1: foolESh
MQ)EzJ'baz' codec can't encode characters in position 1-4: 965230951443685724997i�zK'4000' codec can't encode characters in position 1-4: 965230951443685724997i�zN'4000' codec can't encode characters in position 1000-4: 965230951443685724997sxxxxxz3'baz' codec can't decode bytes in position 1-4: fooz5'baz' codec can't decode byte 0x78 in position 1: foozE'baz' codec can't decode bytes in position 1-4: 965230951443685724997zF'4000' codec can't decode bytes in position 1-4: 965230951443685724997zI'4000' codec can't decode bytes in position 1000-4: 965230951443685724997Zxxxxz/can't translate characters in position 1-4: fooz3can't translate character '\x78' in position 1: foozAcan't translate characters in position 1-4: 965230951443685724997zDcan't translate characters in position 1000-4: 965230951443685724997)	r�rrr�r�r�r�r�r�)r�urrr�test_unicode_change_attributesEs>														z-ExceptionTests.test_unicode_change_attributescCsCtttf}x-|D]%}|jt|j|��d�qWdS)N�)r�r�r�rr�__new__)rZklasses�klassrrr�test_unicode_errors_no_objectjs
z,ExceptionTests.test_unicode_errors_no_objectcsGdd�dt�}Gdd�dtd|�}t��{}y
t��WnW|k
r}z|jd�WYdd}~Xn3tk
r�Yn"|jd�YnX|jd�WdQRX�fdd	����\}}}|jt|t�t|��|jd
t	|��dS)Nc@seZdZdd�ZdS)z/ExceptionTests.test_badisinstance.<locals>.MetacSs
t��dS)N)r;)�cls�subclassrrr�__subclasscheck__uszAExceptionTests.test_badisinstance.<locals>.Meta.__subclasscheck__N)rrrr
rrrr�Metatsrc@seZdZdS)z6ExceptionTests.test_badisinstance.<locals>.MyExceptionN)rrrrrrrr�wsr��	metaclassz%exception should not be a MyExceptionzShould have raised KeyErrorcs.y��SWntk
r)tj�SYnXdS)N)r3rBrjr)r�rrr��s
z,ExceptionTests.test_badisinstance.<locals>.gz maximum recursion depth exceeded)
r�rrr*rLrn�
isinstancer3r�r)rrr�r�rQ�vrqr)r�r�test_badisinstanceps 

z!ExceptionTests.test_badisinstancecsZddl�ddlm����fdd�}|�}|�}�j||�dS)Nr)�raise_memoryerrorcsVy��Wn.tk
r;}z|j}WYdd}~XnX�jd��j|�S)Nz Should have raises a MemoryError)r-r�rL�	format_tb)rQrq)rr�	tracebackrr�
raiseMemError�s
z6ExceptionTests.test_MemoryError.<locals>.raiseMemError)rrhrr)rrZtb1Ztb2r)rrrr�test_MemoryError�s			zExceptionTests.test_MemoryErrorc
Cs�ddl}d}d}|jt|jd�|jd�}|jt|�t�|jt|t��|j	|j
�|jd|�}|j|j
|�|jdd|�}|jt||��Gd	d
�d
t�}|jd|||f�}|jt||��|jt||��|j|j
|�|jdd
|ddi�}	|jt|	|��|j|	j
d�|j|	j
d
�dS)NrzThis is a test docstring.zThis is another test docstring.�error1z_testcapi.error1z_testcapi.error2z_testcapi.error3�basec@seZdZdS)z1ExceptionTests.test_exception_with_doc.<locals>.CN)rrrrrrr�C�srz_testcapi.error4z_testcapi.error5rr�r0)rhr@r8Zmake_exception_with_docr}r�rn�
issubclassrr��__doc__rr�r�)
rrhZdoc2Zdoc4rZerror2Zerror3rZerror4Zerror5rrr�test_exception_with_doc�s2	z&ExceptionTests.test_exception_with_doccs�ddlm�Gdd�d��d����fdd�}y|�Wn8tk
r�}z|j��d�WYdd}~XnX|jd�|j��d�dS)Nr)rc@seZdZdS)z3ExceptionTests.test_memory_error_cleanup.<locals>.CN)rrrrrrrr�srcs#��}tj|����dS)N)r�r�)�c)rrr�rr�inner�s	z7ExceptionTests.test_memory_error_cleanup.<locals>.innerzMemoryError not raised)rhrr-�assertNotEqualrLr)rrrQr)rrr�r�test_memory_error_cleanup�s&
z(ExceptionTests.test_memory_error_cleanupcs�Gdd�d��d����fdd��y��Wn8tk
rv}z|j��d�WYdd}~XnX|jd�|j��d�dS)Nc@seZdZdS)z6ExceptionTests.test_recursion_error_cleanup.<locals>.CN)rrrrrrrr�srcs#��}tj|����dS)N)r�r�)r)rrr�rrr�s	z:ExceptionTests.test_recursion_error_cleanup.<locals>.innerzRecursionError not raised)r3r rLr)rrQr)rrr�r�test_recursion_error_cleanup�s&
z+ExceptionTests.test_recursion_error_cleanupcCsI|jt��}tjt�WdQRX|j|jjtj|j�dS)N)	r@r&�os�listdir�__file__rr[r~�ENOTDIR)rr^rrr�test_errno_ENOTDIR�sz!ExceptionTests.test_errno_ENOTDIRcCsfGdd�d�}Gdd�d|�}Gdd�d�}x#|||fD]}|j|���|�}t��
}~WdQRX|j�}|jd|�||kr�|jd|�n|j|jj|�|jd	|�|jd
|�||kr!|jd|�|jd|�n |jd
|�|jd|�|j|jd��WdQRXqLWdS)Nc@seZdZdd�ZdS)z1ExceptionTests.test_unraisable.<locals>.BrokenDelcSstd�}|�dS)Nz
del is broken)r;)rrrrrr�sz9ExceptionTests.test_unraisable.<locals>.BrokenDel.__del__N)rrrrrrrr�	BrokenDel�sr(c@seZdZdd�ZdS)z2ExceptionTests.test_unraisable.<locals>.BrokenReprcSstd��dS)Nzrepr() is broken)r!)rrrr�__repr__sz;ExceptionTests.test_unraisable.<locals>.BrokenRepr.__repr__N)rrrr)rrrr�
BrokenReprsr*c@seZdZdd�ZdS)z:ExceptionTests.test_unraisable.<locals>.BrokenExceptionDelcSst�}|�dS)N)r)rrrrrrs	zBExceptionTests.test_unraisable.<locals>.BrokenExceptionDel.__del__N)rrrrrrrr�BrokenExceptionDelsr+zException ignoredz<object repr() failed>ztest_exceptions.pyz	raise excrz<exception str() failed>r;z
del is broken�
)�subTestr�getvaluer�rrrnrp)rr(r*r+Z
test_classr�r��reportrrr�test_unraisable�s*	
zExceptionTests.test_unraisablecCsxttfD]�}|j|���y|d�}|�Wn8|k
rst��}tjtj��WdQRXYnX|j�}|jd|�|jd|�|j|j	|�|tkr�|jd|�n|jd|�|j
|jd��WdQRXq
WdS)Nztest messageztest_exceptions.pyz	raise excz<exception str() failed>r,)r;rr-rrB�__excepthook__rjr.r�rrnrp)rr�rr�r/rrr�test_unhandled"s 

zExceptionTests.test_unhandledN)4rrrr rRrZrdrrvr��unittestZ
skipUnlessrBrWr�r�r�r�r�r�r�r�r�r	r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
rrrr!r"r'r0r2rrrrrsXT
0'	~


t

% ('rc@s4eZdZdd�Zdd�Zdd�ZdS)�ImportErrorTestsc)Cs�td�}|j|j�|j|j�tddd�}|j|jd�|j|j�tddd�}|j|jd�|j|j�tddddd�}|j|jd�|j|jd�d}|jt|��tddd	�WdQRX|jt|��tddddd	�WdQRX|jt|��tddddd	�WdQRX|jt|��tdd	�WdQRXd
}|jt|��tddd	dd�WdQRXdS)
N�test�nameZ
somemodule�path�somepath�somenamez:'invalid' is an invalid keyword argument for this function�invalid�keywordzB'invalid|another' is an invalid keyword argument for this functionZanotherT)r'r�r6r7rr�r:)rrrSrrr�test_attributes:s0z ImportErrorTests.test_attributescCsRtdtfdd��3d}t|�}|jt|�t|��WdQRXdS)Nr�quietTsabc)r�BytesWarningr'rr)r�argrrrr�test_non_str_argument]sz&ImportErrorTests.test_non_str_argumentcCsZxSt�tdd�tdd�tdddd�fD]}td|�}x�ttjd�D]s}tjtj||��}|j|jd�|j|j	d�|j|j
|j
�|j|j|j�q`Wxxtjtj
fD]d}||�}|j|jd�|j|j	d�|j|j
|j
�|j|j|j�q�Wq7WdS)	Nr6r9r7r8r5r0)r5)r5)�dictr'rJr�r�rGr�rr�rSr6r7�copy�deepcopy)r�kwargsZorig�protorrrrr�test_copy_pickleds"	z!ImportErrorTests.test_copy_pickleN)rrrr<r@rFrrrrr48s#r4�__main__)rBr#rBr3r�r�r~Ztest.supportrrrrrrrr	r
rrrrrZTestCaserr4r�mainrrrr�<module>s$F����@