Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@s�dZddlZddlmZddlZddlmZddlmZmZm	Z	yddl
mZWn!ek
r�ddlmZnXej
e�Zdefd��YZd	efd
��YZdefd��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.
i�N(tHandler(tPlugin(tanyptlntsafe_str(tStringIOt	FilterSetcBsVeZd�Zd�Zee�Zd�Zd�Zee�Zd�Zd�ZRS(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}|jd�r=|j|d�q|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�|kp�j|d�S(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					tMyMemoryHandlercBsGeZd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(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|j�S(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
LogCapturecBs�eZdZeZdZdZdZdZdZ
eZdgZ
d�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�ZRS(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
logcapturei�s$%(name)s: %(levelname)s: %(message)ss-nosecCs.|jdddd|j|j�dddd�|jd	dd
ddd|jd�p_|jd
ddd�|jddd
ddd|jd�p�|jd
ddd�|jddd
ddd|jd�d
ddd�|jddddtdddd�|jddd
dddddd �d!S("s&Register commandline options.
        s--nologcapturetactiontstore_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_LOGDATEFMTs�Specify custom date/time format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGDATEFMT]s--logging-filtertlogcapture_filterstNOSE_LOGFILTERtFILTERs�Specify 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	configure�s		cCstj�}|jr�t|d�rHx!|jD]}|j|�q.WnxStjjjj	�D]9}t|d�r^x!|jD]}|j|�q}Wq^q^Wnx4|jD](}t
|t�r�|jj|�q�q�W|j
|j�t|dd�}|jtt|��dS(NthandlersR\RO(R#t	getLoggerR[thasattrR_t
removeHandlertLoggertmanagert
loggerDicttvaluest
isinstanceR"tremovet
addHandlerthandlertgetattrtsetLevel(R
troot_loggerRjtloggerR\((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytsetupLoghandler�s	cCs|j�dS(s7Set up logging handler before test run begins.
        N(tstart(R
((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytbegin�scCs,t|j|j|j�|_|j�dS(N(R"R(R)R*RjRo(R
((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRp�scCsdS(N((R
((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pytend�scCs|j�dS(s0Clear buffers and handlers before test.
        N(Ro(R
ttest((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt
beforeTest�scCs|jj�dS(s"Clear buffers after test.
        N(RjR/(R
Rs((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt	afterTest�scCs|j||�S(s5Add captured log messages to failure output.
        (tformatError(R
Rsterr((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt
formatFailure�scCsE|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.pyRv�s
cCstt|jj�S(N(RRRjR'(R
((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyRy�scCs0djt|�td�g|td�g�S(Ns
s>> begin captured logging <<s>> 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*		.									
	(R�R#RR8tnose.plugins.baseRt	nose.utilRRRt	cStringIORtImportErrorR`RtlogtobjectRR"R;(((s;/sys/lib/python2.7/site-packages/nose/plugins/logcapture.pyt<module>s
*

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.