HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/application/runner/test/__pycache__/test_pidfile.cpython-38.pyc
U


W[�2�@s�dZddlmZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZd
dlmZdd
lmZmZmZmZmZmZmZddlZddlmZdd�ZGdd�dejj j!�Z"Gdd�dejj j!�Z#ee�Gdd�de$��Z%dS)z3
Tests for L{twisted.application.runner._pidfile}.
���wrapsN)�getpid�name)�BytesIO)�implementer)�verifyObject)�	IFilePath)�platform�)�_pidfile�)�IPIDFile�PIDFile�NonePIDFile�AlreadyRunningError�InvalidPIDFileError�StalePIDFileError�
NoPIDFound)�SkipTestcst���fdd��}|S)aQ
    Decorator for tests that are not expected to work on all platforms.

    Calling L{PIDFile.isRunning} currently raises L{NotImplementedError} on
    non-POSIX platforms.

    On an unsupported platform, we expect to see any test that calls
    L{PIDFile.isRunning} to raise either L{NotImplementedError}, L{SkipTest},
    or C{self.failureException}.
    (C{self.failureException} may occur in a test that checks for a specific
    exception but it gets NotImplementedError instead.)

    @param f: The test method to decorate.
    @type f: method

    @return: The wrapped callable.
    cs`t��dk}|r �|f|�|�S|jtt|jf�|f|�|�}t|t�r\|�t|��	d��dS)N�posixz isRunning is not implemented on )
r
ZgetType�assertRaises�NotImplementedErrorrZfailureException�
isinstance�
assertTrue�str�
startswith)�self�args�kwargsZ	supported�e��f��N/usr/lib/python3/dist-packages/twisted/application/runner/test/test_pidfile.py�wrapper0s 
���
�z$ifPlatformSupported.<locals>.wrapperr)r"r%r#r!r$�ifPlatformSupportedsr&c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zd$d%�Zd&d'�Zed(d)��Zed*d+��Zd,S)-�PIDFileTestsz
    Tests for L{PIDFile}.
    cCstt��}tt|�dS)z5
        L{PIDFile} conforms to L{IPIDFile}.
        N)r�
DummyFilePathrr�r�pidFiler#r#r$�test_interfaceIs
zPIDFileTests.test_interfacecCs|�tjdd�d�dS)zR
        L{PIDFile._format} returns the expected format when given a PID.
        �9��pids1337
N)�assertEqualr�_format�rr#r#r$�test_formatWithPIDQszPIDFileTests.test_formatWithPIDcCs,d}tttj|d���}|�||���dS)zK
        L{PIDFile.read} returns the PID from the given file path.
        r,r-N)rr(r0r/�read�rr.r*r#r#r$�test_readWithPIDXszPIDFileTests.test_readWithPIDcCs8d}ttd��}|�t|j�}|�t|�d�|��dS)�f
        L{PIDFile.read} raises L{InvalidPIDFileError} when given an empty file
        path.
        ��'non-integer PID value in PID file: {!r}N�rr(rrr3r/r�format�rZpidValuer*r r#r#r$�test_readEmptyPIDcs�zPIDFileTests.test_readEmptyPIDcCs8d}tt|��}|�t|j�}|�t|�d�|��dS)r6s$foo!r8Nr9r;r#r#r$�test_readWithBogusPIDrs�z"PIDFileTests.test_readWithBogusPIDcCs,tt��}|�t|j�}|�t|�d�dS)zc
        L{PIDFile.read} raises L{NoPIDFound} when given a non-existing file
        path.
        �PID file does not existN)rr(rrr3r/r�rr*r r#r#r$�test_readDoesntExist�s
z!PIDFileTests.test_readDoesntExistcCsDddd�}|�td|�tt��}|�t|j�}|�|jtj�dS)z�
        L{PIDFile.read} re-raises L{OSError} if the associated C{errno} is
        anything other than L{errno.ENOENT}.
        �rcSsttjd��dS)Nz	I/O error)�OSError�errno�EIO)�moder#r#r$�oops�sz>PIDFileTests.test_readOpenRaisesOSErrorNotENOENT.<locals>.oops�openN)rA)	�patchr(rrrBr3r/rCrD)rrFr*�errorr#r#r$�#test_readOpenRaisesOSErrorNotENOENT�s


z0PIDFileTests.test_readOpenRaisesOSErrorNotENOENTcCs,d}tt��}|�|�|�|��|�dS)z9
        L{PIDFile._write} stores the given PID.
        i�N)rr(�_writer/r3r4r#r#r$�
test_writePID�s

zPIDFileTests.test_writePIDcCstt��}|�t|jd�dS)zS
        L{PIDFile._write} raises L{ValueError} when given an invalid PID.
        ZburpN)rr(r�
ValueErrorrKr)r#r#r$�test_writePIDInvalid�s
z!PIDFileTests.test_writePIDInvalidcCs(tt��}|��|�|��t��dS)zT
        L{PIDFile.writeRunningPID} stores the PID for the current process.
        N)rr(�writeRunningPIDr/r3rr)r#r#r$�test_writeRunningPID�s
z!PIDFileTests.test_writeRunningPIDcCs8ttd��}|�|j���|��|�|j���dS)z9
        L{PIDFile.remove} removes the PID file.
        r7N)rr(r�filePath�exists�remove�assertFalser)r#r#r$�test_remove�szPIDFileTests.test_removecCs<tt��}|�d�dd�}|�td|�|�|���dS)zR
        L{PIDFile.isRunning} returns true for a process that does exist.
        r,cSsdS�Nr#�r.�signalr#r#r$�kill�sz2PIDFileTests.test_isRunningDoesExist.<locals>.killrYN�rr(rKrHrr�	isRunning�rr*rYr#r#r$�test_isRunningDoesExist�s


z$PIDFileTests.test_isRunningDoesExistcCs$tt��}|��|�|���dS)a@
        L{PIDFile.isRunning} returns true for this process (which is running).

        @note: This differs from L{PIDFileTests.test_isRunningDoesExist} in
        that it actually invokes the C{kill} system call, which is useful for
        testing of our chosen method for probing the existence of a process.
        N)rr(rOrr[r)r#r#r$�test_isRunningThis�s	
zPIDFileTests.test_isRunningThiscCs<tt��}|�d�dd�}|�td|�|�t|j�dS)z{
        L{PIDFile.isRunning} raises L{StalePIDFileError} for a process that
        does not exist (errno=ESRCH).
        r,cSsttjd��dS�NzNo such process�rBrCZESRCHrWr#r#r$rY�sz5PIDFileTests.test_isRunningDoesNotExist.<locals>.killrYN)rr(rKrHrrrr[r\r#r#r$�test_isRunningDoesNotExist�s


z'PIDFileTests.test_isRunningDoesNotExistcCs<tt��}|�d�dd�}|�td|�|�|���dS)zx
        L{PIDFile.isRunning} returns true for a process that we are not allowed
        to kill (errno=EPERM).
        r,cSsttjd��dS)NzOperation not permitted)rBrC�EPERMrWr#r#r$rY�sz3PIDFileTests.test_isRunningNotAllowed.<locals>.killrYNrZr\r#r#r$�test_isRunningNotAllowed�s


z%PIDFileTests.test_isRunningNotAllowedcCs6tdkrtd��tt��}|�d�|�|���dS)ac
        L{PIDFile.isRunning} returns true for a process that we are not allowed
        to kill (errno=EPERM).

        @note: This differs from L{PIDFileTests.test_isRunningNotAllowed} in
        that it actually invokes the C{kill} system call, which is useful for
        testing of our chosen method for probing the existence of a process
        that we are not allowed to kill.

        @note: In this case, we try killing C{init}, which is process #1 on
        POSIX systems, so this test is not portable.  C{init} should always be
        running and should not be killable by non-root users.
        rzThis test assumes POSIX�N)�SYSTEM_NAMErrr(rKrr[r)r#r#r$�test_isRunningInits


zPIDFileTests.test_isRunningInitcCs:tt��}|��dd�}|�td|�|�t|j�dS)z�
        L{PIDFile.isRunning} re-raises L{OSError} if the attached C{errno}
        value from L{os.kill} is not an expected one.
        cSsttjd��dS)NzFile exists)rBrCZEEXISTrWr#r#r$rY(sz5PIDFileTests.test_isRunningUnknownErrno.<locals>.killrYN)rr(rOrHrrrBr[r\r#r#r$�test_isRunningUnknownErrnos

z'PIDFileTests.test_isRunningUnknownErrnocCstt��}|�|���dS)zS
        L{PIDFile.isRunning} returns false if the PID file doesn't exist.
        N)rr(rTr[r)r#r#r$�test_isRunningNoPIDFile0s
z$PIDFileTests.test_isRunningNoPIDFilec	Cs`tt��}|�|j���|�(|�|j���|�|��t��W5QRX|�|j���dS)z�
        When used as a context manager, a L{PIDFile} will store the current pid
        on entry, then removes the PID file on exit.
        N)	rr(rTrQrRrr/r3rr)r#r#r$�test_contextManager9s
z PIDFileTests.test_contextManagerc	Csntt��}|�d�dd�}|�td|�|�t|j�}|�t	|�d�|�|�|�
�t��W5QRXdS)z�
        When used as a context manager, a L{PIDFile} will replace the
        underlying PIDFile rather than raising L{AlreadyRunningError} if the
        contained PID file exists but refers to a non-running PID.
        r,cSsttjd��dSr_r`rWr#r#r$rYRsz9PIDFileTests.test_contextManagerDoesntExist.<locals>.killrYz'PID file refers to non-existing processN)rr(rKrHrrrr[r/rr3r)rr*rYr r#r#r$�test_contextManagerDoesntExistHs

z+PIDFileTests.test_contextManagerDoesntExistcCsJtt��}|�d�dd�}|�td|�|�|���|�t|j	�dS)z�
        When used as a context manager, a L{PIDFile} will raise
        L{AlreadyRunningError} if the there is already a running process with
        the contained PID.
        r,cSsdSrVr#rWr#r#r$rYhsz<PIDFileTests.test_contextManagerAlreadyRunning.<locals>.killrYN)
rr(rKrHrrr[rr�	__enter__r\r#r#r$�!test_contextManagerAlreadyRunning^s

z.PIDFileTests.test_contextManagerAlreadyRunningN)�__name__�
__module__�__qualname__�__doc__r+r2r5r<r=r@rJrLrNrPrUr&r]r^rarcrfrgrhrirjrlr#r#r#r$r'Ds<	






	
r'c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�NonePIDFileTestsz#
    Tests for L{NonePIDFile}.
    cCst�}tt|�dS)z9
        L{NonePIDFile} conforms to L{IPIDFile}.
        N)rrrr)r#r#r$r+xszNonePIDFileTests.test_interfacecCs(t�}|�t|j�}|�t|�d�dS)z;
        L{NonePIDFile.read} raises L{NoPIDFound}.
        r>N)rrrr3r/rr?r#r#r$�	test_read�szNonePIDFileTests.test_readcCs*t�}|�t|jd�}|�|jtj�dS)zZ
        L{NonePIDFile._write} raises L{OSError} with an errno of L{errno.EPERM}.
        rN)rrrBrKr/rCrb�rr*rIr#r#r$�
test_write�szNonePIDFileTests.test_writecCs(t�}|�t|j�}|�|jtj�dS)zk
        L{NonePIDFile.writeRunningPID} raises L{OSError} with an errno of
        L{errno.EPERM}.
        N)rrrBrOr/rCrbrsr#r#r$rP�sz%NonePIDFileTests.test_writeRunningPIDcCs(t�}|�t|j�}|�|jtj�dS)zZ
        L{NonePIDFile.remove} raises L{OSError} with an errno of L{errno.EPERM}.
        N)rrrBrSr/rC�ENOENTrsr#r#r$rU�szNonePIDFileTests.test_removecCst�}|�|��d�dS)z<
        L{NonePIDFile.isRunning} returns L{False}.
        FN)rr/r[r)r#r#r$�test_isRunning�szNonePIDFileTests.test_isRunningc	Cst�}|�W5QRXdS)zo
        When used as a context manager, a L{NonePIDFile} doesn't raise, despite
        not existing.
        N)rr)r#r#r$ri�sz$NonePIDFileTests.test_contextManagerN)rmrnrorpr+rrrtrPrUrvrir#r#r#r$rqss


	rqc@sDeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)r(z!
    In-memory L{IFilePath}.
    NcCs|�|�dSrV��
setContent�rZcontentr#r#r$�__init__�szDummyFilePath.__init__rAcCs|jsttjd��t|���S)NzNo such file or directory)�_existsrBrCrur�
getContent)rrEr#r#r$rG�szDummyFilePath.opencCs|dk	|_||_dSrV)r{�_contentryr#r#r$rx�s
zDummyFilePath.setContentcCs|jSrV)r}r1r#r#r$r|�szDummyFilePath.getContentcCs|�d�dSrVrwr1r#r#r$rS�szDummyFilePath.removecCs|jSrV)r{r1r#r#r$rR�szDummyFilePath.exists)N)rA)
rmrnrorprzrGrxr|rSrRr#r#r#r$r(�s

r()&rp�	functoolsrrC�osrrre�iorZzope.interfacerZzope.interface.verifyrZtwisted.python.filepathr	Ztwisted.python.runtimer
ZrunnerrrrrrrrrZtwisted.trial.unittestZtwistedrr&ZtrialZunittestZTestCaser'rq�objectr(r#r#r#r$�<module>s&$&1K