+
    Dfj]2                     f   R t ^ RIt^ RIHt ^ RIHtHt ^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIHt ^ R	IHt ^R
IHt ^RIHtHtHtHtHtHtHt R R lt ! R R]P@                  PB                  PD                  4      t# ! R R]P@                  PB                  PD                  4      t$R# )z3
Tests for L{twisted.application.runner._pidfile}.
Nwraps)getpidname)AnyCallableOptional)verifyObject)NoReturn)FilePath)platform)SkipTest)_pidfile)AlreadyRunningErrorInvalidPIDFileErrorIPIDFileNonePIDFile
NoPIDFoundPIDFileStalePIDFileErrorc                d    V ^8  d   QhR\         R\        3,          R\         R\        3,          /# )   f.return)r   r   )formats   "N/usr/lib/python3/dist-packages/twisted/application/runner/test/test_pidfile.py__annotate__r   !   s,     # #8CH- #(382D #    c                6   a  \        S 4      R V 3R ll4       pV# )a  
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.

@return: The wrapped callable.
c                H    V ^8  d   QhR\         R\         R\         R\         /# )r   selfargskwargsr   )r   )r   s   "r   r   )ifPlatformSupported.<locals>.__annotate__4   s.     W Wc W# W W Wr   c                 <  < \         P                  ! 4       R 8H  pV'       d   S! V .VO5/ VB # V P                  ! \        \        V P
                  3SV .VO5/ VB p\        V\        4      '       d,   V P                  \        V4      P                  R4      4       R# R# )posixz isRunning is not implemented on N)
r   getTypeassertRaisesNotImplementedErrorr   failureException
isinstance
assertTruestr
startswith)r    r!   r"   	supporteder   s   &*,  r   wrapper$ifPlatformSupported.<locals>.wrapper3   s    $$&'1	T+D+F++!!$h0E0EF 	
 A !011A 1 12T UV 2r   r   )r   r0   s   f r   ifPlatformSupportedr2   !   s$    $ 1XW W  Nr   c                     a  ] tR t^Gt o RtR0V 3R lR lltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR lt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR  l4       t]V 3R! lR" l4       t]V 3R# lR$ l4       t]V 3R% lR& l4       tV 3R' lR( ltV 3R) lR* lt]V 3R+ lR, l4       t]V 3R- lR. l4       tR/tV tR# )1PIDFileTestsz
Tests for L{PIDFile}.
Nc                F   < V ^8  d   QhRS[ S[,          RS[S[,          /# )r   contentr   )r   bytesr   r,   )r   __classdict__s   "r   r   PIDFileTests.__annotate__L   s#       8C= r   c                b    \        V P                  4       4      pVe   VP                  V4       V# N)r   mktemp
setContent)r    r6   filePaths   && r   r>   PIDFileTests.filePathL   s+    DKKM*(r   c                   < V ^8  d   QhRR/# r   r   N )r   r8   s   "r   r   r9   R        ( ( (r   c                X    \        V P                  4       4      p\        \        V4       R# )z%
L{PIDFile} conforms to L{IPIDFile}.
N)r   r>   r	   r   r    pidFiles   & r   test_interfacePIDFileTests.test_interfaceR   s     $--/*Xw'r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   Y   s     ? ?D ?r   c                T    V P                  \        P                  ! RR7      R4       R# )zB
L{PIDFile._format} returns the expected format when given a PID.
9  pids   1337
N)assertEqualr   _format)r    s   &r   test_formatWithPIDPIDFileTests.test_formatWithPIDY   s     	T2I>r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   _   s     . .$ .r   c                    Rp\        V P                  \         P                  ! VR7      4      4      pV P                  WP	                  4       4       R# )z;
L{PIDFile.read} returns the PID from the given file path.
rK   rL   N)r   r>   rO   rN   readr    rM   rF   s   &  r   test_readWithPIDPIDFileTests.test_readWithPID_   s9     $--C(@ABlln-r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   i   s     	U 	U4 	Ur   c                    Rp\        V P                  R4      4      pV P                  \        VP                  4      pV P                  \        V4      RV: 24       R# )N
L{PIDFile.read} raises L{InvalidPIDFileError} when given an empty file
path.
r   #non-integer PID value in PID file: Nr   r>   r'   r   rT   rN   r,   r    pidValuerF   r/   s   &   r   test_readEmptyPIDPIDFileTests.test_readEmptyPIDi   sO    
 $--,-17<<@Q#Fxl!STr   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   t   s     	U 	Ut 	Ur   c                    Rp\        V P                  V4      4      pV P                  \        VP                  4      pV P                  \        V4      RV: 24       R# )rZ   s   $foo!r[   Nr\   r]   s   &   r   test_readWithBogusPID"PIDFileTests.test_readWithBogusPIDt   sO    
 $--1217<<@Q#Fxl!STr   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     < <d <r   c                    \        V P                  4       4      pV P                  \        VP                  4      pV P                  \        V4      R4       R# )zK
L{PIDFile.read} raises L{NoPIDFound} when given a non-existing file
path.
PID file does not existN)r   r>   r'   r   rT   rN   r,   r    rF   r/   s   &  r   test_readDoesntExist!PIDFileTests.test_readDoesntExist   s?    
 $--/*j',,7Q!:;r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     1 1T 1r   c                
   RR R llpV P                  \        RV4       \        V P                  4       4      pV P	                  \
        VP                  4      pV P                  VP                  \        P                  4       R# )zi
L{PIDFile.read} re-raises L{OSError} if the associated C{errno} is
anything other than L{errno.ENOENT}.
c                0    V ^8  d   QhR\         R\        /# )r   moder   )r,   r
   )r   s   "r   r   FPIDFileTests.test_readOpenRaisesOSErrorNotENOENT.<locals>.__annotate__   s     	2 	2s 	2X 	2r   c                 6    \        \        P                  R 4      h)z	I/O error)OSErrorerrnoEIO)rn   s   &r   oops>PIDFileTests.test_readOpenRaisesOSErrorNotENOENT.<locals>.oops   s    %))[11r   openN)r)
patchr   r   r>   r'   rq   rT   rN   rr   rs   )r    rt   rF   errors   &   r   #test_readOpenRaisesOSErrorNotENOENT0PIDFileTests.test_readOpenRaisesOSErrorNotENOENT   sW    	2 	

8VT*$--/*!!'7<<8eii0r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     	. 	.t 	.r   c                    Rp\        V P                  4       4      pVP                  V4       V P                  VP	                  4       V4       R# )z)
L{PIDFile._write} stores the given PID.
i  N)r   r>   _writerN   rT   rU   s   &  r   test_writePIDPIDFileTests.test_writePID   s;     $--/*s-r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     > >d >r   c                z    \        V P                  4       4      pV P                  \        VP                  R4       R# )zC
L{PIDFile._write} raises L{ValueError} when given an invalid PID.
burpN)r   r>   r'   
ValueErrorr~   rE   s   & r   test_writePIDInvalid!PIDFileTests.test_writePIDInvalid   s*     $--/**gnnf=r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     3 3d 3r   c                    \        V P                  4       4      pVP                  4        V P                  VP	                  4       \        4       4       R# )zD
L{PIDFile.writeRunningPID} stores the PID for the current process.
N)r   r>   writeRunningPIDrN   rT   r   rE   s   & r   test_writeRunningPID!PIDFileTests.test_writeRunningPID   s8     $--/*!2r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     4 4T 4r   c                    \        V P                  R4      4      pV P                  VP                  P                  4       4       VP	                  4        V P                  VP                  P                  4       4       R# )z)
L{PIDFile.remove} removes the PID file.
r   N)r   r>   r+   existsremoveassertFalserE   s   & r   test_removePIDFileTests.test_remove   sY     $--,-((//12))0023r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     - - -r   c                    \        V P                  4       4      pVP                  R4       R R lpV P                  \        RV4       V P                  VP                  4       4       R# )zB
L{PIDFile.isRunning} returns true for a process that does exist.
rK   c                4    V ^8  d   QhR\         R\         RR/# r   rM   signalr   Nint)r   s   "r   r   :PIDFileTests.test_isRunningDoesExist.<locals>.__annotate__   !     	 	c 	3 	4 	r   c                     R # r;   rB   rM   r   s   &&r   kill2PIDFileTests.test_isRunningDoesExist.<locals>.kill       r   r   Nr   r>   r~   rx   r   r+   	isRunningr    rF   r   s   &  r   test_isRunningDoesExist$PIDFileTests.test_isRunningDoesExist   sL    
 $--/*t	 	

8VT*))+,r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     - -D -r   c                    \        V P                  4       4      pVP                  4        V P                  VP	                  4       4       R# )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)r   r>   r   r+   r   rE   s   & r   test_isRunningThisPIDFileTests.test_isRunningThis   s5     $--/*!))+,r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     @ @D @r   c                    \        V P                  4       4      pVP                  R4       R R lpV P                  \        RV4       V P                  \        VP                  4       R# )zc
L{PIDFile.isRunning} raises L{StalePIDFileError} for a process that
does not exist (errno=ESRCH).
rK   c                4    V ^8  d   QhR\         R\         RR/# r   r   )r   s   "r   r   =PIDFileTests.test_isRunningDoesNotExist.<locals>.__annotate__   !     	: 	:c 	:3 	:4 	:r   c                 6    \        \        P                  R 4      hzNo such processrq   rr   ESRCHr   s   &&r   r   5PIDFileTests.test_isRunningDoesNotExist.<locals>.kill       %++'899r   r   N)r   r>   r~   rx   r   r'   r   r   r   s   &  r   test_isRunningDoesNotExist'PIDFileTests.test_isRunningDoesNotExist   sN     $--/*t	: 	

8VT*+W->->?r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     - -$ -r   c                    \        V P                  4       4      pVP                  R4       R R lpV P                  \        RV4       V P                  VP                  4       4       R# )z`
L{PIDFile.isRunning} returns true for a process that we are not allowed
to kill (errno=EPERM).
rK   c                4    V ^8  d   QhR\         R\         RR/# r   r   )r   s   "r   r   ;PIDFileTests.test_isRunningNotAllowed.<locals>.__annotate__   s&     	B 	Bc 	B3 	B4 	Br   c                 6    \        \        P                  R 4      h)zOperation not permitted)rq   rr   EPERMr   s   &&r   r   3PIDFileTests.test_isRunningNotAllowed.<locals>.kill   s    %++'@AAr   r   Nr   r   s   &  r   test_isRunningNotAllowed%PIDFileTests.test_isRunningNotAllowed   sM     $--/*t	B 	

8VT*))+,r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9      s     - -D -r   c                    \         R8w  d   \        R4      h\        V P                  4       4      pVP	                  ^4       V P                  VP                  4       4       R# )a  
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.
r%   zThis test assumes POSIXN)SYSTEM_NAMEr   r   r>   r~   r+   r   rE   s   & r   test_isRunningInitPIDFileTests.test_isRunningInit   sI     '!455$--/*q))+,r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9     s     6 6D 6r   c                    \        V P                  4       4      pVP                  4        R R lpV P                  \        RV4       V P                  \        VP                  4       R# )zr
L{PIDFile.isRunning} re-raises L{OSError} if the attached C{errno}
value from L{os.kill} is not an expected one.
c                4    V ^8  d   QhR\         R\         RR/# r   r   )r   s   "r   r   =PIDFileTests.test_isRunningUnknownErrno.<locals>.__annotate__  s!     	7 	7c 	73 	74 	7r   c                 6    \        \        P                  R 4      h)zFile exists)rq   rr   EEXISTr   s   &&r   r   5PIDFileTests.test_isRunningUnknownErrno.<locals>.kill  s    %,,66r   r   N)r   r>   r   rx   r   r'   rq   r   r   s   &  r   test_isRunningUnknownErrno'PIDFileTests.test_isRunningUnknownErrno  sM     $--/*!	7 	

8VT*'7#4#45r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   #  s     . . .r   c                v    \        V P                  4       4      pV P                  VP                  4       4       R# )zC
L{PIDFile.isRunning} returns false if the PID file doesn't exist.
N)r   r>   r   r   rE   s   & r   test_isRunningNoPIDFile$PIDFileTests.test_isRunningNoPIDFile#  s+     $--/***,-r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   +  s     4 4T 4r   c                   \        V P                  4       4      pV P                  VP                  P                  4       4       V;_uu_ 4        V P	                  VP                  P                  4       4       V P                  VP                  4       \        4       4       RRR4       V P                  VP                  P                  4       4       R#   + '       g   i     L;; i)zv
When used as a context manager, a L{PIDFile} will store the current pid
on entry, then removes the PID file on exit.
N)r   r>   r   r   r+   rN   rT   r   rE   s   & r   test_contextManager PIDFileTests.test_contextManager+  s    
 $--/*))0023WOOG,,3356W\\^VX6  	))0023	 Ws   ACC"	c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   :  s     7 7 7r   c                   \        V P                  4       4      pVP                  R4       R R lpV P                  \        RV4       V P                  \        VP                  4      pV P                  \        V4      R4       V;_uu_ 4        V P                  VP                  4       \        4       4       RRR4       R#   + '       g   i     R# ; i)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.
rK   c                4    V ^8  d   QhR\         R\         RR/# r   r   )r   s   "r   r   APIDFileTests.test_contextManagerDoesntExist.<locals>.__annotate__C  r   r   c                 6    \        \        P                  R 4      hr   r   r   s   &&r   r   9PIDFileTests.test_contextManagerDoesntExist.<locals>.killC  r   r   r   z'PID file refers to non-existing processN)r   r>   r~   rx   r   r'   r   r   rN   r,   rT   r   )r    rF   r   r/   s   &   r   test_contextManagerDoesntExist+PIDFileTests.test_contextManagerDoesntExist9  s     $--/*t	: 	

8VT*/1B1BCQ!JKWW\\^VX6 WWWs   )C  C	c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r9   O  s     B B4 Br   c                   \        V P                  4       4      pVP                  R4       R R lpV P                  \        RV4       V P                  VP                  4       4       V P                  \        VP                  4       R# )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.
rK   c                4    V ^8  d   QhR\         R\         RR/# r   r   )r   s   "r   r   DPIDFileTests.test_contextManagerAlreadyRunning.<locals>.__annotate__X  r   r   c                     R # r;   rB   r   s   &&r   r   <PIDFileTests.test_contextManagerAlreadyRunning.<locals>.killX  r   r   r   N)
r   r>   r~   rx   r   r+   r   r'   r   	__enter__r   s   &  r   !test_contextManagerAlreadyRunning.PIDFileTests.test_contextManagerAlreadyRunningN  sc     $--/*t	 	

8VT*))+,-w/@/@Ar   rB   r;   )__name__
__module____qualname____firstlineno____doc__r>   rG   rP   rV   r_   rc   ri   rz   r   r   r   r   r2   r   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__r8   s   @r   r4   r4   G   s>     ( (? ?. .	U 	U	U 	U< <1 1 	. 	.> >3 34 4 - - - - @ @ - - - -, 6 6. .4 4 7 7( B Br   r4   c                      a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltRtV tR# )NonePIDFileTestsib  z
Tests for L{NonePIDFile}.
c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   NonePIDFileTests.__annotate__g  rC   r   c                :    \        4       p\        \        V4       R# )z)
L{NonePIDFile} conforms to L{IPIDFile}.
N)r   r	   r   rE   s   & r   rG   NonePIDFileTests.test_interfaceg  s     -Xw'r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r   n  s     < <4 <r   c                    \        4       pV P                  \        VP                  4      pV P	                  \        V4      R4       R# )z+
L{NonePIDFile.read} raises L{NoPIDFound}.
rg   N)r   r'   r   rT   rN   r,   rh   s   &  r   	test_readNonePIDFileTests.test_readn  s6     -j',,7Q!:;r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r   w  s     3 3D 3r   c                    \        4       pV P                  \        VP                  ^ 4      pV P	                  VP
                  \
        P                  4       R# )zJ
L{NonePIDFile._write} raises L{OSError} with an errno of L{errno.EPERM}.
N)r   r'   rq   r~   rN   rr   r   r    rF   ry   s   &  r   
test_writeNonePIDFileTests.test_writew  s;     -!!'7>>1=ekk2r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r     s     3 3d 3r   c                    \        4       pV P                  \        VP                  4      pV P	                  VP
                  \
        P                  4       R# )zS
L{NonePIDFile.writeRunningPID} raises L{OSError} with an errno of
L{errno.EPERM}.
N)r   r'   rq   r   rN   rr   r   r   s   &  r   r   %NonePIDFileTests.test_writeRunningPID  s;    
 -!!'7+B+BCekk2r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r     s     4 4T 4r   c                    \        4       pV P                  \        VP                  4      pV P	                  VP
                  \
        P                  4       R# )zJ
L{NonePIDFile.remove} raises L{OSError} with an errno of L{errno.EPERM}.
N)r   r'   rq   r   rN   rr   ENOENTr   s   &  r   r   NonePIDFileTests.test_remove  s9     -!!'7>>:ell3r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r     s     5 5 5r   c                Z    \        4       pV P                  VP                  4       R4       R# )z,
L{NonePIDFile.isRunning} returns L{False}.
FN)r   rN   r   rE   s   & r   test_isRunningNonePIDFileTests.test_isRunning  s$     -**,e4r   c                   < V ^8  d   QhRR/# rA   rB   )r   r8   s   "r   r   r     s      T r   c                j    \        4       pV;_uu_ 4         RRR4       R#   + '       g   i     R# ; i)zW
When used as a context manager, a L{NonePIDFile} doesn't raise, despite
not existing.
N)r   rE   s   & r   r   $NonePIDFileTests.test_contextManager  s    
 -W WWWs   !2	rB   N)r   r   r   r   r   rG   r   r   r   r   r  r   r   r   r   s   @r   r   r   b  sP     ( (< <3 33 34 45 5 r   r   )%r   rr   	functoolsr   osr   r   r   typingr   r   r   zope.interface.verifyr	   r
   twisted.trial.unittesttwistedtwisted.python.filepathr   twisted.python.runtimer   r   runnerr   r   r   r   r   r   r   r   r2   trialunittestTestCaser4   r   rB   r   r   <module>r     s      * * * .   , + +   #LXB7==))22 XBvAw}}--66 Ar   