Your IP : 216.73.216.85


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.pyc



��Yfڡ�@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�9/opt/alt/python35/lib64/python3.5/test/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�excZexcname�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)*rr �assertRaises�getattr�sysr!�openr�close�stdin�marshal�loadsr
r%r&�
__import__r'�__getitem__r)r+r,r-Zundefined_variabler.�ranger1r2r3r6r4r5�compile�failr7r8�exitr9r:�chrr=rr>)r�fpZ	savestdinrEr
Zdummy�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>r6zexpected %s, got %sz"failed to get expected SyntaxError)rJr3�msgrK)�srcrQrO)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
)rA�platform�
startswith)rrS�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>r6)r?r3rJr�	exception�lineno�offset)rRrZr[�cm)rrr�check�sz3ExceptionTests.testSyntaxErrorOffset.<locals>.checkzdef fact(x):
	return x!
�r(z1 +
r/�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)r1)Zself_rrrr�szBExceptionTests.testSettingException.<locals>.BadException.__init__N)rrrrrrrr�BadException�srcc@seZdZdS)z=ExceptionTests.testSettingException.<locals>.InvalidExceptionN)rrrrrrr�InvalidException�srdcs�ddl}y|j�d�Wnrtk
r�}zRtj�\}}}|jj}�j|jd��j	|j
jd��WYdd}~XnX�jd�dS)Nrr/�
test_capi1ztest_exceptions.pyzExpected exception)
�	_testcapi�raise_exceptionr9rA�exc_info�tb_frame�f_coder�co_name�
assertTrue�co_filename�endswithrK)rfrr�tb�co)rcrrrre�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)rfrgr1rArhrirjrrkrlrmrn�f_backrK)rfrrrorpZco2)rcrrrrq�s&z7ExceptionTests.testSettingException.<locals>.test_capi2cs)ddl}�jt|j�d�dS)Nrr/)rfr?r7rg)rf)rdrrr�
test_capi3�sz7ExceptionTests.testSettingException.<locals>.test_capi3rT)rrArUrV)rrerqrsr)rcrdrr�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'rr`r^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)z:Should fill in unknown error code in Windows error message�ctypeslcs�@zWindows Error 0x%xN)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�argsr/rwr�rr�r|r~rx�baz�quux�errnoStr�strErrorStr�filenameStrrQ�textrZr[�print_file_and_line�msgStr�	linenoStr�	offsetStr�textStr�print_file_and_lineStr�ascii�ar�ordinal not in range�encoding�object�start�reason���あ�ouch�endr
r}z
exc=%r, args=%r�filer�builtinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s)r/)r/)rw)rw)rwr/)rwr/)rw)rw)rw)rw)rwrx)rwrx)rwrxr�)rwrx)rwrxr�Nr�)rwrx)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�r�r�)r�r�r�r�r�r�)r�r�rr/r�)r�r�rr/r�)r�r�rr/r�)r�r�rr/r�)r�rr/r�)r�rr/r�)rw)rw)rw)rw)r/r�r�)r/r�)�
BaseExceptionr8r%r3�UnicodeError�UnicodeEncodeError�UnicodeDecodeError�	bytearray�UnicodeTranslateErrorrr�appendrzr-�printrA�stderr�typerrnrrrr@�repr�picklerI�HIGHEST_PROTOCOL�dumpsrF)rZ
exceptionListrr�ZexpectedrOrWZcheckArgName�value�pZprotocol�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)Nr_r^�c@seZdZdS)z5ExceptionTests.testWithTraceback.<locals>.MyExceptionN)rrrrrrr�MyException�sr�)	r'rArhr��with_traceback�assertIsInstancer�
__traceback__r)rrorOr�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�r9�assertInrrK)rrOrrr�testInvalidTraceback�s
)z#ExceptionTests.testInvalidTracebackcCsn|jttt�dd�|jttt�d�|jttt�dd�|jttt�d�dS)N�	__cause__r/�__context__)r?r9�setattrr�delattr)rrrr�testInvalidAttrs�szExceptionTests.testInvalidAttrsc	Cs]ytd��Wntj�d}YnXt�}||_d|_|j|jd�dS)Nr_r^)r'rArhrr�r)rrorOrrr�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�r9r%)rrOr�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�rl)rrrOrrr�testChainingDescriptors�s
		z&ExceptionTests.testChainingDescriptorscCsR|jttdd�Gdd�dt�}|dd�}|j|jd�dS)Nr�r/c@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?r9r�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)Nr/���)r:r)�grrr��s
z/ExceptionTests.testInfiniteRecursion.<locals>.g)r?r2)rr)r�r�r�testInfiniteRecursion�sz$ExceptionTests.testInfiniteRecursioncCsL|jtt��|jttd���|jttdd���dS)Nr��b)rlrr)rrrr�test_str�szExceptionTests.test_strcCs\y
t��Wn5tk
rD}z|j|�~WYdd}~XnX|jdt��dS)NrO)rrlZassertNotIn�locals)rrOrrr�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_valueZexc_tbrrr�__exit__mszBExceptionTests.testExceptionCleanupState.<locals>.Context.__exit__N)rrrr�r�rrrr�Contextjsr�)r�weakref�refrlr)r�rr)rr�r��wrrO�ir�r)r�r�r�testExceptionCleanupStates�			
				
				-	


		
	z(ExceptionTests.testExceptionCleanupStatecsM�fdd�}ytWn,tk
rH�z|�WYdd��XnXdS)Ncs�dS)Nrr)rOrr�print_error|szIExceptionTests.test_exception_target_in_nested_scope.<locals>.print_error)Z	somethingr)rr�r)rOr�%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)rArhrrrr�yield_raise�s
z:ExceptionTests.test_generator_leaking.<locals>.yield_raiserrw)r�nextr)rArhr9)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)r1r��
StopIterationrrArh)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)Nr/)r=rArhrrrrr��s	
z1ExceptionTests.test_generator_leaking3.<locals>.gr/r)NNN)r�r=r{rArh�throwr)rr�r�rOZgen_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)Nr/r)r=rArhrrrrr��s

z1ExceptionTests.test_generator_leaking4.<locals>.gr/)NNN)r9r�r{r=rArhr)rr�r��tprOrrr�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)Nr/)NNN)r�rArhr1rr)rrrr��sz>ExceptionTests.test_generator_doesnt_retain_old_exc.<locals>.g)r1r�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)Nr/rrrrr�
simple_gen�szIExceptionTests.test_generator_finalizing_and_exc_info.<locals>.simple_gencs6��}y
t�Wntk
r1t|�SYnXdS)N)r1r�)�gen)r�rr�run_gen�s
	

zFExceptionTests.test_generator_finalizing_and_exc_info.<locals>.run_gen)NNN)rrrArh)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�r1)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)rC)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�rK)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�rK)r�)rrr�do_send.s

zEExceptionTests.test_generator_send_cleanup_exc_state.<locals>.do_send)r�)rr�r)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)rArh)r)rOrr�__del__;sz2ExceptionTests.test_3114.<locals>.MyObject.__del__N)rrrr�r)rOrr�MyObject:sr�)NNN)rr)rr�r)rOr�	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�Zxxxxxr/r�rwz8'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r
c@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)r2rArhr)r�rrr��s
z,ExceptionTests.test_badisinstance.<locals>.gz maximum recursion depth exceeded)
r�rrr)rKrl�
isinstancer2r�r)rr
r�r�rO�vror)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�rK�	format_tb)rOro)rr�	tracebackrr�
raiseMemError�s
z6ExceptionTests.test_MemoryError.<locals>.raiseMemError)rrfrr)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�r/)rfr?r7Zmake_exception_with_docr{r�rl�
issubclassrr��__doc__rr�r�)
rrfZdoc2Zdoc4rZerror2Zerror3rZerror4Zerror5rrr�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)rfrr,�assertNotEqualrKr)rrrOr)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)r2rrKr)rrOr)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__rrYr|�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)rrrr�rrrr�	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)rrrrrr�s	zBExceptionTests.test_unraisable.<locals>.BrokenExceptionDel.__del__N)rrrr�rrrr�BrokenExceptionDelsr'zException ignoredz<object repr() failed>ztest_exceptions.pyz	raise excrz<exception str() failed>r:z
del is broken�
)�subTestr�getvaluer�r�rrlrn)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)rrA�__excepthook__rhr*r�rrlrn)rr�rr�r+rrr�test_unhandled"s 

zExceptionTests.test_unhandledN)4rrrrrPrXrbrrtr��unittestZ
skipUnlessrArUr�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�rrrrrrrrr#r,r.rrrrrsX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 functionZinvalid�keywordzB'invalid|another' is an invalid keyword argument for this functionZanotherT)r&r�r2r3rr�r9)rrrQrrr�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)	Nr2r5r3r4r1r/)r1)r1)�dictr&rIr�r�rFr�rr�rQr2r3�copy�deepcopy)r�kwargsZorig�protorrrrr�test_copy_pickleds"	z!ImportErrorTests.test_copy_pickleN)rrrr7r;rArrrrr08s#r0�__main__)r=rrAr/r�r�r|Ztest.supportrrrrrrrr	r
rrrrrZTestCaserr0r�mainrrrr�<module>s$F����@