Your IP : 172.28.240.42


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


Mc@sdZddlZddlZddlmZddlmZddlmZmZm	Z	ddl
mZdefdYZ
d	efd
YZdefdYZd
efdYZdS(s?
Tests for Trial's interaction with the Python warning system.
iN(tStringIO(tFilePath(tTestCaset_collectWarningst_setWarningRegistryToNone(t
TestResulttMaskcBs$eZdZdefdYZRS(sS
    Hide a L{TestCase} definition from trial's automatic discovery mechanism.
    t	MockTestscBs,eZdZdZeZdZdZRS(s
        A test case which is used by L{FlushWarningsTests} to verify behavior
        which cannot be verified by code inside a single test method.
        ssome warning textcCstj|j|jdS(s@
            Generate a warning and don't flush it.
            N(twarningstwarntmessagetcategory(tself((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_unflushedscCs6tj|j|j|jt|jddS(s:
            Generate a warning and flush it.
            iN(RR	R
RtassertEqualtlent
flushWarnings(R((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_flushed#s(t__name__t
__module__t__doc__R
tUserWarningRR
R(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRs
	(RRRRR(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRstFlushWarningsTestscBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZRS(sn
    Tests for L{TestCase.flushWarnings}, an API for examining the warnings
    emitted so far in a test.
    cCs5x.|jD] \}}|j|||q
WdS(s
        Assert that all the keys present in C{subset} are also present in
        C{set} and that the corresponding values are equal.
        N(t	iteritemsR(Rtsettsubsettktv((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pytassertDictSubset2scCsP|jt|t|x-t||D]\}}|j||q,WdS(s
        For each pair of corresponding elements in C{sets} and C{subsets},
        assert that the element from C{subsets} is a subset of the element from
        C{sets}.
        N(RRtzipR(Rtsetstsubsetstatb((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pytassertDictSubsets;scCs|j|jgdS(sp
        If no warnings are emitted by a test, L{TestCase.flushWarnings} returns
        an empty list.
        N(RR(R((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt	test_noneFscCsd}t}tjd|d|d}t}tjd|d||j|ji|d6|d6i|d6|d6gdS(s
        If several warnings are emitted by a test, L{TestCase.flushWarnings}
        returns a list containing all of them.
        sfirst warning messageR
Rssecond warning messageN(RRR	tRuntimeWarningR"R(RtfirstMessaget
firstCategoryt
secondMessagetsecondCategory((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_severalNs	cCshd}t}x*tdD]}tjd|d|qW|j|ji|d6|d6gddS(s
        The same warning triggered twice from the same place is included twice
        in the list returned by L{TestCase.flushWarnings}.
        sthe messageiR
RN(R$trangeRR	R"R(RR
Rti((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt
test_repeatedas	cCscd}t}tjd|d||j|ji|d6|d6g|j|jgdS(s
        After a particular warning event has been returned by
        L{TestCase.flushWarnings}, it is not returned by subsequent calls.
        sthe messageR
RN(R$RR	R"RR(RR
R((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_clearedps	cCst}tjd}|j||jtjjg}|j|ddd|j|ddt|jj	j
}|j}|jd}|j|dd||j|dd||jt
|d	d
S(sx
        Any warnings emitted by a test which are not flushed are emitted to the
        Python warning system.
        R
iR
ssome warning textRitfilenametlinenoiN(RRRtrunRR
RtassertIdenticalRtim_funct	func_codetco_filenametco_firstlinenoR(Rtresulttcaset
warningsShowntwhereR.R/((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyR
~s	
	
cCsgt}tjd}t}|jtd|}|j||j|j|j	ddS(sx
        Any warnings emitted by a test which are flushed are not emitted to the
        Python warning system.
        RtstdouttN(
RRRRtpatchtsysR0trestoreRtgetvalue(RR6R7toutputtmonkey((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRs		

cCsdtfdY}t}tjd}||_tj}zjtjd|j||j	t
|jd|j|jdd||jddj
|Wd|tj(XdS(s
        If a warnings filter has been installed which turns warnings into
        exceptions, tests have an error added to the reporter for them for each
        unflushed warning.
        t
CustomWarningcBseZRS((RR(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRBsR
terroriiN(tWarningRRRRRtfilterstsimplefilterR0RRterrorsR1ttrap(RRBR6R7toriginalWarnings((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_warningsConfiguredAsErrorss		


cCsdtfdY}t}tjd}||_tj}z1tjd|j||j	|j
gWd|tj(XdS(s
        If a warnings filter has been installed which turns warnings into
        exceptions, tests which emit those warnings but flush them do not have
        an error added to the reporter.
        RBcBseZRS((RR(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRBsRRCN(RDRRRRRRERFR0RRG(RRBR6R7RI((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt&test_flushedWarningsConfiguredAsErrorss		


cCsVtjd|jt|jdtjd|jt|jddS(s
        Any warnings emitted after a call to L{TestCase.flushWarnings} can be
        flushed by another call to L{TestCase.flushWarnings}.
        s
first messageissecond messageN(RR	RRR(R((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_multipleFlushess

csdtfd}dtfd}|||j|jd|gid6d6g|j|jd|gid6d6gdS(	s
        The list returned by L{TestCase.flushWarnings} includes only those
        warnings which refer to the source of the function passed as the value
        for C{offendingFunction}, if a value is passed for that parameter.
        sfirst warning textcstjdddS(Nt
stackleveli(RR	((R%R&(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pytoness	some textcstjdddS(NRMi(RR	((R(R'(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttwostoffendingFunctionsRR
N(RR$R"R(RRNRO((R%R'R(R&sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_filterOnOffendingFunctionscCs9d}||jt|jd|gddS(s
        Verify that warnings emitted at the very edges of a function are still
        determined to be emitted from that function.
        cSs+tjdtjdtjddS(Nsfirst line warningsinternal line warningslast line warning(RR	(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pytwarners

RPiN(RRR(RRR((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_functionBoundariess	cCsFtjd|jt|jdg|jt|jddS(s
        If an object which is neither a function nor a method is included in
        the C{offendingFunctions} list, L{TestCase.flushWarnings} raises
        L{ValueError}.  Such a call flushes no warnings.
        soh noiN(RR	tassertRaisest
ValueErrorRtNoneRR(R((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_invalidFilters
cCst|jjd}|j|jdjd|jdjdtjjd|jj|j	tjj
|jjddlm}|j	tj
jd|j	tj
j|j|jdj
|j|jt|j|jgd	d
S(sx
        Warnings emitted by a function the source code of which is not
        available can still be flushed.
        ttwisted_private_helpers__init__.pyR;smissingsourcefile.pys7
import warnings
def foo():
    warnings.warn("oh no")
ii(tmissingsourcefileiN(Rtmktemptchildtmakedirst
setContentR=tpathtinserttparentt
addCleanuptremoveRXRYtmodulestpopRtfooRRR(RtpackageRY((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_missingSources

cCs;t|jjd}|j|jdjd|jdjdtjjd|jj|j	tjj
|jjddlm}tj
d=tj
|j=|j|jd	ddlm}|j	tj
jd	|j	tj
j|j|j|jt|j|jgd
dS(s

        Warnings emitted by a function defined in a file which has been renamed
        since it was initially compiled can still be flushed.

        This is testing the code which specifically supports working around the
        unfortunate behavior of CPython to write a .py source file name into
        the .pyc files it generates and then trust that it is correct in
        various places.  If source files are renamed, .pyc files may not be
        regenerated, but they will contain incorrect filenames.
        RXs__init__.pyR;s	module.pys7
import warnings
def foo():
    warnings.warn("oh no")
ii(tmodulettwisted_renamed_helperiN(RRZR[R\R]R=R^R_R`RaRbRXRhRcRtmoveTotsiblingRiRdReRRR(RRfRh((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_renamedSource*s 



(RRRRR"R#R)R,R-R
RRJRKRLRQRSRWRgRl(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyR,s"																tFakeWarningcBseZRS((RR(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRmXstCollectWarningsTestscBsDeZdZdZdZdZdZdZdZRS(s(
    Tests for L{_collectWarnings}.
    csddddgfd}tj||jdd|jdj|jdj|jd	d
|jtddS(sS
        L{_collectWarnings} calls the observer with each emitted warning.
        sdummy calls observer warningNics8jdtjtjjddS(Ntcallt	returning(tappendRR	((R%R'tevents(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pytfhs


iRoiiiRpi(RRqRR
R(RRs((R%R'RrsC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_callsObserverascCsLt}|jtd|tdtjd|j|jddS(s
        Any warnings emitted by a call to a function passed to
        L{_collectWarnings} are not actually emitted to the warning system.
        R:cSsdS(N(RV(tx((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt<lambda>~sttextR;N(RR<R=RRR	RR?(RR@((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_suppressesws	c	sgtfd}td|dddddd}|jd
idd6dd6fg|j|d	S(s
        L{_collectWarnings} returns the result of calling the callable passed to
        it with the parameters given.
        csj||fS(N(Rq(targstkwargs(t	argumentstvalue(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRsscSsdS(N(RV(Ru((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRvsiR R!itctdN(iR (tobjectRRR1(RRsR6((R|R{sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_callsFunctions	$'cCsbd}tjd|g}t|j||jt|d|j|djd|jt|jddS(s
        Subsequent emissions of a warning from a particular source site can be
        collected by L{_collectWarnings}.  In particular, the per-module
        emitted-warning cache should be bypassed (I{__warningregistry__}).
        cSstjddS(NRe(RR	(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRsstdefaultiiReN(	t__warningregistry__RRFRRqRRR
R(RRsRr((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_duplicateWarningCollecteds	
cCs:t}|tj|<|jtjj||jdS(s
        L{_collectWarnings}'s behavior is not altered by the presence of an
        object which cannot have attributes set on it as a value in
        C{sys.modules}.
        N(RR=RcRaRdR(Rtkey((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyttest_immutableObjects	
csidtffdY}t}t}|||<t}t}|||<t|jt||||gtjdS(s
        If the dictionary passed to L{_setWarningRegistryToNone} changes size
        partway through the process, C{_setWarningRegistryToNone} continues to
        set C{__warningregistry__} to C{None} on the rest of the values anyway.


        This might be caused by C{sys.modules} containing something that's not
        really a module and imports things on setattr.  py.test does this, as
        does L{twisted.python.deprecate.deprecatedModuleAttribute}.
        tAcs eZdZfdZRS(cSs||jd<dS(Nt_key(t__dict__(RR((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt__init__scsd|j<dS(N(RVR(RR|titem(R~(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt__setattr__s(RRRR((R~(sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRs	N(RRRRtkeys(RRtkey1tkey2tkey3tkey4((R~sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt+test_setWarningRegistryChangeWhileIteratings				
(	RRRRtRxRRRR(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyRn]s					(RR=RRttwisted.python.filepathRttwisted.trial.unittestRRRttwisted.trial.reporterRRRRRDRmRn(((sC/usr/lib/python2.7/dist-packages/twisted/trial/test/test_warning.pyt<module>s-