kWc@sddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl Z ddl Ze jdddgZe jdddgZed Zd ejfd YZd efd YZdeejfdYZdeejfdYZdefdYZdeefdYZdeefdYZdejfdYZdeefdYZdeefdYZdejfdYZd eefd!YZ d"eefd#YZ!d$efd%YZ"d&ejfd'YZ#d(ee#fd)YZ$d*ee#fd+YZ%d,efd-YZ&d.e&fd/YZ'd0e&fd1YZ(d2efd3YZ)d4e)fd5YZ*d6e)fd7YZ+d8Z,e-d9kre,ndS(:i(tcontextmanagerN(t test_support(tassert_python_oktwarningstblockedt _warningstfreshccsx9ttfD]+}y|jjWq tk r7q Xq WytjWntk r]nXtj}|j}z)||_|jd|t_dVWd|t_||_XdS(s8Use a specific warnings implementation in warning_tests.tonceN( tsyst warning_testst__warningregistry__tcleartAttributeErrort NameErrorRtfilterst simplefilter(tmoduletto_cleartoriginal_warningstoriginal_filters((s(/usr/lib/python2.7/test/test_warnings.pytwarnings_states$         tBaseTestcBs eZdZdZdZRS(s'Basic bookkeeping required for testing.cCssdtkrtd=nttdr4t`nttdrLt`n|jtjdRARFRGRHRJRMRR(((s(/usr/lib/python2.7/test/test_warnings.pyR2Us      t CFilterTestscBseZeZRS((RRR/R(((s(/usr/lib/python2.7/test/test_warnings.pyRSst PyFilterTestscBseZeZRS((RRR1R(((s(/usr/lib/python2.7/test/test_warnings.pyRTst WarnTestscBszeZdZdZdZdZdZeje e dddZ dZ d Z d Zd ZRS( s2Test warnings.warn() and warnings.warn_explicit().c Cstjdtd|j}|jjdxetdD]W}d|}|jj||jt|dj ||j |dj t kq;WWdQXdS(NR9RRismulti %di( RR(R;RRtrangeR"R<ROR@R)R4R5(RR7tiRQ((s(/usr/lib/python2.7/test/test_warnings.pyt test_messages c Cst|jtjdtd|jg}tjd|jtj j |dj dtj d|jtj j |dj dWdQXWdQXdS(NR9Rtspam1iswarning_tests.pytspam2( RRRR(R;R tinnerR<tostpathtbasenametfilenametouter(RR7((s(/usr/lib/python2.7/test/test_warnings.pyt test_filenames  c Cst|jmtjdtd|jK}tjddd|jtj j |dj dtj ddd|jtj j |dj dtjd dd |jtj j |dj d tj d dd |jtj j |dj dtj d dd|jtj j |dj d tjddd|jtj j |dj dWdQXWdQXdS(NR9Rtspam3t stackleveliiswarning_tests.pytspam4tspam5istest_warnings.pytspam6sspam6.5itspam7i'R( RRRR(R;R R[R<R\R]R^R_R`(RR7((s(/usr/lib/python2.7/test/test_warnings.pyttest_stacklevels*c Cstj}zqt`t|jVtjdtd|j4}tjddd|j|dj tj WdQXWdQXWd|t_XdS(NR9Rtspam8Rcii( R t__file__RRRR(R;R[R<R_R(RR_R7((s(/usr/lib/python2.7/test/test_warnings.pyttest_missing_filename_not_main s *targvstest needs sys.argvc Cstj}tj}z~t`dt_t|jZtjdtd|j8}tjddd|j |dj t j dWdQXWdQXWd|t_|t_XdS( Nt__main__R9Rtspam9Rciii( R RjRRRRR(R;R[R<R_RRl(RR_t module_nameR7((s(/usr/lib/python2.7/test/test_warnings.pyt$test_missing_filename_main_with_argvs   . c Cstj}tj}tj}z}t`dt_t`t|jStjdt d|j1}tj ddd|j |dj dWdQXWdQXWd|t_|t_|t_XdS(NRmR9Rtspam10Rcii( R RjRRRlRRRR(R;R[R<R_(RR_RoRlR7((s(/usr/lib/python2.7/test/test_warnings.pyt'test_missing_filename_main_without_argv+s    '  c Cstj}tj}tj}zt`dt_dgt_t|jStjdt d|j1}tj ddd|j |dj dWdQXWdQXWd|t_|t_|t_XdS( NRmRNR9Rtspam11Rcii( R RjRRRlRRRR(R;R[R<R_(Rt file_nameRoRlR7((s(/usr/lib/python2.7/test/test_warnings.pyt1test_missing_filename_main_with_argv_empty_string?s     '  c Csv|jt|jjdtdd|jt|jjdddd|jttf|jjdtdddddS(Nitregistryi*(R6t TypeErrorRR#tNoneR5R RI(R((s(/usr/lib/python2.7/test/test_warnings.pyttest_warn_explicit_type_errorsTs cCsCdtfdY}|jt|jj|WdQXdS(Nt BadStrWarningcBseZdZdZRS(s-Warning with a bad format string for __str__.cSsdidd6S(NsA bad formatted string %(err)sthere is no %(err)sterr((R((s(/usr/lib/python2.7/test/test_warnings.pyt__str__is(RRRR|(((s(/usr/lib/python2.7/test/test_warnings.pyRzgs(RIR6RDRR"(RRz((s(/usr/lib/python2.7/test/test_warnings.pyt test_bad_strcs(RRRRXRaRhRktunittestt skipUnlessRRRpRrRuRyR}(((s(/usr/lib/python2.7/test/test_warnings.pyRUs  $   t CWarnTestscBseZeZdZRS(cCs6|jt|jk|jt|jjddS(Nt func_code(t assertFalseRRRR"(R((s(/usr/lib/python2.7/test/test_warnings.pyttest_acceleratedvs(RRR/RR(((s(/usr/lib/python2.7/test/test_warnings.pyRqst PyWarnTestscBseZeZdZRS(cCs6|jt|jk|jt|jjddS(NR(RRRR)RR"(R((s(/usr/lib/python2.7/test/test_warnings.pyttest_pure_pythons(RRR1RR(((s(/usr/lib/python2.7/test/test_warnings.pyRzst WCmdLineTestscBs#eZdZdZdZRS(cCstjd|j|j|jj|jjd|j|jj|jjd|j|jj|jjd|jjd|jt|jjdWdQXdS(NRs 1:2:3:4:5:6sbogus::Warningsignore:2::4:-5serror::Warning::0sconvert to error(RR(RR6t _OptionErrort _setoptionR5R"(R((s(/usr/lib/python2.7/test/test_warnings.pyttest_improper_inputscCs/tddd\}}}|jd|dS(Ns-Wxxxs-ctpasss0Invalid -W option ignored: invalid action: 'xxx'(RtassertIn(RtrctoutR{((s(/usr/lib/python2.7/test/test_warnings.pyttest_improper_optionscCsBtddd\}}}|j|j|jd|dS(Ns-Wis-cs?import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)tRuntimeWarning(RRtstript assertNotIn(RRRR{((s(/usr/lib/python2.7/test/test_warnings.pyttest_warnings_bootstraps (RRRRR(((s(/usr/lib/python2.7/test/test_warnings.pyRs tCWCmdLineTestscBseZeZRS((RRR/R(((s(/usr/lib/python2.7/test/test_warnings.pyRstPyWCmdLineTestscBseZeZRS((RRR1R(((s(/usr/lib/python2.7/test/test_warnings.pyRst_WarningsTestscBsSeZdZeZdZdZdZdZdZ dZ dZ RS(s'Tests specific to the _warnings module.c Csytjd|j^}|jjddtdd|jt|jjd|j`|jt|jjdWdQXdS(NRR3RNisconvert to error( RR(RR&RIR6R5R"R(RR7((s(/usr/lib/python2.7/test/test_warnings.pyt test_filters c Csatd}zA|jj}iatjdtd|j}|jj|jjddt|jj |tdd|j |dj ||2|jj |tdd|j t |d i|j_ia|jj d|j |dj j|j|2|j`ia|jj |tdd|j t |d WdQXWd||j_XdS( Nsonceregistry testR9RRR4tfilei*ii(R5Rt onceregistryR RR(R;R'R&R#R<R@R=R"targs(RR@toriginal_registryR7((s(/usr/lib/python2.7/test/test_warnings.pyttest_onceregistrys.      c Cstd}|jj}zitjdtd|jH}|jji}|jj|tddd||j|dj ||jt |d|jt |d|2|j`i}i}|jj|tdd d||j|dj ||jt |d|jt |d|2d |j_i}i}|jj|tdd d||jt |d WdQXWd||j_XdS( Nsdefaultaction testR9Rsi*Rviii+R:i,i( R5Rt defaultactionRR(R;R'R#R<R@R=(RR@toriginalR7RvR ((s(/usr/lib/python2.7/test/test_warnings.pyttest_default_actions:      c Csd}tjd|jX|jjddt|j`tjd#}|jj||j }WdQXWdQX|j ||dS(Nsdel showwarning testRR?R4tstderr( RR(RR&R5R$Rtcaptured_outputR"tgetvalueR(RRQtstreamtresult((s(/usr/lib/python2.7/test/test_warnings.pyttest_showwarning_missings c Cs{tjd|j`|jjddt|jj}d|j_z|jt|jjdWd||j_XWdQXdS(NRR?R4isWarning!( RR(RR&R5R$R6RwR"(Rtold_showwarning((s(/usr/lib/python2.7/test/test_warnings.pyttest_showwarning_not_callables  c Csrd}tjd|jU|jjddt|j`tjd }tj ||j }WdQXWdQX|j |j ddd||j dd \}}tjjtjd d }|jd d }|\}} } } t| } |j |||j | dtj|j | d|dtj|| jd} | s^t|j || dS(Nstest show_warningRR?R4Rs isToo many newlines in %riis.pyt:it s (RR(RR&R5R$RRR R[RR<tcounttsplitR\R]tsplitextRjtrsplittintRt linecachetgetlineRtAssertionError( RRQRRt first_linet second_linet expected_filetfirst_line_partsR]tlinet warning_classR@t expected_line((s(/usr/lib/python2.7/test/test_warnings.pyttest_show_warning_outputs(      cCszt}|d}zUtjd|j:}|jjddtd|d<|jjdtWdQXWd||dsN        {  ,g