a ze8@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZGdddeZGdddeZGdd d eZGd d d ejZGd d d ejZedkredS)N) TESTFNcaptured_stderrcheck_impl_detailcheck_warnings cpython_only gc_collect no_tracingunlink import_module script_helperSuppressCrashReport)supportc@seZdZddZdS)NaiveExceptioncCs ||_dSNxselfrrH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_exceptions.py__init__szNaiveException.__init__N__name__ __module__ __qualname__rrrrrrsrc@seZdZdZddZdS)SlottedNaiveExceptionrcCs ||_dSrrrrrrrszSlottedNaiveException.__init__N)rrr __slots__rrrrrrsrc@seZdZddZdS)BrokenStrExceptioncCs tddS)Nzstr() is broken) Exceptionrrrr__str__szBrokenStrException.__str__N)rrrr rrrrrsrc@s<eZdZddZddZddZddZdd d Zd d ZddZ e ddZ ddZ e ejdkdddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zed(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Z d4d5Z!d6d7Z"d8d9Z#d:d;Z$dd?Z&d@dAZ'dBdCZ(dDdEZ)dFdGZ*dHdIZ+dJdKZ,dLdMZ-dNdOZ.dPdQZ/dRdSZ0dTdUZ1dVdWZ2edXdYZ3e dZd[Z4e d\d]Z5e d^d_Z6e d`daZ7e dbdcZ8e dddeZ9e dfdgZ:edhdiZ;djdkZe dpdqZ?drdsZ@dtduZAdvdwZBe dxdydzd{ZCd|d}ZDd~S)ExceptionTestsc Cs|j||dz |dWn,|yH}zt|}WYd}~n d}~00z |dWn,|y}zt|}WYd}~n d}~00|||||j|Wdn1s0YdS)N)excexcnameZspam)subTeststr assertEqualr)rr"r#errZbuf1Zbuf2rrr raise_catch$s   zExceptionTests.raise_catchc Cs|td|tttd|tdttd}|ttd}tj }zDzddl }| dWntytYn0W|t_ |t tn|t_ |t t0|t d|t td d|td |ttd |td g}|t|jd |tdi}|t|jd|td|td|tdzt}Wnty^Yn0|tdd}tdD]}||7}qx|td|td|tdz tdWntyYn0|td|tdztdddWnty Yn 0| d|t!d |t"d!|t"tj#d|t$d"z gd#Wnt$yjYn0|t%d$|t%t&d%|t'd&z dd}Wnt'yYn0|t(d'z dd}Wn&t(y}z WYd}~n d}~00|t)d(dS))NAttributeErrorZundefined_attributeEOFErrorwrrOSErrorzthis file does not exist ImportErrorZundefined_module IndexError KeyErrorkeyKeyboardInterrupt MemoryError NameError OverflowError RuntimeErrorRecursionError SyntaxErrorz/ IndentationErrorTabErrorz"try: 1/0 1/0 finally: pass zexeczTabError not raised SystemError SystemExit TypeErrorr ValueErroriZeroDivisionErrorrStopAsyncIteration)*r(r) assertRaisesgetattrsysr*openrclosestdinmarshalloadsr r.r/ __import__r0 __getitem__r2r4r5r6Zundefined_variabler7ranger:r;r<r?r=r>compilefailr@rAexitrBrCchrrDrrE)rfpZ savestdinrLrdummyerrr testRaising1s                              &zExceptionTests.testRaisingcs(fdd}d}||d|dddS)Nc sj||dnzt|ddWnBtyb}z*|j|krNd||jfWYd}~nd}~00dWdn1s0YdS)N)srcmsg r?expected %s, got %s"failed to get expected SyntaxError)r$rQr<rZrR)rYrZrWrrrckmsgs *z4ExceptionTests.testSyntaxErrorMessage..ckmsgzHif 1: try: continue except: passz'continue' not properly in loopz continue rrr^srrrtestSyntaxErrorMessages  z%ExceptionTests.testSyntaxErrorMessagecs^tffdd }d}||dd}||dd}||dd }||d td }||d tdS) Nc sbzt|ddWnB|yR}z*|j|kr>d||jfWYd}~nd}~00ddS)Nr[r?r\r])rQrZrR)rYrZ exceptionrWrrrr^s  *z:ExceptionTests.testSyntaxErrorMissingParens..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)r<r=r>r_rrrtestSyntaxErrorMissingParenss     z+ExceptionTests.testSyntaxErrorMissingParensutf-8c Cs|j|||d|t}t|ddWdn1s>0Y||jj|||jj||jjdurt |t s| |d}| d|d}| ||jjWdn1s0YdS)N)sourcelinenooffsetr[r?replace r8)r$rFr<rQr&rbrfrgtext isinstancer%decodesplitassertIn)rrYrfrgencodingcmlinerrrchecks *   zExceptionTests.checkcCs|j}|ddddS)Nz"\ "(1 for c in I,\ \)rrrrrrrr)test_error_offset_continuation_characterssz8ExceptionTests.test_error_offset_continuation_characterscCs@|j}|ddd|ddd|ddd|d dd |d dd |d dd dd|ddd|ddd|ddd|ddd|ddd|ddd|ddd|ddd|ddd|ddd|ddd|ddd |d!dd|d"dd|d#dd|d$ddd%d|d&d'd |d(dd|d)dd|d*d+trNd+nd,|d-dd.|d/dd|d0dd|d1dd|d2dd|d3dd|d4dd|d5dd|d6dd|d7dd|d8dd.|d9dd|d:dd|d;dd.|ddd.dS)?Nzdef fact(x): return x! r1z1 + r8z def spam(): print(1) print(2)rszPython = "Python" +uPython = "Ṕýţĥòñ" +s+# -*- coding: cp1251 -*- Python = "ϳ" +cp1251)rosPython = "ϳ" +zx = "azlambda x: x = 2z f{a + b + c}zclass foo:return 1 zdef f(): continuezdef f(): breakz4try: pass except: pass except ValueError: passz(0x+1)zx = 0xIz0010 + 2z x = 32e-+4zx = 0o9uα = 0xIsα = 0xIs## -*- coding: iso8859-7 -*- = 0xIz iso8859-7sif 1: def foo(): ''' def bar(): pass def baz(): '''quux''' z"pass pass pass (1+) pass pass passz(1+)s#coding: utf8 print('我') rz!x = [(yield i) for i in range(3)]zdef f(): from _ import *zdef f(x, x): passzdef f(x): nonlocal xzdef f(x): x = 1 global xz nonlocal xz def f(): global x nonlocal xz#from __future__ import doesnt_existzfrom __future__ import bracesz#x=1 from __future__ import divisionzfoo(1=2)zdef f(): x, y: intz[*x for x in xs]zfoo(x for x in range(10), 100)z (yield i) = 2zdef f(*): passzfor 1 in []: pass)rrr Zuse_old_parserrurrrtestSyntaxErrorOffsetsh                                     z$ExceptionTests.testSyntaxErrorOffsetcsjGdddtGdddfdd}fdd}fd d }tjd sf|||dS) Nc@seZdZddZdS)z9ExceptionTests.testSettingException..BadExceptioncSs tddS)Nzcan't instantiate BadException)r:)Zself_rrrrszBExceptionTests.testSettingException..BadException.__init__Nrrrrr BadExceptionsrc@s eZdZdS)z=ExceptionTests.testSettingException..InvalidExceptionNrrrrrrrInvalidExceptionsrc sddl}z|dWnZtyr}zBt\}}}|jj}|jd |j dWYd}~nd}~00 ddS)Nrr8 test_capi1test_exceptions.pyExpected exception) _testcapiraise_exceptionrBrHexc_infotb_framef_coder&co_name assertTrue co_filenameendswithrR)rr'r"tbcorrrrrs(z7ExceptionTests.testSettingException..test_capi1c sddl}z|dWnrty}zZt\}}}|jj}|jd |j d|jj j}|jdWYd}~nd}~00 ddS)Nrrr test_capi2r)rrr:rHrrrr&rrrrf_backrR)rr'r"rrZco2rrrr"s $z7ExceptionTests.testSettingException..test_capi2csddl}t|jddS)Nrr8)rrFr@r)r)rrrr test_capi30s z7ExceptionTests.testSettingException..test_capi3java)rrHplatform startswith)rrrrr)rrrrtestSettingException s  z#ExceptionTests.testSettingExceptioncCsztWntyYn0|tt|ttdd|ttdddtddd}||jd||jd|t|dtd ddd }||jd ||jd ||jd||j d||j d|t|d td ddd}||jd ||jd||jd||j d||j d|t|dtdd}||jd||jd||jd||j d||j ddS)NiZ1001messagez[Errno 1001] messagerfoobarz[Errno 9] foo: 'bar'rrsrwz[WinError 3] foo: 'bar'rtz[WinError 1001] foo) WindowsErrorr6assertIsr.r&r%errnowinerrorstrerrorfilename filename2)rr+rrrtest_WindowsError:sB    z ExceptionTests.test_WindowsErrorwin32ztest specific to WindowscCsLtd}d}|td||j|Wdn1s>0YdS)z:Should fill in unknown error code in Windows error messagectypeslcs@zWindows Error 0x%xN)r assertRaisesRegexr.Z pythonapiZPyErr_SetFromWindowsErr)rrcoderrrtest_windows_messageasz#ExceptionTests.test_windows_messagecCs tdddiftdddiftdddiftdddiftddddftdddddddftd d dddd dftd d d ddd dftd d d ddftddddddftdddddddftddddddddftdddddddddftddd 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(dd0ft dddd1ft dddd1fg}z"| t dddddddd2fWnt yYn0|D] \}}}z ||}Wn$td3||ftjd4Yn0t|jd5sD|t|jd6t|}|D]:}t||}|t|t||d7|||||fqPtfD]n} t| jdD]X} | || }| |} |D]6}tt| |} t||} || | d8||fqqqqdS)9Nrargs)r8)r)rr8r)rr)rrrrr)rrr)rrbazr)rrrNquuxr)rrr)errnoStr strErrorStr filenameStr)rrrrr)rrrr)r8rr)r8rr8)rrrrr)rZrjrrfrgprint_file_and_line)msgStrr)rrjrrZrrfrg)r)r linenoStr offsetStrtextStrrrr)rgrjrrrZrrf)rrrrrZprint_file_and_lineStr)rjrrrZrrfrg)asciiarr8ordinal not in rangerrrr)rroobjectstartreason)rrrr8r)あrr8ouchrr)rrrrend)rr)rrrrrrz exc=%r, args=%r)filerbuiltinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s) BaseExceptionrAr.r< UnicodeErrorUnicodeEncodeErrorUnicodeDecodeError bytearrayUnicodeTranslateErrorrrappendrr6printrHstderrtyperrr&rr%rGreprpicklerPHIGHEST_PROTOCOLdumpsrM)rZ exceptionListr"rZexpectedrWr`Z checkArgNamevaluepprotocolnewZgotZwantrrrtestAttributesks"     O        zExceptionTests.testAttributescCsz tdWntd}Yn0t|}||t||j|td|}||t||j|Gdddt}||}|||||j|dS)Nrxrwrc@s eZdZdS)z5ExceptionTests.testWithTraceback..MyExceptionNrrrrr MyExceptionsr) r0rHrrwith_tracebackassertIsInstancer& __traceback__r)rrrWrrrrtestWithTracebacks      z ExceptionTests.testWithTracebackc CsPz dt_Wn4ty@}z|dt|WYd}~nd}~00|ddS)Nrz!__traceback__ must be a tracebackzNo exception raised)rrrBrnr%rRrrWrrrtestInvalidTracebacks  &z#ExceptionTests.testInvalidTracebackcCsP|tttdd|tttd|tttdd|tttddS)N __cause__r8 __context__)rFrBsetattrrdelattrrrrrtestInvalidAttrsszExceptionTests.testInvalidAttrscCsJz tdWntd}Yn0t}||_d|_||jddS)Nrxrw)r0rHrrrr&)rrrWrrrtestNoneClearsTracebackAttr s z*ExceptionTests.testNoneClearsTracebackAttrcCsnt}||j||jt}||j||jGdddt}|}||j||jdS)Nc@s eZdZdS)z5ExceptionTests.testChainingAttrs..MyExceptionNrrrrrr sr)r assertIsNonerrrBr.)rrWrrrrtestChainingAttrss     z ExceptionTests.testChainingAttrsc Csz tWn(ty2}z|}WYd}~n d}~00||j||j||jt|_d|_||jt||j||jd|_||jdS)NF) rrrrZ assertFalse__suppress_context__r6rr)rr"rWrrrtestChainingDescriptors's      z&ExceptionTests.testChainingDescriptorscCs<|jttddGdddt}|dd}||jddS)Nr8)rc@seZdZddZdS)z8ExceptionTests.testKeywordArgs..DerivedExceptioncSst|||_dSr)rr fancy_arg)rrrrrr?s zAExceptionTests.testKeywordArgs..DerivedException.__init__NrrrrrDerivedException>sr*)r)rFrBrr&r)rrrrrrtestKeywordArgs9s zExceptionTests.testKeywordArgscs4fdd|tfdd|tdS)NcsSrrr)frrrHsz/ExceptionTests.testInfiniteRecursion..fcs"zWStyYdS0dS)NrrCrgrrrLs z/ExceptionTests.testInfiniteRecursion..g)rFr;rr)rrrtestInfiniteRecursionFs   z$ExceptionTests.testInfiniteRecursioncCs8|tt|ttd|ttdddS)Nrb)rr%rrrrrtest_strSszExceptionTests.test_strc CsNz tWn0ty:}z||~WYd}~n d}~00|dtdS)NrW)rrZ assertNotInlocalsrrrrtestExceptionCleanupNamesYs   z(ExceptionTests.testExceptionCleanupNamesc sGdddtGddd}fdd}|t}z |Wn$yj}z WYd}~n d}~00dt|||t}z |WnyYn0dt|||t}z |Wn Yn0dt|||t}dD]&}z |WnYqLYn0q$dt|||t}z z |WntYn0WnXty}z>d|_dt|tdd rt|WYd}~n d}~00|t}z |Wn<yFzzWn0Wny@Yn0Yn0dtdd r^t||Gd d d }|t}||Wdn1s0Ydtdd rt||dS) Nc@seZdZddZdS)z=ExceptionTests.testExceptionCleanupState..MyExceptioncSs ||_dSrobjrrrrrrhszFExceptionTests.testExceptionCleanupState..MyException.__init__Nrrrrrrgsrc@s eZdZdS)z7ExceptionTests.testExceptionCleanupState..MyObjNrrrrrMyObjjsrcs}dSrr)Z local_refrrrrinner_raising_funcmszDExceptionTests.testExceptionCleanupState..inner_raising_func)rF)Zcpythonc@seZdZddZddZdS)z9ExceptionTests.testExceptionCleanupState..ContextcSs|Srrrrrr __enter__szCExceptionTests.testExceptionCleanupState..Context.__enter__cSsdS)NTr)rexc_type exc_valueexc_tbrrr__exit__szBExceptionTests.testExceptionCleanupState..Context.__exit__N)rrrrrrrrrContextsr)rweakrefrefrrr2rr)rrrwrrWirrrrtestExceptionCleanupStatecs                        & z(ExceptionTests.testExceptionCleanupStatec sDfdd}ztWn*ty>z|WYdn d00dS)NcsdSrrrrWrr print_errorszIExceptionTests.test_exception_target_in_nested_scope..print_error)Z somethingr)rrrrr%test_exception_target_in_nested_scopes  z4ExceptionTests.test_exception_target_in_nested_scopecCsdd}|}|t|t|tdd|t|t|tdd|t|dz tdWnty|}|t|t|tdt|t|t|tdt|t|t~|tdtYn0dS)NcssNz tdWn.ty:tdVtdVYn0tdVdS)NZcaughtr)r2rHrrrrr yield_raises   z:ExceptionTests.test_generator_leaking..yield_raiserr)r&nextr2rHrrB)rr rrrrtest_generator_leakings$  z%ExceptionTests.test_generator_leakingcCsfdd}ztWn ty0|}t|Yn0z t|WntyPYn0|tddS)Ncss dVdSrrrrrrrsz1ExceptionTests.test_generator_leaking2..gNNN)r:r  StopIterationr&rHrrritrrrtest_generator_leaking2s   z&ExceptionTests.test_generator_leaking2c Csdd}|}t|z ddWnbty}zJ|td|||}|td||||WYd}~n d}~00|tddS)Ncss0z dVWn ty*tdVYn0dSNr8rDrHrrrrrrs  z1ExceptionTests.test_generator_leaking3..gr8rr )r rDrrHrthrowr&)rrrrWZgen_excrrrtest_generator_leaking3s  "z&ExceptionTests.test_generator_leaking3c Csdd}|}ztWnty0t|}Yn0||tz t|Wn8ty}z |td|WYd}~n d}~00|tddS)Ncss4z ddWn"ty.tdVYn0dS)Nr8rrrrrrr*s   z1ExceptionTests.test_generator_leaking4..gr8r )rBr rrDrHrr&)rrrtprWrrrtest_generator_leaking4's   *z&ExceptionTests.test_generator_leaking4csHfdd}|}ztWnty4t|Yn0tt|dS)Nc3s.tdtdVtddS)Nr8r )rrHrr:r&rrrrrCsz>ExceptionTests.test_generator_doesnt_retain_old_exc..g)r:r rFrrrrr$test_generator_doesnt_retain_old_excBs  z3ExceptionTests.test_generator_doesnt_retain_old_exccs4ddfdd}|t|tddS)Ncss dVdSrrrrrr simple_genPszIExceptionTests.test_generator_finalizing_and_exc_info..simple_gencs.}ztWnty(t|YS0dSr)r:r )genrrrrun_genRs  zFExceptionTests.test_generator_finalizing_and_exc_info..run_genr )rr&rHr)rrrrr&test_generator_finalizing_and_exc_infoNs  z5ExceptionTests.test_generator_finalizing_and_exc_infocstGdddtGddd}fdd}|t}|}t|||d}t||dS)Nc@seZdZddZdS)zFExceptionTests._check_generator_cleanup_exc_state..MyExceptioncSs ||_dSrrrrrrr`szOExceptionTests._check_generator_cleanup_exc_state..MyException.__init__Nrrrrrr_src@s eZdZdS)z@ExceptionTests._check_generator_cleanup_exc_state..MyObjNrrrrrrbsrc3s*z Wny$dVYn0dSrrrrrr raising_genes  zFExceptionTests._check_generator_cleanup_exc_state..raising_gen)rrrr rr)rZtestfuncrrrrrrr"_check_generator_cleanup_exc_state\s z1ExceptionTests._check_generator_cleanup_exc_statecCsdd}||dS)NcSs(z|tWnty"Yn0dSr)rr:rrrrdo_throwvs zGExceptionTests.test_generator_throw_cleanup_exc_state..do_throwr)rr rrr&test_generator_throw_cleanup_exc_stateusz5ExceptionTests.test_generator_throw_cleanup_exc_statecCsdd}||dS)NcSs |dSr)rJrrrrdo_close~szGExceptionTests.test_generator_close_cleanup_exc_state..do_closer!)rr#rrr&test_generator_close_cleanup_exc_state}sz5ExceptionTests.test_generator_close_cleanup_exc_statecCsdd}||dS)NcSsd}dSrrrrrrdo_delszCExceptionTests.test_generator_del_cleanup_exc_state..do_delr!)rr%rrr$test_generator_del_cleanup_exc_statesz3ExceptionTests.test_generator_del_cleanup_exc_statecsfdd}|dS)Ncs.z t|WntyYn 0ddSNz should have raised StopIteration)r rrRrrrrdo_nexts   zEExceptionTests.test_generator_next_cleanup_exc_state..do_nextr!)rr(rrr%test_generator_next_cleanup_exc_states z4ExceptionTests.test_generator_next_cleanup_exc_statecsfdd}|dS)Ncs0z|dWnty Yn 0ddSr')sendrrRrrrrdo_sends  zEExceptionTests.test_generator_send_cleanup_exc_state..do_sendr!)rr+rrr%test_generator_send_cleanup_exc_states z4ExceptionTests.test_generator_send_cleanup_exc_statecsHGfddd}dzt|Wn Yn0t|ddS)NcseZdZfddZdS)z*ExceptionTests.test_3114..MyObjectcs tdSr)rHrrrrr__del__sz2ExceptionTests.test_3114..MyObject.__del__Nrrrr-rrrrMyObjectsr/rr )rrr&)rr/rrr test_3114szExceptionTests.test_3114c CsGdddt}Gdddt}Gdddt}zz|Wn|y}z|}z|Wn|y}z|}z|Wnx|y}z`|} |||||||| |||j||j||| j||WYd}~n d}~00WYd}~n d}~00WYd}~n d}~00Wn*|yH} z| } WYd} ~ n d} ~ 00|| |||j| || j|||jdS)Nc@s eZdZdS)zHExceptionTests.test_raise_does_not_create_context_chain_cycle..ANrrrrrAsr1c@s eZdZdS)zHExceptionTests.test_raise_does_not_create_context_chain_cycle..BNrrrrrBsr2c@s eZdZdS)zHExceptionTests.test_raise_does_not_create_context_chain_cycle..CNrrrrrCsr3)rrrrr) rr1r2r3Za_rZb_rZc_crWr"rrr.test_raise_does_not_create_context_chain_cycles:    J z=ExceptionTests.test_raise_does_not_create_context_chain_cyclec Csldd}z |Wn(ty:}z|}WYd}~n d}~00||t||jt||jj|jdS)Nc SsDz tdWn2ty>}z||_tdWYd}~n d}~00dSNr8rw)rCrrB)exrrrcycles  zBExceptionTests.test_no_hang_on_context_chain_cycle1..cycle)rrrBrrCr)rr8rWr"rrr$test_no_hang_on_context_chain_cycle1s  z3ExceptionTests.test_no_hang_on_context_chain_cycle1c Cs<Gdddt}Gdddt}Gdddt}||}z |Wn|y}z|}z |Wnf|y}zN|}z |Wn2|y} z| } | |_| WYd} ~ n d} ~ 00WYd}~n d}~00WYd}~n d}~00Wdn1s0Y||j| || j|||j|||j| dS)Nc@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle2..ANrrrrrr1sr1c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle2..BNrrrrrr2sr2c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle2..CNrrrrrr3sr3rrFrrrb) rr1r2r3rp_ar_br_cr4rrr$test_no_hang_on_context_chain_cycle2s,    dz3ExceptionTests.test_no_hang_on_context_chain_cycle2cCsGdddt}Gdddt}Gdddt}Gdddt}Gd d d t}||}z |Wn|y@}z|}z |Wn|y*} z| } z |Wnn|y} zT| } | |_z |Wn2|y} z| }|}|WYd} ~ n d} ~ 00WYd} ~ n d} ~ 00WYd} ~ n d} ~ 00WYd}~n d}~00Wdn1sX0Y||j|||j|||j| || j| || j|||j| dS) Nc@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle3..ANrrrrrr1 sr1c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle3..BNrrrrrr2sr2c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle3..CNrrrrrr3sr3c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle3..DNrrrrrDsr?c@s eZdZdS)z>ExceptionTests.test_no_hang_on_context_chain_cycle3..ENrrrrrEsr@r:)rr1r2r3r?r@rpr;rr<rr=r4Z_ddrWrrr$test_no_hang_on_context_chain_cycle3 s>     |z3ExceptionTests.test_no_hang_on_context_chain_cycle3cCsftddddd}|t|dd|_|t|dd|_d |_|t|d d |_|t|d d |_|t|dtddddd}|t|dd|_|t|dd|_d |_|t|dd |_|t|dd |_|t|dtdddd}|t|dd|_|t|dd|_d |_|t|dd |_|t|ddS)NrZxxxxxr8rrz8'baz' codec can't encode characters in position 1-4: foorwz<'baz' codec can't encode character '\x78' in position 1: foolESh MQ)EzJ'baz' codec can't encode characters in position 1-4: 965230951443685724997izK'4000' codec can't encode characters in position 1-4: 965230951443685724997izN'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) rr&r%rrrorrr)rurrrtest_unicode_change_attributes8s>z-ExceptionTests.test_unicode_change_attributescCs.tttf}|D]}|t||dqdS)N)rrrr&r%__new__)rZklassesklassrrrtest_unicode_errors_no_object]s z,ExceptionTests.test_unicode_errors_no_objectc sGdddt}Gdddt|d}tx}z tWnR|yd}z|dWYd}~n8d}~0tytYn |dYn 0|dWdn1s0Yfdd \}}}||tt||d t|dS) Nc@seZdZddZdS)z/ExceptionTests.test_badisinstance..MetacSs tdSrr)clssubclassrrr__subclasscheck__hszAExceptionTests.test_badisinstance..Meta.__subclasscheck__N)rrrrKrrrrMetagsrLc@s eZdZdS)z6ExceptionTests.test_badisinstance..MyExceptionNrrrrrrjsr) metaclassz%exception should not be a MyExceptionzShould have raised KeyErrorcs(zWSty"tYS0dSr)r;rHrrrrrrys z,ExceptionTests.test_badisinstance..gz maximum recursion depth exceeded) rrrr2rRrr;rnr%)rrLrrrWvrrrrtest_badisinstancecs   (  z!ExceptionTests.test_badisinstancecCsdd}|tdS)NcSst}tdD] }|j}qdS)Ni@B)rrP__dir__)orrrrrs z3ExceptionTests.test_trashcan_recursion..foo)r r)rrrrrtest_trashcan_recursionsz&ExceptionTests.test_trashcan_recursioncCsPdt}tdd|\}}}||d|d||d||d|dS)Naif 1: import sys from _testinternalcapi 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-Wd-cr8sRecursionErrorsResourceWarningDone.)__file__r assert_python_failurer&rnrrrcoutr'rrr$test_recursion_normalizing_exceptions ()   z3ExceptionTests.test_recursion_normalizing_exceptioncCs>d}td|\}}}||d|d||d|dS)Nzif 1: import _testcapi try: raise _testcapi.RecursingInfinitelyError finally: print('Done.') rSr8sORecursionError: maximum recursion depth exceeded while normalizing an exceptionrT)r rVr&rnrWrrr-test_recursion_normalizing_infinite_exceptions z0YdS)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) rSsmFatal Python error: _PyErr_NormalizeException: Cannot recover from MemoryErrors while normalizing exceptions.)r r rVrnrWrrr)test_recursion_normalizing_with_no_memorys  z8ExceptionTests.test_recursion_normalizing_with_no_memorycs@ddlddlmfdd}|}|}||dS)Nrraise_memoryerrorc sJz Wn*ty4}z|j}WYd}~nd}~00d|S)Nz Should have raises a MemoryError)r5rrR format_tb)rWrr^r tracebackrr raiseMemErrors   z6ExceptionTests.test_MemoryError..raiseMemError)rarr^r&)rrbZtb1Ztb2rr`rtest_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..CNrrrrrr3"sr3z_testcapi.error4z_testcapi.error5rErr8)rrFr@Zmake_exception_with_docrrr issubclassrr__doc__r&rr) rrZdoc2Zdoc4rdZerror2Zerror3r3Zerror4Zerror5rrrtest_exception_with_doc s:    z&ExceptionTests.test_exception_with_docc sddlmGddddfdd}z |Wn2tyj}z|dWYd}~nd}~00|dt|ddS)Nrr]c@s eZdZdS)z3ExceptionTests.test_memory_error_cleanup..CNrrrrrr36sr3cs}t|dSrrrr4r3r^rrrinner9s z7ExceptionTests.test_memory_error_cleanup..innerzMemoryError not raised)rr^r5assertNotEqualrRrr&)rrlrWrrkrtest_memory_error_cleanup1s  $ z(ExceptionTests.test_memory_error_cleanupc sGddddfddz Wn2ty^}z|dWYd}~nd}~00|dt|ddS)Nc@s eZdZdS)z6ExceptionTests.test_recursion_error_cleanup..CNrrrrrr3Ksr3cs}t|dSrrirjr3rlrrrrlNs z:ExceptionTests.test_recursion_error_cleanup..innerzRecursionError not raised)r;rmrRrr&rrrortest_recursion_error_cleanupHs $ z+ExceptionTests.test_recursion_error_cleanupcCsN|t}ttWdn1s*0Y||jjtj|jdSr) rFr.oslistdirrUr&rbrENOTDIR)rrprrrtest_errno_ENOTDIR]s (z!ExceptionTests.test_errno_ENOTDIRcCshGddd}|}t8}~t||jj|j||jjWdn1sZ0YdS)Nc@seZdZddZdS)z1ExceptionTests.test_unraisable..BrokenDelcSstd}|dS)Nz del is brokenrrr"rrrr-fsz9ExceptionTests.test_unraisable..BrokenDel.__del__Nr.rrrr BrokenDelesrv) r Zcatch_unraisable_exceptionrr&Z unraisablerr-ZassertIsNotNone exc_traceback)rrvrrprrrtest_unraisablecs zExceptionTests.test_unraisablec CsttfD]}||z|d}|WnF|ynt}tjtWdn1s`0YYn0|}|d||d|||j ||tur|d|n |d|| | dWdq1s0YqdS)Nz test messagerz raise exczri) rCrr$rrH__excepthook__rgetvaluernrrr)rrr"rreportrrrtest_unhandledss    2   zExceptionTests.test_unhandledcCsFd}tddD]2}td||\}}}||d|d|qdS)Nzif 1: import _testcapi class C(): pass _testcapi.set_nomemory(0, %d) C() r8ryrS)r8xs MemoryError)rPr rVrn)rrrrXrYr'rrr"test_memory_error_in_PyErr_PrintExs   z1ExceptionTests.test_memory_error_in_PyErr_PrintExcsxGdddtGdddtfdd}|}|d||Wdn1sj0YdS)Nc@s eZdZdS)zBExceptionTests.test_yield_in_nested_try_excepts..MainErrorNrrrrr MainErrorsrc@s eZdZdS)zAExceptionTests.test_yield_in_nested_try_excepts..SubErrorNrrrrrSubErrorsrc 3sBz Wn2y<z dVWny4Yn0Yn0dSrrrrrrrmains    z=ExceptionTests.test_yield_in_nested_try_excepts..main)rr*rFr)rrcororrr test_yield_in_nested_try_exceptss   z/ExceptionTests.test_yield_in_nested_try_exceptscsRfdd}|}ztWn"ty<t|dYn0t|ddS)Nc3s<ztWnty dVYn0tddVdS)Nr8r rw)rCr&rHrrrrrrs   z?ExceptionTests.test_generator_doesnt_retain_old_exc2..gr8rw)r0r&r )rrrrrr%test_generator_doesnt_retain_old_exc2s  z4ExceptionTests.test_generator_doesnt_retain_old_exc2cCsfdd}|t@|}z ddWnt|t|Yn0Wdn1sX0YdS)NcssdVdVdSr6rrrrrrsz1ExceptionTests.test_raise_in_generator..gr8r)rFrDr )rrrrrrtest_raise_in_generators  z&ExceptionTests.test_raise_in_generatorFz Won't work if __debug__ is Falsec Cs\tazWnBtyJ}z*b||t|t|dWYd}~nd}~00b|ddS)NZhellor)rBAssertionErrorrrr&r%rRrrrrtest_assert_shadowings &z$ExceptionTests.test_assert_shadowingc CsGdddt}ztWn(ty@}z|}WYd}~n d}~00z|Wnty\Yn0tdD]8}ztWn$ty}z WYd}~n d}~00tqfdS)Nc@s eZdZdS)zBExceptionTests.test_memory_error_subclasses..TestExceptionNrrrrr TestExceptionsrr1)r5rrPr)rrr"inst_rrrtest_memory_error_subclassess   z+ExceptionTests.test_memory_error_subclassesN)rd)Errrr(rXrarcrrrvrrrrunittestZ skipUnlessrHrrrrrrrrrrrrrrrr r rrrrrrr"r$r&r)r,r0r5r9r>rBrDrHrOrRrZr[r\rcrhrnrprtrxr|r~rrrrrrrrrr!"s T B /'  ~    y    ($/%   :    '     r!c@s,eZdZddZddZddZddZd S) ImportErrorTestscCstd}||j||jtddd}||jd||jtddd}||jd||jtdddd}||jd||jdd}|t|tdd d Wdn1s0Y|t|tdd d d Wdn1s0Y|t|tdd d dWdn1s@0Y|t|td d Wdn1sx0Y|t|tdd ddWdn1s0YdS)NtestZ somemodulenamesomepathpathsomename)rrz8'invalid' is an invalid keyword argument for ImportErrorkeyword)invalidr)rrr)rrT)rZanother)r/rrrr&rrB)rr"rZrrrtest_attributess.      *..*z ImportErrorTests.test_attributescCstdddd}||jd||jd||jd||jd|||jd||jd||jd||jddS)Nrrrrrrr)r/r&rrZrrrrurrrtest_reset_attributes$sz&ImportErrorTests.test_reset_attributescCsTtdtfdd0d}t|}|t|t|Wdn1sF0YdS)NrET)quietsabc)r BytesWarningr/r&r%)rargr"rrrtest_non_str_argument2sz&ImportErrorTests.test_non_str_argumentcCsttddtddtdddfD]}td i|}ttjdD]R}tt||}||jd||j d||j |j ||j |j qBt j t j fD]H}||}||jd||j d||j |j ||j |j qq"dS) Nrrrrrrr8r)r)dictr/rPrrrMrr&rrZrrcopydeepcopy)rkwargsZorigprotor"r4rrrtest_copy_pickle9s$ z!ImportErrorTests.test_copy_pickleN)rrrrrrrrrrrrs"r__main__)rgcrqrHrrrrZ test.supportrrrrrrrr r r r rr rrrrZTestCaser!rrrrrrrs64 iM