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_lockfile.pyc


[XMc@sdZddlZddlZddlmZddlmZddlmZdZ
ejry ddlm
Z
ddlZWqek
rdZ
qXndejfd	YZd
ejfdYZdS(s'
Tests for L{twisted.python.lockfile}.
iN(tunittest(tlockfile(tplatform(tOpenProcesssZOn windows, lockfile.kill is not implemented in the absence of win32api and/or pywintypes.t	UtilTestscBseZdZdZdZejs6de_ndZdZ	ejs`de	_ndZ
ee
_dZee_d	Z
RS(
sM
    Tests for the helper functions used to implement L{FilesystemLock}.
    cCsQ|j}tjd||jttjd|}|j|jtjdS(s
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EEXIST}
        when an attempt is made to create a symlink which already exists.
        tfooN(tmktempRtsymlinktassertRaisestOSErrortassertEqualterrnotEEXIST(tselftnametexc((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_symlinkEEXISTscCs]|j}d}|jtd||jttj|d}|j|jtjdS(s<
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EIO} when
        the underlying L{rename} call fails with L{EIO}.

        Renaming a file on Windows may fail if the target of the rename is in
        the process of being deleted (directory deletion appears not to be
        atomic).
        cSsttjddS(N(tIOErrorRtEIOtNone(tsrctdst((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt
fakeRename1strenameRN(	RtpatchRRRRR
RR(R
RRR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_symlinkEIOWindows's
		sBspecial rename EIO handling only necessary and correct on Windows.cCs>|j}|jttj|}|j|jtjdS(s
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{ENOENT}
        when an attempt is made to read a symlink which does not exist.
        N(RRR	RtreadlinkR
RtENOENT(R
RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_readlinkENOENT<scCsZ|j}d}|jtd||jttj|}|j|jtjdS(s\
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{EACCES}
        on Windows when the underlying file open attempt fails with C{EACCES}.

        Opening a file on Windows may fail if the path is inside a directory
        which is in the process of being deleted (directory deletion appears
        not to be atomic).
        cSsttjddS(N(RRtEACCESR(tpathtmode((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pytfakeOpenPst_openN(	RRRRRRR
RR(R
RR R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_readlinkEACCESWindowsFs
		sGspecial readlink EACCES handling only necessary and correct on Windows.cCstjtjddS(s}
        L{lockfile.kill} returns without error if passed the PID of a
        process which exists and signal C{0}.
        iN(Rtkilltostgetpid(R
((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt	test_kill[scCs5|jttjdd}|j|jtjdS(s
        L{lockfile.kill} raises L{OSError} with errno of L{ESRCH} if
        passed a PID which does not correspond to any process.
        iiiiNIi(RR	RR#R
RtESRCH(R
R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_killESRCHdscCsI|jtddtj|j}|j|j|jdS(s
        Verify that when L{lockfile.kill} does end up as None (e.g. on Windows
        without pywin32), it doesn't end up being called and raising a
        L{TypeError}.
        R#N(RRRtFilesystemLockRtlocktassertFalse(R
tfl((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_noKillCallos
(t__name__t
__module__t__doc__RRRt	isWindowstskipRR"R&tskipKillR(R-(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRs			
					tLockingTestCasecBs
eZdZdZdZejr9de_ndZdZ	dZ
dZdZd	Z
ejsd
e
_ndZejsde_nd
ZdZdZejrde_ndZdZdZdZdZRS(csifd}|jtd||j}tj|}|jt|j}|j|jdS(NcstddS(N(R	R(tsourcetdest(R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pytfakeSymlink~sR(	RRRR)RR	R*R
R(R
RR7tlockfR*R((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt_symlinkErrorTest}scCs|jtjdS(s
        An exception raised by C{symlink} other than C{EEXIST} is passed up to
        the caller of L{FilesystemLock.lock}.
        N(R9RtENOSYS(R
((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_symlinkErrorscCs$|jtj|jtjdS(s 
        An L{OSError} raised by C{symlink} on a POSIX platform with an errno of
        C{EACCES} or C{EIO} is passed to the caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N(R9RRR(R
((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_symlinkErrorPOSIXss9POSIX-specific error propagation not expected on Windows.cCsR|j}tj|}|j|j|j|j|j|jdS(s
        If the lock has never been held, it can be acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N(RRR)t
assertTrueR*tcleantlocked(R
R8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_cleanlyAcquires
cCs|j}tj|}|j|j|j|j|jtj|}|j|j|j|j|j|jdS(s
        If a lock is released cleanly, it can be re-acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N(	RRR)R=R*tunlockR+R?R>(R
R8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_cleanlyReleases
cCsd|j}tj|}|j|jtj|}|j|j|j|jdS(sK
        If a lock is currently locked, it cannot be locked again.
        N(RRR)R=R*R+R?(R
R8t	firstLockt
secondLock((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_cannotLockLockedscsdfd}|j}|jtd|tjt|tj|}|j|j|j|j	|j|j
|jtj|tt
jdS(s
        If a lock was held by a process which no longer exists, it can be
        acquired, the C{clean} attribute is set to C{False}, and the
        C{locked} attribute is set to C{True}.
        i90csF|dkr!ttjdn|krBttjdndS(Ni(R	RtEPERMRR'(tpidtsignal(towner(s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pytfakeKillsR#N(RRRRtstrR)R=R*R+R>R?R
RR$R%(R
RJR8R*((RIs>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_uncleanlyAcquirescsfd}|jtd|d}|jtd||jtj}tjtd|j|j|j|j|j|j	dS(s
        If the lock is initially held but then released before it can be
        examined to determine if the process which held it still exists, it is
        acquired and the C{clean} and C{locked} attributes are set to C{True}.
        cs$tjjtj|S(N(RtrmlinktrestoreR(R(R8t
readlinkPatch(s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pytfakeReadlinks

RcSsF|dkr!ttjdn|dkrBttjdndS(Niiu(R	RRFRR'(RGRH((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRJsR#iuN(
RRRR)RRKR=R*R>R?(R
RPRJR*((R8ROs>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_lockReleasedBeforeChecks	cCs^d}|jtd||j}tj|}|j|j|j|jdS(s
        If the lock is released while an attempt is made to acquire
        it, the lock attempt fails and C{FilesystemLock.lock} returns
        C{False}.  This can happen on Windows when L{lockfile.symlink}
        fails with L{IOError} of C{EIO} because another process is in
        the middle of a call to L{os.rmdir} (implemented in terms of
        RemoveDirectory) which is not atomic.
        cSsttjddS(N(R	RRR(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyR7	sRN(RRRR)R+R*R?(R
R7R8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt%test_lockReleasedDuringAcquireSymlinks		sBspecial rename EIO handling only necessary and correct on Windows.cCsvd}|jtd|}|j}tj|}tjtd||j|j|j|jdS(s
        If the lock is initially held but is released while an attempt
        is made to acquire it, the lock attempt fails and
        L{FilesystemLock.lock} returns C{False}.
        cSsttjddS(N(RRRR(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRP sRiuN(	RRRR)RRKR+R*R?(R
RPROR8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt&test_lockReleasedDuringAcquireReadlinks	sGspecial readlink EACCES handling only necessary and correct on Windows.csfd}|jtd||j}tjtd|tj|}|j|j}|j|j	|j
|jdS(NcsddS(N(R(R(Rt
exceptionType(s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRP3sRiu(RRRRRKR)RR*R
RR+R?(R
RTRRPR8R*R((RRTs>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt_readlinkErrorTest2scCs*|jttj|jttjdS(s
        An exception raised by C{readlink} other than C{ENOENT} is passed up to
        the caller of L{FilesystemLock.lock}.
        N(RUR	RR:R(R
((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_readlinkErrorBscCs*|jttj|jttjdS(s
        Any L{IOError} raised by C{readlink} on a POSIX platform passed to the
        caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N(RURRR:R(R
((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_readlinkErrorPOSIXKscsfd}|jtd|d}|jtd||jtj}tjtd|j|j|j|j|j|j	dS(s
        If a second process cleans up the lock after a first one checks the
        lock and finds that no process is holding it, the first process does
        not fail when it tries to clean up the lock.
        cs$jtjtj|S(N(RNRRM(R(trmlinkPatchR8(s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt
fakeRmlink`s

RMcSsF|dkr!ttjdn|dkrBttjdndS(Niiu(R	RRFRR'(RGRH((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRJhsR#iuN(
RRRR)RRKR=R*R>R?(R
RYRJR*((R8RXs>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_lockCleanedUpConcurrentlyZs	cCsd}|jtd|d}|jtd||j}tjtd|tj|}|jt|j}|j	|j
t
j|j|j
dS(s
        An exception raised by L{rmlink} other than C{ENOENT} is passed up
        to the caller of L{FilesystemLock.lock}.
        cSsttjddS(N(R	RR:R(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRY|sRMcSsF|dkr!ttjdn|dkrBttjdndS(Niiu(R	RRFRR'(RGRH((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRJsR#iuN(RRRRRKR)RR	R*R
RR:R+R?(R
RYRJR8R*R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_rmlinkErrorws		cCsd}|jtd||j}tjtd|tj|}|jt|j}|j	|j
t
j|j|j
dS(s
        If L{kill} raises an exception other than L{OSError} with errno set to
        C{ESRCH}, the exception is passed up to the caller of
        L{FilesystemLock.lock}.
        cSsttjddS(N(R	RRFR(RGRH((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyRJsR#iuN(RRRRRKR)RR	R*R
RRFR+R?(R
RJR8R*R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_killErrors	cCsR|j}tjttjd|tj|}|jt|j	dS(s
        L{FilesystemLock.unlock} raises L{ValueError} if called for a lock
        which is held by a different process.
        iN(
RRRRKR$R%R)Rt
ValueErrorRA(R
R8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyttest_unlockOthers cCs~|j}|jtj|tj|}|j|j|jtj||j|jtj|dS(sp
        L{isLocked} returns C{True} if the named lock is currently locked,
        C{False} otherwise.
        N(RR+RtisLockedR)R=R*RA(R
R8R*((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt
test_isLockeds
(R.R/R9R;R<RR1R2R@RBRERLRQRRRSRURVRWRZR[R\R^R`(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyR4|s4			
			
								
				(R0R$Rt
twisted.trialRttwisted.pythonRttwisted.python.runtimeRRR3R1twin32apiRt
pywintypestImportErrortTestCaseRR4(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_lockfile.pyt<module>s

d