J9Qc@sdZddlZddlmZddlZddlmZddlmZmZm Z yddl m Z Wn!e k rddl m Z nXej eZdefdYZd efd YZd efd YZdS( s This plugin captures logging statements issued during test execution. When an error or failure occurs, the captured log messages are attached to the running test in the test.capturedLogging attribute, and displayed with the error failure output. It is enabled by default but can be turned off with the option ``--nologcapture``. You can filter captured logging statements with the ``--logging-filter`` option. If set, it specifies which logger(s) will be captured; loggers that do not match will be passed. Example: specifying ``--logging-filter=sqlalchemy,myapp`` will ensure that only statements logged via sqlalchemy.engine, myapp or myapp.foo.bar logger will be logged. You can remove other installed logging handlers with the ``--logging-clear-handlers`` option. iN(tHandler(tPlugin(tanyptlntsafe_str(tStringIOt FilterSetcBsVeZdZdZeeZdZdZeeZdZdZRS(cCs|j|\|_|_dS(N(t _partitiont inclusivet exclusive(tselftfilter_components((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt__init__!scCsXgg}}x>|D]6}|jdr=|j|dq|j|qW||fS(Nt-i(t startswithtappend(t componentsRR t component((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR%s   cCs'|s tS|j|o&|j| S(s-returns whether this record should be printed(tTruet_allowt_deny(R trecord((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytallow/scs%fd}ttt||S(sNreturn the bool of whether `record` starts with any item in `matchers`cs|kpj|dS(Nt.(R(tkey(R(s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytrecord_matches_key:s(Rtbooltmap(tmatchersRR((Rs;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt _any_match7scCs |js tS|j|j|S(N(RRR(R R((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR?s cCs |js tS|j|j|S(N(R tFalseR(R R((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRDs ( t__name__t __module__R Rt staticmethodRRRR(((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR s       tMyMemoryHandlercBsGeZdZdZdZdZdZdZdZRS(cCsHtj|tj||}|j|t||_g|_dS(N(RR tloggingt Formattert setFormatterRt filtersettbuffer(R t logformatt logdatefmttfilterstfmt((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR Ks   cCs|jj|j|dS(N(R'Rtformat(R R((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytemitQscCsdS(N((R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytflushSscCs g|_dS(N(R'(R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyttruncateUscCs|jj|jS(N(R&Rtname(R R((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytfilterWscCs|jj}|d=|S(Ntlock(t__dict__tcopy(R tstate((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt __getstate__YscCs#|jj|tj|_dS(N(R3tupdatet threadingtRLockR2(R R5((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt __setstate__]s( RR R R-R.R/R1R6R:(((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR"Js      t LogCapturecBseZdZeZdZdZdZdZdZ e Z dgZ dZdZdZd Zd Zd Zd Zd ZdZdZdZdZRS(s Log capture plugin. Enabled by default. Disable with --nologcapture. This plugin captures logging statements issued during test execution, appending any output captured to the error or failure output, should the test fail or raise an error. tNOSE_NOLOGCAPTUREt logcaptureis$%(name)s: %(levelname)s: %(message)ss-nosecCs.|jdddd|j|j dddd|jd dd dd d|jd p_|jd ddd|jddd ddd|jdp|jd ddd|jddd ddd|jdd ddd|jddddtdddd|jddd dddddd d!S("s&Register commandline options. s--nologcapturetactiont store_falsetdefaulttdestR=thelps]Disable logging capture plugin. Logging configurtion will be left intact. [NOSE_NOLOGCAPTURE]s--logging-formattstoretlogcapture_formattNOSE_LOGFORMATtmetavartFORMATsvSpecify custom format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGFORMAT]s--logging-datefmttlogcapture_datefmttNOSE_LOGDATEFMTsSpecify custom date/time format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGDATEFMT]s--logging-filtertlogcapture_filterstNOSE_LOGFILTERtFILTERsSpecify which statements to filter in/out. By default, everything is captured. If the output is too verbose, use this option to filter out needless output. Example: filter=foo will capture statements issued ONLY to foo or foo.what.ever.sub but not foobar or other logger. Specify multiple loggers with comma: filter=foo,bar,baz. If any logger name is prefixed with a minus, eg filter=-foo, it will be excluded rather than included. Default: exclude logging messages from nose itself (-nose). [NOSE_LOGFILTER] s--logging-clear-handlerst store_truetlogcapture_clears Clear all other logging handlerss--logging-leveltNOTSETtlogcapture_levelsSet the log level to captureN(t add_optiontgettenv_optR(R)R(R tparsertenv((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytoptionsrs6      cCs}||_|j s|jr(t|_n|j|_|j|_|j |_ |j |_ |j ry|j jd|_ndS(sConfigure plugin. t,N(tconfR=t loggingConfigRtenabledRDR(RHR)RNtclearRPtloglevelRJtsplitR*(R RVRX((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt configures       cCstj}|jrt|drHx!|jD]}|j|q.WnxStjjjj D]9}t|dr^x!|jD]}|j|q}Wq^q^Wnx4|jD](}t |t r|jj |qqW|j |jt|dd}|jtt|dS(NthandlersR\RO(R#t getLoggerR[thasattrR_t removeHandlertLoggertmanagert loggerDicttvaluest isinstanceR"tremovet addHandlerthandlertgetattrtsetLevel(R t root_loggerRjtloggerR\((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytsetupLoghandlers  cCs|jdS(s7Set up logging handler before test run begins. N(tstart(R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytbeginscCs,t|j|j|j|_|jdS(N(R"R(R)R*RjRo(R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRpscCsdS(N((R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytendscCs|jdS(s0Clear buffers and handlers before test. N(Ro(R ttest((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt beforeTestscCs|jjdS(s"Clear buffers after test. N(RjR/(R Rs((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt afterTestscCs|j||S(s5Add captured log messages to failure output. (t formatError(R Rsterr((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt formatFailurescCsE|j|_}|s|S|\}}}||j|||fS(s3Add captured log messages to error output. (tformatLogRecordstcapturedLoggingtaddCaptureToErr(R RsRwtrecordstectevttb((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRvs cCstt|jjS(N(RRRjR'(R ((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRyscCs0djt|tdg|tdgS(Ns s>> begin captured logging <> end captured logging <<(tjoinRR(R R~R|((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR{sN(RR t__doc__RRZRSR0tscoreR(tNoneR)RR[R*RVR^RoRqRpRrRtRuRxRvRyR{(((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyR;bs*  .         (RR#RR8tnose.plugins.baseRt nose.utilRRRt cStringIORt ImportErrorR`RtlogtobjectRR"R;(((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyts   *