{G_Tc@sddlZddlZddlZddlZddlZddlmZmZmZm Z m Z m Z ddl m Z dejfdYZdefdYZdejfd YZd Zed krendS( iN(tTESTFNtunlinkt run_unittesttcaptured_outputtcheck_warningst cpython_only(tignore_deprecation_warningstExceptionTestscBseZdZdZdZdZedZdZe dZ dZ dZ e d Z e d Zd Zd Zd ZdZdZdZdZdZdZRS(cCsUy*ddlm}ddl}||Wn$tk rP}|jd|nXdS(Ni(treloadsreloading exceptions: %s(timpRt exceptionst ImportErrortfail(tselfRR te((s0/usr/local/lib/python2.7/test/test_exceptions.pyt testReloads  cCsy |dWn|k r.}t|}nXy|dWn|k r`}t|}nX|j|||j|j|dS(Ntspam(tstrt assertEqualt__name__(R texctexcnameterrtbuf1tbuf2((s0/usr/local/lib/python2.7/test/test_exceptions.pyt raise_catchs cBs/|jed|jeeed|jedeed}|jeed}ej }z.y|e_ e }Wnek rnXWd|e_ |je eX|je d|je edd|je d|je ed |jed g}|je|jd |jed i}|je|jd |jed|jed|jedy e}Wnek rnX|jedd}xedD]}||7}qW|jed|jedy ddUWnek rnX|jed|jed|jed|jed|jeejd|jedy gd!Wnek rnX|je d|je e!d|je"dydd}Wne"k rnX|je#d ydd}Wne#k r*}nXdS("NtAttributeErrortundefined_attributetEOFErrortwtrtIOErrorsthis file does not existR tundefined_modulet IndexErrori tKeyErrortkeytKeyboardInterruptt MemoryErrort NameErrort OverflowErroriit RuntimeErrort SyntaxErrors/ tIndentationErrortTabErrort SystemErrort SystemExitit TypeErrort ValueErrori'tZeroDivisionErrort Exception(($RRt assertRaisestgetattrtsysRtopenRtclosetstdint raw_inputRRR t __import__R!t __getitem__R"R$R%R&tundefined_variableR'trangeR(R)R*R+R,R-texitR.R/tchrR0R1(R tfpt savestdintxtdummyR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt testRaising&s               cs[fd}d}tjjds7||dnd}||d|dddS(Ncsgyt|ddWn?tk rU}|j|krcjd||jfqcnXjddS(Ns texecsexpected %s, got %ss"failed to get expected SyntaxError(tcompileR)tmsgR (tsrcRFR(R (s0/usr/local/lib/python2.7/test/test_exceptions.pytckmsg{s !s\while 1: try: pass finally: continuetjavas0'continue' not supported inside 'finally' clausesHif 1: try: continue except: passs'continue' not properly in loops continue (R4tplatformt startswith(R RHts((R s0/usr/local/lib/python2.7/test/test_exceptions.pyttestSyntaxErrorMessagews  cs^dddYfd}fd}tjjdsZ||ndS(Nt BadExceptioncBseZdZRS(cSs tddS(Nscan't instantiate BadException(R((tself_((s0/usr/local/lib/python2.7/test/test_exceptions.pyt__init__s(Rt __module__RP(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRNscsddl}y|jdWnktk r}tj\}}}|jj}j|jdj |j j dt j dnXjddS(Niit test_capi1ttest_exceptionstpysExpected exception(t _testcapitraise_exceptionR.R4texc_infottb_frametf_codeRtco_namet assertTruet co_filenametendswithtostextsepR (RURRttbtco(RNR (s0/usr/local/lib/python2.7/test/test_exceptions.pyRRs  (csddl}y|jdWntk r}tj\}}}|jj}j|jdj |j j dt j d|jjj}j|jdnXjddS(NiiRPRSRTt test_capi2sExpected exception(RURVR(R4RWRXRYRRZR[R\R]R^R_tf_backR (RURRR`Ratco2(RNR (s0/usr/local/lib/python2.7/test/test_exceptions.pyRbs  $RI((R4RJRK(R RRRb((RNR s0/usr/local/lib/python2.7/test/test_exceptions.pyttestSettingExceptions  cCsytWntk rntX|jttdd|jttddd|jtddjd|jtddjddS(Nit1001tmessages[Error 1001] messagei(t WindowsErrorR&RRterrnotwinerror(R ((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_WindowsErrors c Cs.td+idd6d,d6ftd-idd6d.d6ftd/idd6d0d6ftd1idd6d2d6ftd3idd6d4d6dd6ftd5idd6d6d6dd6dd6dd 6ftd7idd6d8d6dd6dd6d d 6ftd9idd6d:d6d d6dd6d d 6ftd;idd6d<d6ftd=idd6d>d6dd 6d d6dd6ftd?idd6d@d6dd6dd 6dd6ftdAidd6dd6dd6dd6dd6dd6dd6ftdBidd6dCd6dd6dd6dd6dd6dd6dd6ftddDfidd6dd6dd6ddEfd6dd6dd6dd6dd6ftdFidd6dd6dGd6dd6dd6dd6dd6dd6ftdHidd6dId6ftdJidd6dKd6dd6dd6dd 6dd!6ftdLidd6dMd6dd6d"d6dd 6dd!6ft dNidd6dOd6d#d6d$d!6dd 6dd%6fg}yD|j t dPidd6dQd6dd 6dd&6d'd6dd6fWnt k rnXxj|D]b\}}}y||Wqtk r%}t ||k r n|jt |jd(t|}xJ|D]B}|jtt||t||d)t||fq9WxttfD]}xt|jdD]t} |j|j|| } xP|D]H}tt| |} t||} |j| | d*||fqWqWqWqXqWdS(RNtRgtargsitfootcodetfilenameRitstrerrortbartbaztquuxterrnoStrt strErrorStrt filenameStrRFttexttlinenotoffsettprint_file_and_linetmsgStrt linenoStrt offsetStrttextStrtprint_file_and_lineStrtasciiuaisordinal not in rangetencodingtobjecttstarttreasonsuあtouchtendRjiR sexception "%s", attribute "%s"spickled "%r", attribute "%s"(((i(i(Rn(Rn(Rni(Rni(Rn(Rn(Rn(Rn(RnRr(RnRr(RnRrRs(RnRr(RnRrRsRt(RnRrRsRt(RuRvRw(RuRv(iRvRw(iRv((R|(R|(RwR}R~R(RwR}R~R(R|RwR}R~RR(R|RwR}R~RR(((sasciiuaiisordinal not in range(sasciiuaiisordinal not in range(sasciisiisordinal not in range(sasciisiisordinal not in range(uあiiR(uあiiR(iRvRw(iRv(t BaseExceptionR-RtNonetEnvironmentErrorR)t UnicodeErrortUnicodeEncodeErrortUnicodeDecodeErrortUnicodeTranslateErrortappendRhR&ttypeRRQRtreprR3tpickletcPickleR<tHIGHEST_PROTOCOLtloadstdumps( R t exceptionListRRmtexpectedRRLt checkArgNametptprotocoltnewtgottwant((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestAttributess           cCsWtd}tdtf}|j|jdWdQX|jt|jddS(NRns:BaseException.message has been deprecated as of Python 2.6i(RRtDeprecationWarningRRgtlentwarnings(R RR((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestDeprecatedMessageAttribute4s  cCstd}d|_tdt}|j|jdWdQX|jt|jd|`|jt |jWdQXdS(NRnRrtquieti( RRgRtTrueRRRR2R(R RR((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestRegularMessageAttribute=s  cCstd}td}d|_xjttfD]\}|j|j|}|j|jd|j|j|}|j|jdq.WdS(NRnRr(R1RgRRRRR(R RtfRtepR?((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestPickleMessageAttributeJs   cCs;d}t|}|j|||j|j|dS(Niii(iii(RRRm(R RmR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt testSlicingVs cCsR|jttdddtfdY}|dd}|j|jddS(NtaitDerivedExceptioncBseZdZRS(cSstj|||_dS(N(RRPt fancy_arg(R R((s0/usr/local/lib/python2.7/test/test_exceptions.pyRPes (RRQRP(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRdsRi*(R2R.RRR(R RRA((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestKeywordArgs_sc sfd|jtfdtdDy Wn$tk rYn!|jdnX|jdWdQXdS(NcsS(N(((R(s0/usr/local/lib/python2.7/test/test_exceptions.pyRmscs$y SWntk rdSXdS(Ni(R/((tg(s0/usr/local/lib/python2.7/test/test_exceptions.pyRqs  tstderrsShould have raised KeyError(R2R(RR (R ((RRs0/usr/local/lib/python2.7/test/test_exceptions.pyttestInfiniteRecursionls   cCsu|jtt|jtt|jttd|jttd|jttddS(NRuauá(R[RR1tunicode(R ((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestUnicodeStrUsages cCstddddd}|jt|dd|_|jt|dd|_d |_|jt|d d |_|jt|d d |_|jt|dtddddd}|jt|dd|_|jt|dd|_d |_|jt|dd |_|jt|dd |_|jt|dtdddd}|jt|dd|_|jt|dd|_d |_|jt|dd |_|jt|ddS(NRsuxxxxxiiRns8'baz' codec can't encode characters in position 1-4: foois='baz' codec can't encode character u'\x78' in position 1: foolESh MQ)EsJ'baz' codec can't encode characters in position 1-4: 965230951443685724997isK'4000' codec can't encode characters in position 1-4: 965230951443685724997isN'4000' codec can't encode characters in position 1000-4: 965230951443685724997txxxxxs3'baz' codec can't decode bytes in position 1-4: foos5'baz' codec can't decode byte 0x78 in position 1: foosE'baz' codec can't decode bytes in position 1-4: 965230951443685724997sF'4000' codec can't decode bytes in position 1-4: 965230951443685724997sI'4000' codec can't decode bytes in position 1000-4: 965230951443685724997uxxxxs/can't translate characters in position 1-4: foos4can't translate character u'\x78' in position 1: foosAcan't translate characters in position 1-4: 965230951443685724997sDcan't translate characters in position 1000-4: 965230951443685724997( RRRRRRRRR(R tu((s0/usr/local/lib/python2.7/test/test_exceptions.pyttestUnicodeChangeAttributess>              cCsCtttf}x-|D]%}|jt|j|dqWdS(NRl(RRRRRt__new__(R tklassestklass((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_unicode_errors_no_objects c s dtfdYdtffdY}tdg}y tWnC|k rp}|jdn1tk rn!|jdnX|jdWdQXtdT}fd\}}}|j|tk||jd t|WdQXdS( NtMetacBseZdZRS(cSs tdS(N(R/(tclstsubclass((s0/usr/local/lib/python2.7/test/test_exceptions.pyt__subclasscheck__s(RRQR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRst MyExceptioncseZZRS((RRQt __metaclass__((R(s0/usr/local/lib/python2.7/test/test_exceptions.pyRsRs%exception should not be a MyExceptionsShould have raised KeyErrorcs*y SWntk r%tjSXdS(N(R(R4RW((R(s0/usr/local/lib/python2.7/test/test_exceptions.pyRs  s maximum recursion depth exceeded( RR1RR"R R[R(tassertInR(R RRRtvR`((RRs0/usr/local/lib/python2.7/test/test_exceptions.pyttest_badisinstances"  cCs6dtfdY}|jt |WdQXdS(NRcBseZdZRS(cWstS(N(R(RRm((s0/usr/local/lib/python2.7/test/test_exceptions.pyRs(RRQR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRs(R1R2R.(R R((s0/usr/local/lib/python2.7/test/test_exceptions.pyt!test_new_returns_invalid_instancescCsFytstdWn)tk rA}|jt|dnXdS(Nis(3,)(i(tFalsetAssertionErrorRR(R R((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_assert_with_tuple_argscsAdtffdY}t|dd_`dS(NtNastycseZfdZRS(cs `dS(N(Rg(Rg(R(s0/usr/local/lib/python2.7/test/test_exceptions.pyt__del__s(RRQR((R(s0/usr/local/lib/python2.7/test/test_exceptions.pyRsRF((RR/RmRg(R R((Rs0/usr/local/lib/python2.7/test/test_exceptions.pyttest_bad_exception_clearings (RRQRRRCRMRReRkRRRRRRRRRRRRRRR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRs( Q ' j    %  ! tExcWithOverriddenStrcBs eZdZdZdZRS(s|Subclass of Exception that accepts a keyword 'msg' arg that is returned by __str__. 'msg' won't be included in self.argscOs/|jd|_tt|j||dS(NRF(tpopRFtsuperRRP(R Rmtkwargs((s0/usr/local/lib/python2.7/test/test_exceptions.pyRPscCs|jS(N(RF(R ((s0/usr/local/lib/python2.7/test/test_exceptions.pyt__str__s(RRQt__doc__RPR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRs tTestSameStrAndUnicodeMsgcBseeZdZdZdZdZdZdZdZdZ dZ e d Z RS( sBunicode(err) should return the same message of str(err). See #6108cCs6|jt|||jt|t|dS(s>Helper function that checks if str(exc) == unicode(exc) == msgN(RRR(R RRF((s0/usr/local/lib/python2.7/test/test_exceptions.pytcheck_same_msgsc Cstddtddtdtd d d dd td d d dd g}x*|D]"}|jt|t|qXWdS(s&Check same msg for built-in exceptionssinvalid syntaxsiis2+*3isNo such file or directorys both should have the same quotesRsàisordinal not in range(128)uሴN(siis2+*3(R)RR"RRRRR(R R t exception((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_builtin_exceptionss     cCs|jtddS(s(Check same msg for Exception with 0 argsRlN(RR1(R ((s0/usr/local/lib/python2.7/test/test_exceptions.pyt test_0_argsscCsfx'dD]}|jtd||qWtdd}|jtt||jt|ddS(s@Check same msg for exceptions with 0 args and overridden __str__RnufooRFufööN(sfooufoo(RRR2RRRR(R RFR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt#test_0_args_with_overridden___str__s  cCs`x$dD]}|jt||qWtd}|jtt||jt|ddS(s(Check same msg for Exceptions with 1 argRnufooufööN(sfooufoo(RR1R2RRRR(R targR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt test_1_arg,s   cCslx*dD]"}|jtdd||qWtddd}|jtt||jt|ddS(s?Check same msg for exceptions with overridden __str__ and 1 argRnufooRRFufööN(sfooufoo(RRR2RRRR(R RFR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt"test_1_arg_with_overridden___str__8s   cCs@d d d g}x*|D]"}|jt|t|qWd S(s,Check same msg for Exceptions with many argsiRniufooRriufööubarRsN(isfoo(iufoosbar(iufööubarsbaz(RR1R(R targslistRm((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_many_argsEs   cCs~x6d D].}tdddd|}|j||qWtddddd}|jtt||jt|ddS( sCCheck same msg for exceptions with overridden __str__ and many argsRnufootarg1uarg2ufööRFuarg3N(sfooufoo(RRR2RRRR(R RFR((s0/usr/local/lib/python2.7/test/test_exceptions.pyt&test_many_args_with_overridden___str__Ps  c Csddl}d}d}|jt|jd|jd}|jt|t|jt|t|j |j |jd|}|j |j ||jdd|}|jt||d t fd Y}|jd |||f}|jt|||jt|||j |j ||jd d |idd6} |jt| ||j | j d|j | j d dS(NisThis is a test docstring.sThis is another test docstring.terror1s_testcapi.error1s_testcapi.error2s_testcapi.error3tbasetCcBseZRS((RRQ(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRxss_testcapi.error4s_testcapi.error5RliR(RUR2R,tmake_exception_with_doctassertIsRR[t issubclassR1t assertIsNoneRRRR( R RUtdoc2tdoc4Rterror2terror3Rterror4terror5((s0/usr/local/lib/python2.7/test/test_exceptions.pyttest_exception_with_doc_s2     ( RRQRRRRRRRRRRR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyRs    cCstttdS(N(RRR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyt test_mainst__main__(R^R4tunittestRRttest.test_supportRRRRRRttest.test_pep352RtTestCaseRR1RRRR(((s0/usr/local/lib/python2.7/test/test_exceptions.pyts   .