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

ó
y@Nc@sÖdZddlZddlZddlZyddlZWnek
rSdZnXddlmZdZddl
mZdefd„ƒYZ
defd	„ƒYZd
efd„ƒYZdefd
„ƒYZdS(s;
Tests for POSIX-based L{IReactorProcess} implementations.
iÿÿÿÿNsnon-POSIX platform(tprocess(tTestCasetFakeFilecBs eZdZd„Zd„ZRS(s>
    A dummy file object which records when it is closed.
    cCs||_||_dS(N(ttestcasetfd(tselfRR((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyt__init__s	cCs|jjj|jƒdS(N(Rt_filestremoveR(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytcloses(t__name__t
__module__t__doc__RR	(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyRs	tFakeResourceModulecBs&eZdZdZd„Zd„ZRS(s¹
    Fake version of L{resource} which hard-codes a particular rlimit for maximum
    open files.

    @ivar _limit: The value to return for the hard limit of number of open files.
    icCs
||_dS(N(t_limit(Rtlimit((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyR,scCs&||jkrd|jgSddgS(sX
        A fake of L{resource.getrlimit} which returns a pre-determined result.
        ii{iÈ(t
RLIMIT_NOFILER(Rtno((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyt	getrlimit0s
(R
RRRRR(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyR
#s	tFDDetectorTestscBs¤eZdZeZeZeZeZd„Z	d„Z
d„Zd„Zd„Z
d„Zd„Zd„Zd	„Zd
„Zd„Zd„Zd
„Zd„ZRS(së
    Tests for _FDDetector class in twisted.internet.process, which detects
    which function to drop in place for the _listOpenFDs method.

    @ivar devfs: A flag indicating whether the filesystem fake will indicate
        that /dev/fd exists.

    @ivar accurateDevFDResults: A flag indicating whether the /dev/fd fake
        returns accurate open file information.

    @ivar procfs: A flag indicating whether the filesystem fake will indicate
        that /proc/<pid>/fd exists.
    cCsdS(s>
        Fake os.getpid, always return the same thing
        i{((R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytgetpidOscCsttt|jƒ}|jr8|d|jƒfkr8|S|jrg|dkrg|jrZ|SdddgStƒ‚dS(s„
        Fake os.listdir, depending on what mode we're in to simulate behaviour.

        @param arg: the directory to list
        s/proc/%d/fds/dev/fdt0t1t2N(tmaptstrRtprocfsRtdevfstaccurateDevFDResultstOSError(Rtargtaccurate((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytlistdirVs"	
cCsEt|tttdƒƒt|jƒƒƒ}|jj|jƒ|S(sO
        This is a mock for L{open}.  It keeps track of opened files so extra
        descriptors can be returned from the mock for L{os.listdir} when used on
        one of the list-of-filedescriptors directories.

        A L{FakeFile} is returned which can be closed to remove the new
        descriptor from the open list.
        i(RtmintsettrangeRtappendR(Rtfnametmodetf((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytopenfilefs
.cCsdtjd<dS(sp
        Make the L{resource} module unimportable for the remainder of the
        current test method.
        tresourceN(tNonetsystmodules(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pythideResourceModuleuscCst|ƒtjd<dS(s
        Make a L{FakeResourceModule} instance importable at the L{resource}
        name.

        @param limit: The value which will be returned for the hard limit of
            number of open files by the fake resource module's C{getrlimit}
            function.
        R)N(R
R+R,(RR((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytrevealResourceModule}s	cCsB|dkr1ytjd=Wq>tk
r-q>Xn
|tjd<dS(sI
        Restore the original resource module to L{sys.modules}.
        R)N(R*R+R,tKeyError(Rtvalue((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytreplaceResourceModule‰s
cCsqtjƒ|_|j|j_|j|j_|j|j_dddg|_|j|jt	j
jdƒƒdS(sž
        Set up the tests, giving ourselves a detector object to play with and
        setting up its testable knobs to refer to our mocked versions.
        iiiR)N(Rt_FDDetectortdetectorR RR(Rt
addCleanupR1R+R,tget(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytsetUp–scsSd„}d„}‡fd†}|||gˆj_ˆj|ˆjjƒƒdS(sÁ
        L{FDDetector._getImplementation} returns the first method from its
        C{_implementations} list which returns results which reflect a newly
        opened file descriptor.
        cSstdƒ‚dS(NsThis does not work(t
ValueError(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytfailWithExceptionªscSs
dddgS(Niii((((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytfailWithWrongResults­scsˆjS(N(R((R(sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytcorrect°sN(R3t_implementationstassertIdenticalt_getImplementation(RR8R9R:((RsK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_selectFirstWorking¤s
		cCsAd„}d„}||g|j_|j||jjƒƒdS(sâ
        L{FDDetector._getImplementation} returns the last method from its
        C{_implementations} list if none of the implementations manage to return
        results which reflect a newly opened file descriptor.
        cSs
dddgS(Niii	((((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyR9¿scSs
dddgS(Niii((((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pytfailWithOtherWrongResultsÂsN(R3R;R<R=(RR9R?((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_selectLast¹s
		cCshtjƒ}|jj}|jƒ|jj}|jƒ|jj}|j||ƒ|j||ƒdS(sä
        Check that the identity of _listOpenFDs changes after running
        _listOpenFDs the first time, but not after the second time it's run.

        In other words, check that the monkey patching actually works.
        N(RR2t_listOpenFDst	func_nametassertNotEqualtassertEqual(RR3tfirsttsecondtthird((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyt!test_identityOfListOpenFDsChangesÌs

cCsWt|_|jt|jjƒt|_t|_|jdddg|jjƒƒdS(sÈ
        L{_FDDetector._devFDImplementation} raises L{OSError} if there is no
        I{/dev/fd} directory, otherwise it returns the basenames of its children
        interpreted as integers.
        iiiN(	tFalseRtassertRaisesRR3t_devFDImplementationtTrueRRD(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_devFDImplementationàs
			cCsNt|_|jt|jjƒt|_|jdddg|jjƒƒdS(sÐ
        L{_FDDetector._procFDImplementation} raises L{OSError} if there is no
        I{/proc/<pid>/fd} directory, otherwise it returns the basenames of its
        children interpreted as integers.
        iiiN(RIRRJRR3t_procFDImplementationRLRD(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_procFDImplementationís		cCs\|jdƒ|jtdƒ|jjƒƒ|jdƒ|jtdƒ|jjƒƒdS(sÛ
        L{_FDDetector._fallbackFDImplementation} uses the L{resource} module if
        it is available, returning a range of integers from 0 to the the
        minimum of C{1024} and the hard I{NOFILE} limit.
        iiiN(R.RDR#R3t_fallbackFDImplementation(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_resourceFDImplementationùs

cCs-|jƒ|jtdƒ|jjƒƒdS(sÔ
        L{_FDDetector._fallbackFDImplementation}, the implementation of last
        resort, succeeds with a fixed range of integers from 0 to 1024 when the
        L{resource} module is not importable.
        iN(R-RDR#R3RP(R((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_fallbackFDImplementation
s
(R
RRtplatformSkiptskipRIRRRRR R(R-R.R1R6R>R@RHRMRORQRR(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyR:s&
						
					
		tFileDescriptorTestscBs&eZdZeZd„Zd„ZRS(s<
    Tests for L{twisted.internet.process._listOpenFDs}
    cCsnxgtjƒD]Y}ytj|tjƒWq
tk
re}|jtj|jd||jfƒq
Xq
WdS(sµ
        File descriptors returned by L{_listOpenFDs} are mostly open.

        This test assumes that zero-legth writes fail with EBADF on closed
        file descriptors.
        s2fcntl(%d, F_GETFL) failed with unexpected errno %dN(RRAtfcntltF_GETFLtIOErrorRDterrnotEBADF(RRterr((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_openFDsscCs±ttjƒ}tjƒ}|j|jƒ|ƒtj|jƒƒ}|j||jƒkdƒz$|j	ƒ|j|tjƒƒWdtj	|ƒX|j
|tjƒƒdS(sB
        L{_listOpenFDs} lists expected file descriptors.
        s>Expected duplicate file descriptor to be greater than originalN(tfiletostdevnullRRAtassertIntfilenotdupt
assertTrueR	tassertNotIn(RR'topenfdsR((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyttest_expectedFDs,s
(R
RRRSRTR\Rf(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyRUs	(RRYR^R+RVtImportErrorRSttwisted.internetRR*ttwisted.trial.unittestRtobjectRR
RRU(((sK/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixprocess.pyt<module>s$

Û