Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_log.pyc


pGNc@sdZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZde
fdYZde	jfd	YZd
efdYZdd d
YZdd!dYZdeefdYZdd"dYZdee	jfdYZdee	jfdYZde	jfdYZde	jfdYZde	jfdYZde	jfdYZdS(#s"
Tests for L{twisted.python.log}.
iN(tStringIO(tunittest(tlogtfailuretFakeWarningcBseZdZRS(s
    A unique L{Warning} subclass used by tests for interactions of
    L{twisted.python.log} with the L{warnings} module.
    (t__name__t
__module__t__doc__(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRstLogTestcBsbeZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
cCsBg|_|jj|_tj|j|jtj|jdS(N(tcatchertappendtobserverRtaddObservert
addCleanuptremoveObserver(tself((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytsetUps	cCs|j}tjddt|j}|j|ddd|j|dt|j|jd|jt|ddS(NttestttestShouldCatchtmessageittime(	R	RtmsgtTruetpoptassertEqualt
failUnlessthas_keytlen(RR	ti((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestObservation!s	cCs|j}tjidd6dd6dd6tjidd6tjddd	|j}|j|dd|j|dd|j|dd	|j|d
dddS(Nsnot the defaultt	subsystemtatsubsubsystemtctothertbtfootdRi(R	RtcallWithContextRRR(RR	R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestContext+s	cCs|xudttftjttfgD]I\}}tj||jj}|j|dd|j	|q+WdS(Nshello worldtisErrori(shello worldshello world(
tKeyErrorRtFailuretRuntimeErrorRterrR	RRtflushLoggedErrors(RtetigR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
testErrors8s%
cCsxdttftjttfgD]`\}}tj|d|jj}|j|dd|j|dd|j	|q+WdS(Nshello worldtfoobarR(itwhy(shello worldshello world(
R)RR*R+RR,R	RRR-(RR.R/R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestErrorsWithWhyAs%cCsg}g}d}x=|j||jgD]&}tj||jtj|q+WxtdD]}g|(g|(tjd|jt}|j	t
|d|j	t
|d|j	t
|d|j	|ddd	|j	|ddd
qbWdS(s
        Exceptions raised by log observers are logged but the observer which
        raised the exception remains registered with the publisher.  These
        exceptions do not prevent the event from being sent to other observers
        registered with the publisher.
        cSsdddS(Nii((tevents((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytbrokenUsis
Howdy, y'all.iiRiN(s
Howdy, y'all.(s
Howdy, y'all.(R
RRR
RtxrangeRR-tZeroDivisionErrorRR(RtL1tL2R5RRtexcs((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_erroneousErrorsLs 	

cs:ggtj}dtffdY}|}|j|j|j|j|jgz2|j}fd}||_|jdWd||_|j|j|jgX|jd|j|jd|jt	d|jd	d
d|jt	d|j
d	tdS(s
        If logging causes an error, make sure that if logging the fact that
        logging failed also causes an error, the log observer is not removed.
        tFailingObservercseZdZfdZRS(icsH|jd7_|jdkr7td|jfn
j|dS(NiisFailure #%s(tcallsR+R
(RRtkwargs(R4(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR}s(RRR=R((R4(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR<{scs j|jtddS(NsFake recursion error(R
tvalueR+(RR2R>(terrors(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
failingErrsserror in first observerNsbut this should succeediiiR(sbut this should succeed(RtLogPublishertobjectRRt	observerst_errRR=RtassertIsInstanceR+(Rt	publisherR<RtoldErrorRA((R@R4s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%test_doubleErrorDoesNotRemoveObserverrs(
				
cCstj}|j|j|jtdtdd|jj}|j|d|d|j|jg|jtdtdddt	|jj}|j|d|d|j|jgdS(sy
        L{twisted.python.log.showwarning} emits the warning as a message
        to the Twisted logging system.
        sunique warning messageswarning-filename.pyitformatsQwarning-filename.py:27: twisted.test.test_log.FakeWarning: unique warning messagetlineN(
RRBRRtshowwarningRR	RRRC(RRGtevent((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_showwarnings$
c	Csd}t}d}d}t}tj||||d||j|jtj||||tj	d
krd}t}tj||||d|d||j|jtj|||||nd	S(s
        L{twisted.python.log.showwarning} passes warnings with an explicit file
        target on to the underlying Python warning system.
        sanother unique messageswarning-filename.pyitfileiishello worldRKN(ii(
RRRRLRtgetvaluetwarningst
formatwarningtsystversion_info(RRtcategorytfilenametlinenotoutputRK((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_warningToFiles$				csgfd}d}tj}|j||j||jd|j|j||g|jtd|jdtdS(sk
        Log publisher does not use the global L{log.err} when reporting broken
        observers.
        cs*|jdr&j|djndS(NR(R(tgetR
R?(t	eventDict(R@(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytlogErrorscSstddS(Nt*test_publisherLocalyReportsBrokenObservers(R+(R[((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytfailssHello!iiN(	RRBRRRRDRRFR+(RR\R^RG((R@s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt-test_publisherReportsBrokenObserversPrivatelys	


(RRRRR'R0R3R;RIRNRYR_(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRs		
	
				&	3	 	tFakeFilecBseZdZdZRS(cCs|j|dS(N(R
(Rtbytes((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytwritescCsdS(N((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytflushs(RRRbRc(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR`s	tEvilStrcBseZdZRS(cCsdddS(Nii((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt__str__s(RRRe(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRdstEvilReprcBseZdZdZRS(cCsdS(NsHappy Evil Repr((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRescCsdddS(Nii((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt__repr__
s(RRReRg(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRfs	tEvilReprStrcBseZRS((RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRh
stLogPublisherTestCaseMixincBseZdZdZRS(cCst|_tj|_tj|j|_|jj|jjyt	dWnt
k
rpd|_n'Xt
ttj|_tjddS(s
        Add a log observer which records log events in C{self.out}.  Also,
        make sure the default string encoding is ASCII so that
        L{testSingleUnicode} can test the behavior of logging unencodable
        unicode messages.
        u½tasciiN(R`toutRRBtlptFileLogObservertfloRtemittstrtUnicodeEncodeErrortNonet
_origEncodingtreloadRStgetdefaultencodingtsetdefaultencoding(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRs


cCs`x1|jD]&}|jt|td|fq
W|jdk	r\tj|jt`ndS(s
        Verify that everything written to the fake file C{self.out} was a
        C{str}.  Also, restore the default string encoding to its previous
        setting, if it was modified by L{setUp}.
        s%r was not a stringN(RkRt
isinstanceRpRsRrRSRv(Rtchunk((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttearDown(s
$(RRRRy(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRis	tLogPublisherTestCasecBs#eZdZdZdZRS(cCs-|jjd|jt|jddS(Ns
Hello, world.i(RlRRRRk(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestSingleString8scCs0|jjdd|jt|jddS(NsHello, sworld.i(RlRRRRk(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestMultipleString=scCs[|jjd|jt|jd|jd|jd|jd|jddS(NuHello, ½ world.iswith str erroriRq(RlRRRRktassertIn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttestSingleUnicodeEs(RRR{R|R~(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRz7s		tFileObserverTestCasecBseZdZeedddkr3de_ndZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZRS(c	Cshd}tj|}d}tj|}tjjdd}zdtjd<tj|j|jj	|d
|j|jj	|ddtjd<tj|j|jj	|d|j|jj	|ddtjd<tj|j|jj	|d|j|jj	|dWd|dkrLtjd=n
|tjd<tjXdS(s
        Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
        correct values for the current C{TZ} environment setting.  Do this
        by setting C{TZ} to various well-known values and asserting that the
        reported offset is correct.
        iiiiiiiiiitTZsAmerica/New_Yorki@8iPFs
Europe/BerliniisAfrica/JohannesburgN(	iiiiiiiii(	iiiiiiiii(
RtmktimetostenvironRZRrttzsetRRntgetTimezoneOffset(RtlocalDaylightTupletutcDaylightTimestamptlocalStandardTupletutcStandardTimestamptoriginalTimezone((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_getTimezoneOffsetNsD







RsWPlatform cannot change timezone, cannot verify correct offsets in well-known timezones.c
Csotjdtj}d
|j_|j|jj|dd|j_|j|jj|d
d|j_|j|jj|dd|j_|j|jj|dd|j_|j|jj|dd|j_|j|jj|dd|j_|j|jj|dd|j_|j|jj|ddS(su
        Test the method of L{FileLogObserver} which turns a timestamp into a
        human-readable string.
        iiiiiiiiicSsdS(NiPF((twhen((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt<lambda>ss2001-02-02 23:05:06-0500cSsdS(Ni((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 05:05:06+0100cSsdS(NiPe((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 15:05:06+1100cSsdS(Ni((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 02:35:06-0130cSsdS(Ni((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 05:35:06+0130cSsdS(Ni((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 03:35:06-0030cSsdS(Ni((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRss2001-02-03 04:35:06+0030s%Y %ms2001 02N(	iiiiiiiii(RRttimezoneRnRRt
formatTimet
timeFormat(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_timeFormattings"cCsG|jjt|jt|jd|jd|jddS(Nit
UNFORMATTABLEi(RlRRdRRRktassertNotIn(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%test_loggingAnObjectWithBroken__str__scCsP|jjdddt|jt|jd|jd|jddS(NRJs%(blat)stblatis-Invalid format string or unformattable objecti(RlRRdRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt(test_formattingAnObjectWithBroken__str__scCsM|jjddt|jt|jd|jd|jddS(Nthuhtsystemis-Invalid format string or unformattable objecti(RlRRdRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_brokenSystem__str__scCsS|jjdddtg|jt|jd|jd|jddS(NRJs%(blat)sRisUNFORMATTABLE OBJECTi(RlRRfRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt1test_formattingAnObjectWithBroken__repr__IndirectscCsP|jjddtg|jt|jd|jd|jddS(NRRisUNFORMATTABLE OBJECTi(RlRRfRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%test_systemWithBroker__repr__IndirectscCsM|jjdddd|jt|jd|jd|jddS(NRJs
hooj %s %sRis-Invalid format string or unformattable objecti(RlRRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_simpleBrokenFormatscCsM|jjdddd|jt|jd|jd|jddS(NRJi*Ris-Invalid format string or unformattable objecti(RlRRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_ridiculousFormatscCsP|jjdtdd|jt|jd|jd|jddS(NRJRitPATHOLOGICALi(RlRRhRRRkR}(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt!test_evilFormat__repr__And__str__scCs6|jjdddt|jt|jddS(sP
        This kind of eventDict used to fail silently, so test it does.
        RtR(iN(RlRtFalseRRRk(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_strangeEventDictscCs6tjtj}}|jttdtj|jttdtjt}tj|}|j|jtj	d|j
d|j|jtjtj
|jtjjt|jtjj|jptj|jtjtj
|jtjjt|jtjj|jp.tjdS(sj
        startLogging() installs FileLogObserver and overrides sys.stdout and
        sys.stderr.
        tstdouttstderrsHello!N(RSRRR
tsetattrRRtstartLoggingtstopRR}RPRFtStdioOnnaStickRR(RtencodingRuR(Rt
origStdoutt
origStderrtfakeFileR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_startLoggings 	
cCstt_|jttdtj|jttdtjd}tj||jtj|tj	tj}|j|j
|jtjtjtj}tj	tj}|j
tj|dS(s
        There are some obscure error conditions that can occur when logging is
        started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
        information.
        RRcSs+|dr'tjj|djndS(NR(R(RSt
__stdout__RbtgetTraceback(R[((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt	showErrors
N(RRSRR
RRRRRRRRFRtassertIdentical(RRRt
fakeStdout((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_startLoggingTwices		
	N(RRRtgetattrRRrtskipRRRRRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRMs	1	.										tPythonLoggingObserverTestCasecBsMeZdZdZdZdZdZdZdZdZ	RS(s5
    Test the bridge with python logging module.
    cCst|_tjd}|j|_|jtjtj|j|_	tj
tj}|j	j||j
|j	tj|_tj|_|jj|jjdS(NR(RRktloggingt	getLoggertgetEffectiveLevelt
originalLeveltsetLeveltDEBUGt
StreamHandlerthdlrt	FormattertBASIC_FORMATtsetFormattert
addHandlerRRBRltPythonLoggingObservertobsRRo(Rt
rootLoggertfmt((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR%scCs=tjd}|j|j|j|jtjdS(NR(RRt
removeHandlerRRRtshutdown(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRy4scCsF|jjd|jd|jj|jd|jjdS(s<
        Test simple output, and default log level.
        s
Hello, world.tINFON(RlRR}RkRP(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_singleString:scCsE|jjdtjtddt|jd|jjdS(s$
        Test error output.
        RsThat is bad.R(tERRORN(	RlRRR*t
ValueErrorRR}RkRP(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_errorStringBs(cCs<|jjdddddd|jd|jjdS(	s-
        Test logging with a format.
        RJs%(bar)s oo %(foo)stbartHelloR$tworldsHello oo worldN(RlRR}RkRP(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_formatStringIscCs|jjddtj|jd|jj|jd|jj|jj|jjddtj|jd|jj|jd|jjdS(sG
        Test the logLevel keyword for customizing level used.
        s	Spam egg.tlogLevelRsFoo bar.tWARNINGN(	RlRRRR}RkRPtresetR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_customLevelPs
cCs6|jjdddt|j|jjddS(sx
        Verify that an event dictionary which is not an error and has an empty
        message isn't recorded.
        RRR(N(RlRRRRkRP(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR\s(
RRRRRyRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR!s						t PythonLoggingIntegrationTestCasecBs eZdZdZdZRS(s4
    Test integration of python logging bridge.
    cCstj}tj}g}zi|jt_|jt_tj}|j|j|d|j|j	|jt
|dWd|t_|t_XdS(s~
        Test that start and stop methods of the observer actually register
        and unregister to the log system.
        iN(RRRR
tremoveRtstartRRoRR(RtoldAddObservertoldRemoveObservertlR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_startStopObserveris		

	csdtjffdY}g}tjj}z6|jtj_|jd|jt|dWd|tj_XdS(s
        Test that we can inherit L{log.PythonLoggingObserver} and use super:
        that's basically a validation that L{log.PythonLoggingObserver} is
        new-style class.
        t
MyObservercseZfdZRS(cst|j|dS(N(tsuperRo(RR[(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRos(RRRo((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRsR$iN(RRRoR
RR(RRRtoldEmit((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_inheritance}s	
(RRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRes	tDefaultObserverTestCasecBseZdZdZRS(s$
    Test the default observer.
    cCsddlm}tj}||_|jd}tjt||j}|j||jj	|j
t|d|jdS(su
        The reason argument passed to log.err() appears in the report
        generated by DefaultObserver.
        i(RsThe reason.iN(
RRtDefaultObserverRRR,t	ExceptionR-tassertSubstringRPRRR(RRRtreasonR@((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_failureLoggers
(RRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRstStdioOnnaStickTestCasecBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
sF
    StdioOnnaStick should act like the normal sys.stdout object.
    cCs g|_tj|jjdS(N(t
resultLogsRRR
(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRs	cCstj|jjdS(N(RRRR
(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRyscCs'g|jD]}dj|d^q
S(NRR(Rtjoin(RR%((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pytgetLogMessagesscCs_tj}|jd|j|jdg|jd|j|jddgdS(s
        Writing to a StdioOnnaStick instance results in Twisted log messages.

        Log messages are generated every time a '
' is encountered.
        sHello there
This is a testsHello theres!
sThis is a test!N(RRRbRR(Rtstdio((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
test_writes


cCsStj}|jd|j|jddt|j|jddtdS(s{
        The log messages written by StdioOnnaStick have printed=1 keyword, and
        by default are not errors.
        shello
iR(tprintedN(RRRbRRRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
test_metadatas
cCs?tj}|jddg|j|jddgdS(sT
        Writing lines to a StdioOnnaStick results in Twisted log messages.
        slog 1slog 2N(RRt
writelinesRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_writeLinesscCsTtj}tjt_|jttd|dGdGH|j|jdgdS(sW
        When StdioOnnaStick is set as sys.stdout, prints become log messages.
        RtThiss	is a testsThis is a testN(RSRRRR
RRR(Rt	oldStdout((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
test_prints	cCs>tjdt}|jd|j|jddtdS(sR
        StdioOnnaStick created with isError=True log messages as errors.
        R(slog 1
iN(RRRRbRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
test_errors
cCsd}tjdd}|j|jd|j|d|jd|gtj}|t_|jt	td||GH|j|j
|jdd|jd|jdgdS(s
        StdioOnnaStick converts unicode prints to strings, in order to be
        compatible with the normal stdout/stderr objects.
        uHello, ½ world.Rsutf-8u
uAlso, RN(RRRRRbRRSRR
RRtencode(Rt
unicodeStringRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyttest_unicodes		(RRRRRyRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRs				
						((((RRRSRRRQt	cStringIORt
twisted.trialRttwisted.pythonRRtWarningRtTestCaseRtlistR`RdRfRhRiRzRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt<module>s"<'D,