HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_exceptions.cpython-37.pyc
B

��g��@s�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZGdd�de�ZGdd�de�ZGdd�de�ZGd	d
�d
ej�ZGdd�dej�Zed
kr�e��dS)�N)�TESTFN�captured_stderr�check_impl_detail�check_warnings�cpython_only�
gc_collect�run_unittest�
no_tracing�unlink�
import_module�
script_helper�SuppressCrashReportc@seZdZdd�ZdS)�NaiveExceptioncCs
||_dS)N)�x)�selfr�r�0/usr/local/lib/python3.7/test/test_exceptions.py�__init__szNaiveException.__init__N)�__name__�
__module__�__qualname__rrrrrrsrc@seZdZdZdd�ZdS)�SlottedNaiveException)rcCs
||_dS)N)r)rrrrrrszSlottedNaiveException.__init__N)rrr�	__slots__rrrrrrsrc@seZdZdd�ZdS)�BrokenStrExceptioncCstd��dS)Nzstr() is broken)�	Exception)rrrr�__str__szBrokenStrException.__str__N)rrrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
e�e
jdkd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zed#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+dIdJ�Z,edKdL��Z-edMdN��Z.edOdP��Z/edQdR��Z0edSdT��Z1edUdV��Z2edWdX��Z3edYdZ��Z4d[d\�Z5d]d^�Z6d_d`�Z7edadb��Z8dcdd�Z9dedf�Z:dgdh�Z;diS)j�ExceptionTestsc
Cs�y|d��Wn*|k
r6}zt|�}Wdd}~XYnXy|d��Wn*|k
rn}zt|�}Wdd}~XYnX|�||�|�|j|�dS)NZspam)�str�assertEqualr)r�excZexcname�errZbuf1Zbuf2rrr�raise_catch szExceptionTests.raise_catchc
Cs�|�td�|�tttd�|�td�ttd�}|��ttd�}tj	}z0yddl
}|�d�Wntk
rvYnXWd|t_	|��tt�X|�t
d�|�t
td	d�|�td
�|�ttd�|�td�g}|�t|jd
�|�td�i}|�t|jd�|�td�|�td�|�td�yt}Wntk
�rLYnX|�td�d}xtd�D]}||7}�qhW|�td�|�td�|�td�ytd�Wntk
�r�YnX|�td�|�td�ytddd�Wntk
�rYnX|� d�|�t!d �|�t"d!�|�t"tj#d�|�t$d"�ygd#Wnt$k
�rbYnX|�t%d$�|�t%t&d%�|�t'd&�ydd}Wnt'k
�r�YnX|�t(d'�ydd}Wn$t(k
�r�}zWdd}~XYnX|�t)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�	TypeErrorr�
ValueErrori�ZeroDivisionErrorr�StopAsyncIteration)*r!r"�assertRaises�getattr�sysr#�openr�close�stdin�marshal�loadsr
r'r(�
__import__r)�__getitem__r+r-r.r/Zundefined_variabler0�ranger3r4r5r8r6r7�compile�failr9r:�exitr;r<�chrr=rr>)r�fpZ	savestdinrErZdummy�errr�testRaising,s�




zExceptionTests.testRaisingcsB�fdd�}d}tj�d�s&||d�d}||d�|dd�dS)	Nc
s`yt|dd�Wn@tk
rP}z"|j|kr@��d||jf�Wdd}~XYnX��d�dS)Nz
<fragment>r8zexpected %s, got %sz"failed to get expected SyntaxError)rJr5�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.testSyntaxErrorMessagecs^tf�fdd�	}d}||d�d}||d�d}||d�d	}||d
t�d}||dt�dS)
Nc
s`yt|dd�Wn@|k
rP}z"|j|kr@��d||jf�Wdd}~XYnX��d�dS)Nz
<fragment>r8zexpected %s, got %sz"failed to get expected SyntaxError)rJrQrK)rRrQ�	exceptionrO)rrrrS�s
&z:ExceptionTests.testSyntaxErrorMissingParens.<locals>.ckmsgzprint "old style"zHMissing parentheses in call to 'print'. Did you mean print("old style")?zprint "old style",zQMissing parentheses in call to 'print'. Did you mean print("old style", end=" ")?zexec "old style"z%Missing parentheses in call to 'exec'zif True:
print "No indent"zexpected an indented blockz6if True:
        print()
	exec "mixed tabs and spaces"z2inconsistent use of tabs and spaces in indentation)r5r6r7)rrSrWr)rr�testSyntaxErrorMissingParens�s	


z+ExceptionTests.testSyntaxErrorMissingParenscsL�fdd�}|ddd�|ddd�|d	d
d�|ddd�|d
dd�dS)Nc	sF��t��}t|dd�WdQRX��|jj|���|jj|�dS)Nz
<fragment>r8)r?r5rJrrY�lineno�offset)rRr[r\�cm)rrr�check�sz3ExceptionTests.testSyntaxErrorOffset.<locals>.checkzdef fact(x):
	return x!
�r*z1 +
r1�z def spam():
  print(1)
 print(2)�zPython = "Python" +�uPython = "Ṕýţĥòñ" +r)rr^r)rr�testSyntaxErrorOffset�sz$ExceptionTests.testSyntaxErrorOffsetcsjGdd�dt��Gdd�d����fdd�}��fdd�}��fd	d
�}tj�d�sf|�|�|�dS)Nc@seZdZdd�ZdS)z9ExceptionTests.testSettingException.<locals>.BadExceptioncSstd��dS)Nzcan't instantiate BadException)r3)Zself_rrrr�szBExceptionTests.testSettingException.<locals>.BadException.__init__N)rrrrrrrr�BadException�srdc@seZdZdS)z=ExceptionTests.testSettingException.<locals>.InvalidExceptionN)rrrrrrr�InvalidException�srec
s�ddl}y|��d�WnXtk
rp}z:t��\}}}|jj}��|jd���	|j
�d��Wdd}~XYnX��d�dS)Nrr1�
test_capi1ztest_exceptions.pyzExpected exception)
�	_testcapi�raise_exceptionr;rA�exc_info�tb_frame�f_coder�co_name�
assertTrue�co_filename�endswithrK)rgr r�tb�co)rdrrrrf�s$z7ExceptionTests.testSettingException.<locals>.test_capi1c
s�ddl}y|��d�Wnptk
r�}zRt��\}}}|jj}��|jd���	|j
�d��|jjj}��|jd�Wdd}~XYnX��
d�dS)Nrrztest_exceptions.py�
test_capi2zExpected exception)rgrhr3rArirjrkrrlrmrnro�f_backrK)rgr rrprqZco2)rdrrrrr�s
 z7ExceptionTests.testSettingException.<locals>.test_capi2csddl}��t|j�d�dS)Nrr1)rgr?r9rh)rg)rerrr�
test_capi3�s
z7ExceptionTests.testSettingException.<locals>.test_capi3rT)rrArUrV)rrfrrrtr)rdrerr�testSettingException�sz#ExceptionTests.testSettingExceptioncCs�ytWntk
rY�n�X|�tt�|�ttd��d�|�ttdd��d�tddd�}|�|jd�|�|jd�|�t|�d�td	ddd
�}|�|jd�|�|jd
�|�|jd�|�|j	d�|�|j
d�|�t|�d�td	ddd�}|�|jd
�|�|jd�|�|jd�|�|j	d�|�|j
d�|�t|�d�tdd�}|�|jd�|�|jd�|�|jd�|�|j	d�|�|j
d�dS)Ni�Z1001�messagez[Errno 1001] message�	�foo�barz[Errno 9] foo: 'bar'rrar_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	Cs8td�}d}|�td|��|j�|�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_messagesz#ExceptionTests.test_windows_messagecCs"tdddiftdddiftdddiftdddiftdddd�ftddddddd�ftd	d	dddd
d�ftdd	dddd
d�ftd
d	ddd�ftdddddd�ftddddddd�ftdddddddd�ftddddddddd�ftddd ddddd!d"�ftd#dd#dddddd$�ftdddiftd%d%d&d'd(d)d*�ftd&td+�d(dd)fd&td+�d(dd)fd&d+d(d)d*�ftd,d,d&d+d(d)d*�ftd-d-d.d/d(dd0�ft	dddd1�ft
dddd1�fg}y"|�tdddddddd2�f�Wnt
k
�r�YnX�x:|D�]0\}}}y||�}Wn$td3||ftjd4��Yn�Xt|�j�d5��sJ|�t|�jd6�t|�}xB|D]:}t||�}|�t|�t||�d7|||||f��qXWx�tgD]v}	xnt|	jd�D]\}
|	�||
�}|	�|�}x>|D]6}tt||��}t||�}
|�||
d8||f��q�W�q�W�q�W�q�WdS)9Nr�args)r1)rx)rxr1rx)r�r�)r�r�r�r}r)rxryry)rxry�bazr�)rxryr�N�quuxr�)r�r�r�)�errnoStr�strErrorStr�filenameStr)r�r�r�r�r�)r�rr}r�)r1r�r�)r1r�r1)r�r}rr�r�)rQ�textr�r[r\�print_file_and_line)�msgStrr�)r�r�r�rQr�r[r\)r�)r��	linenoStr�	offsetStr�textStrr�r�r�)r\r�r�r�rQr�r[)r�r�r�r�r�Zprint_file_and_lineStr)r�r�r�rQr�r[r\)�ascii�arr1zordinal not in ranger�r�rzordinal not in range)r��encoding�object�start�reason��)r�r�rr1zordinal not in range)uあrr1�ouchuあr�)r�r�r�r��end)r�r)r�rr~r}r�r�z
exc=%r, args=%r)�filer�builtinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s)�
BaseExceptionr:r'r5�UnicodeError�UnicodeEncodeError�UnicodeDecodeError�	bytearray�UnicodeTranslateErrorrr�appendr{r/�printrA�stderr�typerrorrrr@�repr�picklerI�HIGHEST_PROTOCOL�dumpsrF)rZ
exceptionListrr�ZexpectedrOrWZcheckArgName�value�pZprotocol�newZgotZwantrrr�testAttributes)s�
















zExceptionTests.testAttributescCs�ytd��Wnt��d}YnXt��|�}|�|t�|�|j|�td��|�}|�|t�|�|j|�Gdd�dt�}|��|�}|�||�|�|j|�dS)Nr`r_�c@seZdZdS)z5ExceptionTests.testWithTraceback.<locals>.MyExceptionN)rrrrrrr�MyException�sr�)	r)rArir��with_traceback�assertIsInstancer�
__traceback__r)rrprOr�rrr�testWithTraceback�sz ExceptionTests.testWithTracebackc
CsNydt�_Wn2tk
r>}z|�dt|��Wdd}~XYnX|�d�dS)Nr�z!__traceback__ must be a tracebackzNo exception raised)rr�r;�assertInrrK)rrOrrr�testInvalidTraceback�s
"z#ExceptionTests.testInvalidTracebackcCsP|�ttt�dd�|�ttt�d�|�ttt�dd�|�ttt�d�dS)N�	__cause__r1�__context__)r?r;�setattrr�delattr)rrrr�testInvalidAttrs�szExceptionTests.testInvalidAttrscCsJytd��Wnt��d}YnXt�}||_d|_|�|jd�dS)Nr`r_)r)rArirr�r)rrprOrrr�testNoneClearsTracebackAttr�sz*ExceptionTests.testNoneClearsTracebackAttrcCsnt�}|�|j�|�|j�t�}|�|j�|�|j�Gdd�dt�}|�}|�|j�|�|j�dS)Nc@seZdZdS)z5ExceptionTests.testChainingAttrs.<locals>.MyExceptionN)rrrrrrrr��sr�)r�assertIsNoner�r�r;r')rrOr�rrr�testChainingAttrs�sz ExceptionTests.testChainingAttrsc
Cs�y
t��Wn&tk
r0}z|}Wdd}~XYnX|�|j�|�|j�|�|j�t�|_d|_|�|jt�|�|j�|�|j�d|_|�|j�dS)NF)	rr�r�r�ZassertFalse�__suppress_context__r/r�rm)rrrOrrr�testChainingDescriptors�s
z&ExceptionTests.testChainingDescriptorscCs<|jttdd�Gdd�dt�}|dd�}|�|jd�dS)Nr1)r�c@seZdZdd�ZdS)z8ExceptionTests.testKeywordArgs.<locals>.DerivedExceptioncSst�|�||_dS)N)r�r�	fancy_arg)rr�rrrr�s
zAExceptionTests.testKeywordArgs.<locals>.DerivedException.__init__N)rrrrrrrr�DerivedException�sr��*)r�)r?r;r�rr�)rr�rrrr�testKeywordArgs�s
zExceptionTests.testKeywordArgscs4�fdd��|�t���fdd��|�t��dS)Ncs��S)Nrr)�frrr�sz/ExceptionTests.testInfiniteRecursion.<locals>.fcs y��Stk
rdSXdS)N���)r<r)�grrr�
sz/ExceptionTests.testInfiniteRecursion.<locals>.g)r?r4)rr)r�r�r�testInfiniteRecursionsz$ExceptionTests.testInfiniteRecursioncCs8|�tt��|�ttd���|�ttdd���dS)Nr��b)rmrr)rrrr�test_strszExceptionTests.test_strc
CsLy
t��Wn.tk
r8}z|�|�~Wdd}~XYnX|�dt��dS)NrO)rrmZassertNotIn�locals)rrOrrr�testExceptionCleanupNamess

z(ExceptionTests.testExceptionCleanupNamescs�Gdd�dt��Gdd�d�}��fdd�}|��t���}y
|�Wn"�k
rh}zWdd}~XYnXd�|��|���|��t���}y
|�Wn�k
r�YnXd�|��|���|��t���}y
|�WnYnXd�|��|���|��t���}x(dD] }y
|�WnPYnX�qWd�|��|���|��t���}y y
|�Wnt�YnXWnPtk
�r�}z0d|_d�|��tdd	��r�t�|���Wdd}~XYnX|��t���}y
|�Wn>�k
�r&yz�Wd�XWn�k
�r YnXYnXd�tdd	��r>t�|��|���Gd
d�d�}|��t���}|��|�WdQRXd�tdd	��r�t�|��|���dS)Nc@seZdZdd�ZdS)z=ExceptionTests.testExceptionCleanupState.<locals>.MyExceptioncSs
||_dS)N)�obj)rr�rrrr&szFExceptionTests.testExceptionCleanupState.<locals>.MyException.__init__N)rrrrrrrrr�%sr�c@seZdZdS)z7ExceptionTests.testExceptionCleanupState.<locals>.MyObjN)rrrrrrr�MyObj(sr�cs�}����dS)Nr)Z	local_ref)r�r�rr�inner_raising_func+szDExceptionTests.testExceptionCleanupState.<locals>.inner_raising_func)rF)Zcpythonc@seZdZdd�Zdd�ZdS)z9ExceptionTests.testExceptionCleanupState.<locals>.ContextcSs|S)Nr)rrrr�	__enter__�szCExceptionTests.testExceptionCleanupState.<locals>.Context.__enter__cSsdS)NTr)r�exc_type�	exc_valueZexc_tbrrr�__exit__�szBExceptionTests.testExceptionCleanupState.<locals>.Context.__exit__N)rrrr�r�rrrr�Context�sr�)r�weakref�refr�r+r�rr)rr�r��wrrO�ir�r)r�r�r�testExceptionCleanupState!s�


















z(ExceptionTests.testExceptionCleanupStatec
sB�fdd�}ytWn(tk
r<�z
|�Wdd��XYnXdS)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_scope�s
z4ExceptionTests.test_exception_target_in_nested_scopecCsdd�}|�}|�t|�t�|�t��dd�|�t|�t�|�t��dd�|�t|�d�ytd��Wn�tk
r�|�}|�t|�t�|�t��dt�|�t|�t�|�t��dt�|�t|�t�~|�t��dt�YnXdS)NcssPytd��Wn0tk
r<t��dVt��dVYnXt��dVdS)NZcaughtr)r+rArirrrr�yield_raise�sz:ExceptionTests.test_generator_leaking.<locals>.yield_raiserrx)r�nextr+rArir;)rr�r�rrr�test_generator_leaking�s$z%ExceptionTests.test_generator_leakingcCsjdd�}yt�Wn"tk
r2|�}t|�YnXyt|�Wntk
rTYnX|�t��d�dS)Ncss
dVdS)Nrrrrrr��sz1ExceptionTests.test_generator_leaking2.<locals>.g)NNN)r3r��
StopIterationrrAri)rr��itrrr�test_generator_leaking2�sz&ExceptionTests.test_generator_leaking2c
Cs�dd�}|�}t|�yddWn`tk
r�}zB|�t��d|�|�|�}|�t��d|�|�||�Wdd}~XYnX|�t��d�dS)Ncss2y
dVWn"tk
r,t��dVYnXdS)Nr1)r=rArirrrrr��s
z1ExceptionTests.test_generator_leaking3.<locals>.gr1r)NNN)r�r=r|rAri�throwr)rr�r�rOZgen_excrrr�test_generator_leaking3�s
z&ExceptionTests.test_generator_leaking3c
Cs�dd�}|�}yt�Wntk
r2t|�}YnX|�|t�yt|�Wn6tk
r�}z|�t��d|�Wdd}~XYnX|�t��d�dS)Ncss6yddWn$tk
r0t��dV�YnXdS)Nr1r)r=rArirrrrr��s
z1ExceptionTests.test_generator_leaking4.<locals>.gr1)NNN)r;r�r|r=rArir)rr�r��tprOrrr�test_generator_leaking4�s&z&ExceptionTests.test_generator_leaking4csJ�fdd�}|�}yt�Wntk
r6t|�YnX��tt|�dS)Nc3s.��t��dt�dV��t��d�dS)Nr1)NNN)r�rArir3rr)rrrr��sz>ExceptionTests.test_generator_doesnt_retain_old_exc.<locals>.g)r3r�r?r�)rr�r�r)rr�$test_generator_doesnt_retain_old_exc�sz3ExceptionTests.test_generator_doesnt_retain_old_exccs4dd���fdd�}|�t�|�t��d�dS)Ncss
dVdS)Nr1rrrrr�
simple_gen	szIExceptionTests.test_generator_finalizing_and_exc_info.<locals>.simple_gencs,��}yt�Wntk
r&t|�SXdS)N)r3r�)�gen)r�rr�run_gens
zFExceptionTests.test_generator_finalizing_and_exc_info.<locals>.run_gen)NNN)rrrAri)rr�r)r�r�&test_generator_finalizing_and_exc_infos
z5ExceptionTests.test_generator_finalizing_and_exc_infocsnGdd�dt��Gdd�d�}��fdd�}|��t���}|�}t|�||�d}�|��|���dS)Nc@seZdZdd�ZdS)zFExceptionTests._check_generator_cleanup_exc_state.<locals>.MyExceptioncSs
||_dS)N)r�)rr�rrrrszOExceptionTests._check_generator_cleanup_exc_state.<locals>.MyException.__init__N)rrrrrrrrr�sr�c@seZdZdS)z@ExceptionTests._check_generator_cleanup_exc_state.<locals>.MyObjN)rrrrrrrr�sr�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_states
z1ExceptionTests._check_generator_cleanup_exc_statecCsdd�}|�|�dS)NcSs*y|�t��Wntk
r$YnXdS)N)r�r3)r�rrr�do_throw.szGExceptionTests.test_generator_throw_cleanup_exc_state.<locals>.do_throw)r�)rr�rrr�&test_generator_throw_cleanup_exc_state-sz5ExceptionTests.test_generator_throw_cleanup_exc_statecCsdd�}|�|�dS)NcSs|��dS)N)rC)r�rrr�do_close6szGExceptionTests.test_generator_close_cleanup_exc_state.<locals>.do_close)r�)rr�rrr�&test_generator_close_cleanup_exc_state5sz5ExceptionTests.test_generator_close_cleanup_exc_statecCsdd�}|�|�dS)NcSsd}dS)Nr)r�rrr�do_del;szCExceptionTests.test_generator_del_cleanup_exc_state.<locals>.do_del)r�)rr�rrr�$test_generator_del_cleanup_exc_state:sz3ExceptionTests.test_generator_del_cleanup_exc_statecs�fdd�}��|�dS)Ncs0yt|�Wntk
r YnX��d�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?sz4ExceptionTests.test_generator_next_cleanup_exc_statecs�fdd�}��|�dS)Ncs2y|�d�Wntk
r"YnX��d�dS)Nz should have raised StopIteration)�sendr�rK)r�)rrr�do_sendJs
zEExceptionTests.test_generator_send_cleanup_exc_state.<locals>.do_send)r�)rr�r)rr�%test_generator_send_cleanup_exc_stateIsz4ExceptionTests.test_generator_send_cleanup_exc_statecsBG�fdd�d�}d�yt|���WnYnX|��d�dS)NcseZdZ�fdd�ZdS)z*ExceptionTests.test_3114.<locals>.MyObjectcst���dS)N)rAri)r)rOrr�__del__Wsz2ExceptionTests.test_3114.<locals>.MyObject.__del__N)rrrr�r)rOrr�MyObjectVsr�r)NNN)rr)rr�r)rOr�	test_3114SszExceptionTests.test_3114cCsftddddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d
�d|_|�t|�d�d
|_|�t|�d�tddddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d�d|_|�t|�d�d
|_|�t|�d�tdddd�}|�t|�d�d|_|�t|�d�d|_d	|_|�t|�d�d
|_|�t|�d�dS)Nr�Zxxxxxr1r�rxz8'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_attributesas>z-ExceptionTests.test_unicode_change_attributescCs2tttf}x"|D]}|�t|�|��d�qWdS)N�)r�r�r�rr�__new__)rZklasses�klassrrr�test_unicode_errors_no_object�s

z,ExceptionTests.test_unicode_errors_no_objectcs�Gdd�dt�}Gdd�dt|d�}t��n}y
t��WnR|k
rb}z|�d�Wdd}~XYn2tk
rtYn |�d�YnX|�d�WdQRX�fdd	����\}}}|�|tt|��|�d
t|��dS)Nc@seZdZdd�ZdS)z/ExceptionTests.test_badisinstance.<locals>.MetacSs
t��dS)N)r<)�cls�subclassrrr�__subclasscheck__�szAExceptionTests.test_badisinstance.<locals>.Meta.__subclasscheck__N)rrrrrrrr�Meta�src@seZdZdS)z6ExceptionTests.test_badisinstance.<locals>.MyExceptionN)rrrrrrrr��sr�)�	metaclassz%exception should not be a MyExceptionzShould have raised KeyErrorcs$y��Stk
rt��SXdS)N)r4rArir)r�rrr��sz,ExceptionTests.test_badisinstance.<locals>.gz maximum recursion depth exceeded)	r�rrr+rKr�r4r�r)rrr�r�rO�vrpr)r�r�test_badisinstance�s 
z!ExceptionTests.test_badisinstancecCsPdt}t�dd|�\}}}|�|d�|�d|�|�d|�|�d|�dS)Na�if 1:
            import sys
            from _testcapi import get_recursion_depth

            class MyException(Exception): pass

            def setrecursionlimit(depth):
                while 1:
                    try:
                        sys.setrecursionlimit(depth)
                        return depth
                    except RecursionError:
                        # sys.setrecursionlimit() raises a RecursionError if
                        # the new recursion limit is too low (issue #25274).
                        depth += 1

            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    generator.throw(MyException)

            def gen():
                f = open(%a, mode='rb', buffering=0)
                yield

            generator = gen()
            next(generator)
            recursionlimit = sys.getrecursionlimit()
            depth = get_recursion_depth()
            try:
                # Upon the last recursive invocation of recurse(),
                # tstate->recursion_depth is equal to (recursion_limit - 1)
                # and is equal to recursion_limit when _gen_throw() calls
                # PyErr_NormalizeException().
                recurse(setrecursionlimit(depth + 2) - depth - 1)
            finally:
                sys.setrecursionlimit(recursionlimit)
                print('Done.')
        z-Wdz-cr1sRecursionErrorsResourceWarningsDone.)�__file__r�assert_python_failurerr�)rr��rc�outr rrr�$test_recursion_normalizing_exception�s3z3ExceptionTests.test_recursion_normalizing_exceptioncCs>d}t�d|�\}}}|�|d�|�d|�|�d|�dS)Nz�if 1:
            import _testcapi
            try:
                raise _testcapi.RecursingInfinitelyError
            finally:
                print('Done.')
        z-cr1sORecursionError: maximum recursion depth exceeded while normalizing an exceptionsDone.)rrrr�)rr�rr
r rrr�-test_recursion_normalizing_infinite_exception�sz<ExceptionTests.test_recursion_normalizing_infinite_exceptionc	Cs8d}t��$t�d|�\}}}|�d|�WdQRXdS)Na+if 1:
            import _testcapi
            class C(): pass
            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    _testcapi.set_nomemory(0)
                    C()
            recurse(16)
        z-csRFatal Python error: Cannot recover from MemoryErrors while normalizing exceptions.)r
rrr�)rr�rr
r rrr�)test_recursion_normalizing_with_no_memory�s
z8ExceptionTests.test_recursion_normalizing_with_no_memorycs@ddl�ddlm����fdd�}|�}|�}��||�dS)Nr)�raise_memoryerrorc
sHy
��Wn(tk
r2}z
|j}Wdd}~XYnX��d���|�S)Nz Should have raises a MemoryError)r.r�rK�	format_tb)rOrp)rr�	tracebackrr�
raiseMemErrors

z6ExceptionTests.test_MemoryError.<locals>.raiseMemError)rrgrr)rrZtb1Ztb2r)rrrr�test_MemoryErrors	zExceptionTests.test_MemoryErrorc
Cs"ddl}d}d}|�t|jd�|�d�}|�t|�t�|�t|t��|�	|j
�|�d|�}|�|j
|�|jd|d�}|�t||��Gd	d
�d
t�}|�d|||f�}|�t||��|�t||��|�|j
|�|�dd
|ddi�}	|�t|	|��|�|	j
d�|�|	j
d
�dS)NrzThis is a test docstring.zThis is another test docstring.�error1z_testcapi.error1z_testcapi.error2z_testcapi.error3)�basec@seZdZdS)z1ExceptionTests.test_exception_with_doc.<locals>.CN)rrrrrrr�C;srz_testcapi.error4z_testcapi.error5r�r�r1)rgr?r9Zmake_exception_with_docr|r�rm�
issubclassrr��__doc__rr�r�)
rrgZdoc2Zdoc4rZerror2Zerror3rZerror4Zerror5rrr�test_exception_with_doc"s2


z&ExceptionTests.test_exception_with_docc
s�ddlm�Gdd�d��d����fdd�}y
|�Wn0tk
rh}z|���d�Wdd}~XYnX|�d�|���d�dS)Nr)rc@seZdZdS)z3ExceptionTests.test_memory_error_cleanup.<locals>.CN)rrrrrrrrOsrcs��}t�|����dS)N)r�r�)�c)rrr�rr�innerRs
z7ExceptionTests.test_memory_error_cleanup.<locals>.innerzMemoryError not raised)rgrr.�assertNotEqualrKr)rrrOr)rrr�r�test_memory_error_cleanupJs
 
z(ExceptionTests.test_memory_error_cleanupc
szGdd�d��d����fdd��y
��Wn0tk
r\}z|���d�Wdd}~XYnX|�d�|���d�dS)Nc@seZdZdS)z6ExceptionTests.test_recursion_error_cleanup.<locals>.CN)rrrrrrrrcsrcs��}t�|����dS)N)r�r�)r)rrr�rrrfs
z:ExceptionTests.test_recursion_error_cleanup.<locals>.innerzRecursionError not raised)r4rrKr)rrOr)rrr�r�test_recursion_error_cleanup`s
 
z+ExceptionTests.test_recursion_error_cleanupc	Cs:|�t��}t�t�WdQRX|�|jjtj|j�dS)N)	r?r'�os�listdirr
rrYr}ZENOTDIR)rr]rrr�test_errno_ENOTDIRtsz!ExceptionTests.test_errno_ENOTDIRcCs�Gdd�d�}Gdd�d�}x�||fD]�}|�|���|�}t��}~WdQRX|��}|�d|�|�|jj|�|�d|�|�d|�||kr�|�d|�|�d	|�n|�d
|�|�d|�|�|�d��WdQRXq&WdS)
Nc@seZdZdd�ZdS)z1ExceptionTests.test_unraisable.<locals>.BrokenDelcSstd�}|�dS)Nz
del is broken)r<)rrrrrr�}sz9ExceptionTests.test_unraisable.<locals>.BrokenDel.__del__N)rrrr�rrrr�	BrokenDel|sr$c@seZdZdd�ZdS)z:ExceptionTests.test_unraisable.<locals>.BrokenExceptionDelcSst�}|�dS)N)r)rrrrrr��szBExceptionTests.test_unraisable.<locals>.BrokenExceptionDel.__del__N)rrrr�rrrr�BrokenExceptionDel�sr%zException ignoredztest_exceptions.pyz	raise excrz<exception str() failed>r<z
del is broken�
)�subTestr�getvaluer�r�rrmro)rr$r%Z
test_classr�r��reportrrr�test_unraisablezs$zExceptionTests.test_unraisablecCs�x�ttfD]�}|�|���y|d�}|�Wn4|k
r^t��}tjt���WdQRXYnX|��}|�d|�|�d|�|�|j	|�|tkr�|�d|�n|�d|�|�
|�d��WdQRXq
WdS)Nztest messageztest_exceptions.pyz	raise excz<exception str() failed>r&)r<rr'rrA�__excepthook__rir(r�rrmro)rr�rr�r)rrr�test_unhandled�s zExceptionTests.test_unhandledcCsJd}x@tdd�D]2}t�d||�\}}}|�|d�|�d|�qWdS)Nz�if 1:
            import _testcapi
            class C(): pass
            _testcapi.set_nomemory(0, %d)
            C()
        r1rbz-c)r1�xsMemoryError)rIrrr�)rr�r�rr
r rrr�"test_memory_error_in_PyErr_PrintEx�s
z1ExceptionTests.test_memory_error_in_PyErr_PrintExc	sdGdd�dt��Gdd�dt����fdd�}|�}|�d�|����|����WdQRXdS)Nc@seZdZdS)zBExceptionTests.test_yield_in_nested_try_excepts.<locals>.MainErrorN)rrrrrrr�	MainError�sr/c@seZdZdS)zAExceptionTests.test_yield_in_nested_try_excepts.<locals>.SubErrorN)rrrrrrr�SubError�sr0c3sFy
���Wn6�k
r@y
dVWn�k
r8YnX�YnXdS)Nrr)r/r0rr�main�s

z=ExceptionTests.test_yield_in_nested_try_excepts.<locals>.main)rr�r?r�)rr1�coror)r/r0r� test_yield_in_nested_try_excepts�s

z/ExceptionTests.test_yield_in_nested_try_exceptscsT�fdd�}|�}yt�Wn$tk
r>��t|�d�YnX��t|�d�dS)Nc3s>yt�Wntk
r"dVYnX��t��d�dVdS)Nr1)NNNr_)r<rrArir)rrrr��sz?ExceptionTests.test_generator_doesnt_retain_old_exc2.<locals>.gr1r_)r)rr�)rr�r�r)rr�%test_generator_doesnt_retain_old_exc2�sz4ExceptionTests.test_generator_doesnt_retain_old_exc2c	CsRdd�}|�t��6|�}yddWnt|�t|�YnXWdQRXdS)NcssdV�dVdS)Nr1r_rrrrrr��sz1ExceptionTests.test_raise_in_generator.<locals>.gr1r)r?r=r�)rr�r�rrr�test_raise_in_generator�sz&ExceptionTests.test_raise_in_generatorN)<rrrr!rPrXrZrcrrur��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�r�r�rr	rrrrrrr r#r*r,r.r3r4r5rrrrrshT
0'	~


t

%;( rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ImportErrorTestsc	CsVtd�}|�|j�|�|j�tddd�}|�|jd�|�|j�tddd�}|�|jd�|�|j�tdddd�}|�|jd�|�|jd�d}|�t|��tdd	d
�WdQRX|�t|��tddd	d�WdQRX|�t|��tdd
d	d�WdQRX|�t|��td	d
�WdQRX|�t|��tdd	dd�WdQRXdS)N�testZ
somemodule)�name�somepath)�path�somename)r;r9z8'invalid' is an invalid keyword argument for ImportError�keyword)�invalidr9)r9r>r;)r;r>T)r>Zanother)r(r�r9r;rr�r;)rrrQrrr�test_attributes�s.z ImportErrorTests.test_attributescCs�tdddd�}|�|jd�|�|jd�|�|jd�|�|jd�|��|�|jd�|�|jd�|�|jd�|�|jd�dS)Nr8r9r;)r9r;)r8r)r(rr�rQr9r;r)rrrrr�test_reset_attributessz&ImportErrorTests.test_reset_attributesc	Cs@tdtfdd��&d}t|�}|�t|�t|��WdQRXdS)Nr�T)�quietsabc)r�BytesWarningr(rr)r�argrrrr�test_non_str_argument+sz&ImportErrorTests.test_non_str_argumentcCs�x�t�tdd�tdd�tddd�fD]�}td	|�}xdttjd�D]R}t�t�||��}|�|jd�|�|j	d�|�|j
|j
�|�|j|j�qBWxXtjtj
fD]H}||�}|�|jd�|�|j	d�|�|j
|j
�|�|j|j�q�Wq$WdS)
Nr<)r9r:)r;)r9r;r8r1)r8)r8)�dictr(rIr�r�rFr�rr�rQr9r;�copyZdeepcopy)r�kwargsZorig�protorrrrr�test_copy_pickle2s"
z!ImportErrorTests.test_copy_pickleN)rrrr?r@rDrIrrrrr7�s"r7�__main__)rFr!rAr6r�r�r}Ztest.supportrrrrrrrr	r
rrr
rrrrZTestCaserr7rr1rrrr�<module>s.8dM