Your IP : 172.28.240.42


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


=Nc@sdZddlmZmZddlmZmZddlmZyddlm	Z	Wne
k
rod	ZnXddlmZdej
fdYZd	S(
s?
Tests for the inotify wrapper in L{twisted.internet.inotify}.
i(tdefertreactor(tfilepathtruntime(tunittest(t_inotify(tinotifytTestINotifycBseZdZejjs$dZndZdZddZ
dZdZdZ
dZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!RS(s]
    Define all the tests for the basic functionality exposed by
    L{inotify.INotify}.
    s&This platform doesn't support INotify.cCsXtj|j|_|jjtj|_|jj|j|jj	dS(N(
RtFilePathtmktemptdirnametcreateDirectoryRtINotifytstartReadingt
addCleanuptloseConnection(tself((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pytsetUps


cCsFdddY}|jtjd||jtjtjdS(s
        L{inotify.INotify} emits a C{RuntimeError} when initialized
        in an environment that doesn't support inotify as we expect it.

        We just try to raise an exception for every possible case in
        the for loop in L{inotify.INotify._inotify__init__}.
        tFakeINotifycBseZdZRS(cSstjdS(N(RtINotifyError(R((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pytinit.s(t__name__t
__module__R(((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR-sRN((tpatchRRtassertRaisesR(RR((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_initializationErrors%scsdkr!jjdntjfd}j|jjjddfdg|S(s
        Test notification from some filesystem operation.

        @param mask: The event mask to use when setting up the watch.

        @param operation: A function which will be called with the
            name of a file in the watched directory and which should
            trigger the event.

        @param expectedPath: Optionally, the name of the path which is
            expected to come back in the notification event; this will
            also be passed to C{operation} (primarily useful when the
            operation is being done to the directory itself, not a
            file in it).

        @return: A L{Deferred} which fires successfully when the
            expected event has been received or fails otherwise.
        sfoo.barcs4|\}}}j|j|@dS(N(tassertEqualt
assertTrue(t.0twatchtfilenametevents(texpectedPathtmaskR(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt
cbNotifiedJsR!t	callbackscs
j|S(N(tcallback(targs(tnotified(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt<lambda>QsN(tNoneR
tchildRtDeferredtaddCallbackRR(RR!t	operationR R"((R R&RR!sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt_notificationTest4s
	
cCsd}|jtj|S(s{
        Reading from a file in a monitored directory sends an
        C{inotify.IN_ACCESS} event to the callback.
        cSs|jd|jdS(Ntfoo(t
setContentt
getContent(tpath((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,[s
(R-Rt	IN_ACCESS(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_accessVs	cCsd}|jtj|S(sy
        Writing to a file in a monitored directory sends an
        C{inotify.IN_MODIFY} event to the callback.
        cSs*|jd}|jd|jdS(NtwR.(topentwritetclose(R1tfObj((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,gs
(R-Rt	IN_MODIFY(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_modifybs	cCsd}|jtj|S(s
        Changing the metadata of a a file in a monitored directory
        sends an C{inotify.IN_ATTRIB} event to the callback.
        cSs|j|jdS(N(ttouch(R1((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,ts
(R-Rt	IN_ATTRIB(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_attribos	cCsd}|jtj|S(s
        Closing a file which was open for writing in a monitored
        directory sends an C{inotify.IN_CLOSE_WRITE} event to the
        callback.
        cSs|jd}|jdS(NR4(R5R7(R1R8((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s(R-RtIN_CLOSE_WRITE(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_closeWrite{s	cCsd}|jtj|S(s
        Closing a file which was open for reading but not writing in a
        monitored directory sends an C{inotify.IN_CLOSE_NOWRITE} event
        to the callback.
        cSs'|j|jd}|jdS(Ntr(R;R5R7(R1R8((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s
(R-RtIN_CLOSE_NOWRITE(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_closeNoWrites	cCsd}|jtj|S(st
        Opening a file in a monitored directory sends an
        C{inotify.IN_OPEN} event to the callback.
        cSs|jd}|jdS(NR4(R5R7(R1R8((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s(R-RtIN_OPEN(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt	test_opens	cs"fd}jtj|S(s}
        Moving a file out of a monitored directory sends an
        C{inotify.IN_MOVED_FROM} event to the callback.
        cs9|jd}|j|jtjjdS(NR4(R5R7tmoveToRRR	(R1R8(R(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s
(R-Rt
IN_MOVED_FROM(RR,((RsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_movedFromscs"fd}jtj|S(sy
        Moving a file into a monitored directory sends an
        C{inotify.IN_MOVED_TO} event to the callback.
        cs0tjj}|j|j|dS(N(RRR	R;RE(R1tp(R(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s
(R-RtIN_MOVED_TO(RR,((RsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_movedToscCsd}|jtj|S(sw
        Creating a file in a monitored directory sends an
        C{inotify.IN_CREATE} event to the callback.
        cSs|jd}|jdS(NR4(R5R7(R1R8((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s(R-Rt	IN_CREATE(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_creates	cCsd}|jtj|S(sw
        Deleting a file in a monitored directory sends an
        C{inotify.IN_DELETE} event to the callback.
        cSs|j|jdS(N(R;tremove(R1((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,s
(R-Rt	IN_DELETE(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_deletes	cCs%d}|jtj|d|jS(s{
        Deleting the monitored directory itself sends an
        C{inotify.IN_DELETE_SELF} event to the callback.
        cSs|jdS(N(RM(R1((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,sR (R-RtIN_DELETE_SELFR
(RR,((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_deleteSelfs	cs+fd}jtj|djS(sy
        Renaming the monitored directory itself sends an
        C{inotify.IN_MOVE_SELF} event to the callback.
        cs |jtjjdS(N(RERRR	(R1(R(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR,sR (R-RtIN_MOVE_SELFR
(RR,((RsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt
test_moveSelfscsyfd}tjtjB}jjjd|dtd|gjjdtjj	S(s
        L{inotify.INotify} when initialized with autoAdd==True adds
        also adds the created subdirectories to the watchlist.
        cs)fd}tjd|dS(NcsLy*jjjjdWntk
rGjnXdS(N(RRt
_isWatchedR$R(t	Exceptionterrback((Rtsubdirtd(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt_s

i(Rt	callLater(twpRR!RY(RRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt	_callbacksR!tautoAddR#ttest(
RtIN_ISDIRRKRR
tTrueR)RR*R(RR\t	checkMask((RRWRXsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_simpleSubdirectoryAutoAdds	

csgfd}tjtjB}jjjd|dtd|gjjdtjj	S(sz
        L{inotify.INotify} removes a directory from the watchlist when
        it's removed from the filesystem.
        csdfd}fd}sPj|tjd|ntjd|dS(NcsIy'jjjjWntk
rDjnXdS(N(RRRTRMRURV((RRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyRYs

csMy+jjjjdWntk
rHjnXdS(N(RRRTR$R(RURV((RRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt_ebs

i(tappendRRZ(R[RR!RYRc(tcallsRRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR\s
R!R]R#R^(
RR_RKRR
R`R)RR*R(RR\Ra((ReRRWRXsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_simpleDeleteDirectorys	

cCsh|jj|jdt|j|jj|j|jj|j|j|jj|jdS(sR
        L{inotify.INotify.ignore} removes a directory from the watchlist
        R]N(RRR
R`RRTtignoretassertFalse(R((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_ignoreDirectory/scCsx4tjD])\}}|jtj|d|q
WtjtjBtjB}|jttj|tdddgdS(sy
        L{inotify.humaReadableMask} translates all the possible event
        masks to a human readable string.
        itclose_writetaccessR5N(Rt_FLAG_TO_HUMANRthumanReadableMaskR>R2RCtset(RR!tvalueRa((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_humanReadableMask9s!cCs|jjd}|jd}|jd}|j|||g}|jj|jdt|jj|jdtx'|D]}|j|jj|qWdS(s
        L{inotify.INotify.watch} with recursive==True will add all the
        subdirectories under the given path to the watchlist.
        R^ttest2ttest3t	recursiveN(R
R)tmakedirsRRR`RRT(RRWtsubdir2tsubdir3tdirsRX((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_recursiveWatchHs

cCs@ddl}tj}|j|j|j|jdS(s
        L{inotify.INotify.connectionLost} if there's a problem while closing
        the fd shouldn't raise the exception but should log the error
        iN(tosRRR7t_fdRtflushLoggedErrors(RRytin_((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_connectionLostErrorYs

csyfd}tjtjB}jjjd|dtd|gjjdtjj	S(s
        L{inotify.INotify.watch} with autoAdd==False will stop inotify
        from watching subdirectories created under the watched one.
        cs)fd}tjd|dS(NcsOy-jjjjjdWntk
rJjnXdS(N(RhRRTR1R$R(RURV((RRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyRYls

i(RRZ(R[tfpR!RY(RRWRX(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR\isR!R]R#R^(
RR_RKRR
tFalseR)RR*R(RR\Ra((RRWRXsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_noAutoAddSubdirectoryds	

csjjdjtjfd}fd}jjjd|gjjjjjdtj	d|gj
|jS(s
        L{inotify.INotify} will watch a filepath for events even if the same
        path is repeatedly added/removed/re-added to the watchpoints.
        sfoo.bar2cs7|\}}}j|j|tj@dS(N(RRRRP(RtignoredRR(R R(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR"scsj|dS(N(R$(R%(R&(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pytcallItsR#R!(R
R)R;RR*RRRRgRPR+RM(RR"R((R R&RsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_seriesOfWatchAndIgnore~s
"	

csjjd}|jjjdjtjfd}fd}jjj|tjd|gj	|jjjtjd|gjj
||jjS(sr
        L{inotify.INotify} will ignore a filepath after it has been removed from
        the watch list.
        sfoo.bar2sfoo.bar3cs7|\}}}j|j|tj@dS(N(RRRRP(RRRR(Rt
expectedPath2(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR"scsj|dS(N(R$(R%(R&(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyRsR#(R
R)R;RR*RRRRPR+RgRM(RR R"R((R&RRsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_ignoreFilePaths$

	
	

cCs9|jjd}|j|jt|jj|dS(sf
        L{inotify.INotify} will raise KeyError if a non-watched filepath is
        ignored.
        sfoo.ignoredN(R
R)R;RtKeyErrorRRg(RR ((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_ignoreNonWatchedFiles
cstfd}tjtjB}jjjd|dtd|gjjdjdjdtj	j
jdjd	jd
gx*tD]\}}|j|j
qWS(sB
        L{inotify.INotify} with autoAdd==True for a watched path
        generates events for every file or directory already present
        in a newly created subdirectory under the watched one.

        This tests that we solve a race condition in inotify even though
        we may generate duplicate events.
        csj|tdkryjjjjjjjjjg}jtt|jt|Wntk
rjqXj	dndS(Ni(taddtlenRRRTRRnRURVR$R((R[RR!tcreated(RXReRuRRvt	someFilesRW(sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyR\s

R!R]R#R^RqRrs	file1.dats	file2.dats	file3.dat(RnRR_RKRR
R`R)RR*Rtt	enumerateR/R1(RR\RatiR((ReRRuRvRRWRXsF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyttest_complexSubdirectoryAutoAdds"		!	

N("RRt__doc__RtplatformtsupportsINotifytskipRRR(R-R3R:R=R?RBRDRGRJRLRORQRSRbRfRiRpRxR}RRRRR(((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyRs:			"		
		
			
	
						)	
					"	#	N(Rttwisted.internetRRttwisted.pythonRRt
twisted.trialRRtImportErrorR(RtTestCaseR(((sF/usr/lib/python2.7/dist-packages/twisted/internet/test/test_inotify.pyt<module>s