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_runner.cpython-38.pyc
U


W[�3�@s0dZddlmZddlmZddlZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZddlmZdd	lmZd
dlmZd
dlmZmZd
d
lmZddlmZddlZGdd�dejj j!�Z"edd�Gdd�de��Z#Gdd�de�Z$Gdd�de%�Z&Gdd�de%�Z'Gdd�de%�Z(Gdd�de%�Z)dS) z2
Tests for L{twisted.application.runner._runner}.
�)�SIGTERM)�BytesION)�attrib�attrs�Factory)�LogLevel�LogPublisher�LogBeginner�FileLogObserver�FilteringLogObserver�LogLevelFilterPredicate)�
MemoryReactor�)�_runner�)�
ExitStatus)�PIDFile�NonePIDFile)�Runner�)�
DummyFilePathc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd#d!d"�Zd S)$�RunnerTestsz
    Tests for L{Runner}.
    cCs�t�|_t�|_|�td|j�|�td|j�d|_d�|j��d�|_	t
�|_t
�|_t
|j|j�|_t�|_t�|_t|j|jj|j|j�|_|�td|j�|�td|j�dS)N�exit�killi9z{}
zutf-8�stderr�globalLogBeginner)�	DummyExitr�	DummyKillr�patchr�pid�format�encode�pidFileContentr�stdoutr�DummyStandardIOZstdio�DummyWarningsModule�warningsrZglobalLogPublisherr	r��self�r)�M/usr/lib/python3/dist-packages/twisted/application/runner/test/test_runner.py�setUp#s&�zRunnerTests.setUpcCs.tt�d�}|��|�|jddddg�dS)zD
        L{Runner.run} calls the expected methods in order.
        ��reactor�killIfRequested�startLogging�startReactor�
reactorExitedN)�DummyRunnerr
�run�assertEqual�
calledMethods�r(�runnerr)r)r*�test_runInOrderEs��zRunnerTests.test_runInOrdercCsPt�}tt�|d�}|�|j�|�|j�|��|�|j�|�|j�dS)z;
        L{Runner.run} uses the provided PID file.
        �r-�pidFileN)�DummyPIDFilerr
�assertFalse�entered�exitedr3�
assertTrue�r(r:r7r)r)r*�test_runUsesPIDFileWszRunnerTests.test_runUsesPIDFilecCsTtt|j��}dd�|_tt�|d�}|��|�|jj	t
j�|�|jjd�dS)z�
        L{Runner.run} exits with L{ExitStatus.EX_USAGE} and the expected
        message if a process is already running that corresponds to the given
        PID file.
        cSsdS�NTr)r)r)r)r*�<lambda>o�z4RunnerTests.test_runAlreadyRunning.<locals>.<lambda>r9zAlready running.N)
rrr"Z	isRunningrr
r3r4r�statusr�	EX_CONFIG�messager@r)r)r*�test_runAlreadyRunninghs
z"RunnerTests.test_runAlreadyRunningcCs6tt�d�}|��|�|jjg�|�|jj�dS)z�
        L{Runner.killIfRequested} when C{kill} is false doesn't exit and
        doesn't indiscriminately murder anyone.
        r,N)	rr
r.r4r�callsr<rr>r6r)r)r*�test_killNotRequestedxsz!RunnerTests.test_killNotRequestedcCsLtt�dd�}|��|�|jjg�|�|jjtj	�|�|jj
d�dS)z�
        L{Runner.killIfRequested} when C{kill} is true but C{pidFile} is
        L{nonePIDFile} exits with L{ExitStatus.EX_USAGE} and the expected
        message; and also doesn't indiscriminately murder anyone.
        T)r-rzNo PID file specified.N)rr
r.r4rrIrrEr�EX_USAGErGr6r)r)r*� test_killRequestedWithoutPIDFile�s
z,RunnerTests.test_killRequestedWithoutPIDFilecCsdtt|j��}tt�d|d�}|��|�|jj|j	t
fg�|�|jjt
j�|�|jjd�dS)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        performs a targeted killing of the appropriate process.
        T�r-rr:N)rrr"rr
r.r4rrIrrrrEr�EX_OK�assertIdenticalrGr@r)r)r*�test_killRequestedWithPIDFile�sz)RunnerTests.test_killRequestedWithPIDFilecCsXttd��}dd�}||_tt�d|d�}|��|�|jjt	j
�|�|jjd�dS)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        that it can't read exits with L{ExitStatus.EX_IOERR}.
        NcSsttjd��dS)NzPermission denied)�OSError�errnoZEACCESr)r)r)r*�read�sz?RunnerTests.test_killRequestedWithPIDFileCantRead.<locals>.readTrMzUnable to read PID file.)rrrSrr
r.r4rrEr�EX_IOERRrG)r(r:rSr7r)r)r*�%test_killRequestedWithPIDFileCantRead�sz1RunnerTests.test_killRequestedWithPIDFileCantReadcCsJttd��}tt�d|d�}|��|�|jjtj	�|�|jj
d�dS)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        containing no value exits with L{ExitStatus.EX_DATAERR}.
        rDTrM�Invalid PID file.N�rrrr
r.r4rrEr�
EX_DATAERRrGr@r)r)r*�"test_killRequestedWithPIDFileEmpty�s
z.RunnerTests.test_killRequestedWithPIDFileEmptycCsJttd��}tt�d|d�}|��|�|jjtj	�|�|jj
d�dS)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        containing a non-integer value exits with L{ExitStatus.EX_DATAERR}.
        s ** totally not a number, dude **TrMrVNrWr@r)r)r*�%test_killRequestedWithPIDFileNotAnInt�s
z1RunnerTests.test_killRequestedWithPIDFileNotAnIntcs�t�}G�fdd�dt��|�td���G�fdd�dt��|�td��G�fdd�dt��tt�tj	|�d	�}|�
�|�t�j
�d
�|��j
dt�|�t�j�d
�|��jdt�|��jdjtj	�|��j��|��jj|�dS)
z�
        L{Runner.startLogging} sets up a filtering observer with a log level
        predicate set to the given log level that contains a file observer of
        the given type which writes to the given file.
        cseZdZ�fdd�ZdS)z2RunnerTests.test_startLogging.<locals>.LogBeginnercs
|�_dS�N)�	observers)r(r\�r	r)r*�beginLoggingTo�szARunnerTests.test_startLogging.<locals>.LogBeginner.beginLoggingToN)�__name__�
__module__�__qualname__r^r)r]r)r*r	�sr	rcs eZdZdd�f�fdd�	ZdS)z?RunnerTests.test_startLogging.<locals>.MockFilteringLogObservercSsdSr[r))Zeventr)r)r*rC�rDzHRunnerTests.test_startLogging.<locals>.MockFilteringLogObserver.<lambda>cs |�_|�_t�||||�dSr[)�observer�
predicatesr�__init__)r(rbrcZnegativeObserver��MockFilteringLogObserverr)r*rd�s�zHRunnerTests.test_startLogging.<locals>.MockFilteringLogObserver.__init__N�r_r`rardr)rer)r*rf�s�rfrcseZdZ�fdd�ZdS)z:RunnerTests.test_startLogging.<locals>.MockFileLogObservercs|�_t�||t�dSr[)�outFiler
rd�str)r(rh��MockFileLogObserverr)r*rd�szCRunnerTests.test_startLogging.<locals>.MockFileLogObserver.__init__Nrgr)rjr)r*rk�srk)r-�defaultLogLevel�logFileZfileLogObserverFactoryrrN)r�objectrrrr
rr
rZcriticalr/r4�lenr\ZassertIsInstancercrrOrlrbrh)r(rmr7r))r	rkrfr*�test_startLogging�s@��
���zRunnerTests.test_startLoggingcCs(t�}t|d�}|��|�|j�dS)ze
        L{Runner.startReactor} with the C{reactor} argument runs the given
        reactor.
        r,N)r
rr0r?ZhasRun)r(r-r7r)r)r*�test_startReactorWithReactors
z(RunnerTests.test_startReactorWithReactorcCs|�dd�dS)z�
        L{Runner.startReactor} ensures that C{whenRunning} is called with
        C{whenRunningArguments} when the reactor is running.
        �whenRunningr0N��	_testHookr'r)r)r*�test_startReactorWhenRunning#sz(RunnerTests.test_startReactorWhenRunningcCs|�d�dS)zb
        L{Runner.whenRunning} calls C{whenRunning} with
        C{whenRunningArguments}.
        rrNrsr'r)r)r*�test_whenRunningWithArguments+sz)RunnerTests.test_whenRunningWithArgumentscCs|�d�dS)zf
        L{Runner.whenRunning} calls C{reactorExited} with
        C{reactorExitedArguments}.
        r1Nrsr'r)r)r*�test_reactorExitedWithArguments3sz+RunnerTests.test_reactorExitedWithArgumentsNcs�|dkr|}tt�t�t�d�}g��fdd�}||d�|�|��i}tfdt�i|��}t||�}|�|�t��d�|��d|�dS)	a
        Verify that the named hook is run with the expected arguments as
        specified by the arguments used to create the L{Runner}, when the
        specified caller is invoked.

        @param methodName: The name of the hook to verify.
        @type methodName: L{str}

        @param callerName: The name of the method that is expected to cause the
            hook to be called.
            If C{None}, use the L{Runner} method with the same name as the
            hook.
        @type callerName: L{str}
        N)�a�b�ccs��|�dSr[)�append)�	arguments�Z
argumentsSeenr)r*�hookPsz#RunnerTests._testHook.<locals>.hookz{}Argumentsr-rr)	�dictrnr �copyrr
�getattrr4ro)r(Z
methodNameZ
callerNamer|r~ZrunnerArgumentsr7Z
hookCallerr)r}r*rt;s�
zRunnerTests._testHook)N)r_r`ra�__doc__r+r8rArHrJrLrPrUrYrZrprqrurvrwrtr)r)r)r*rs""

JrT)�frozenc@s>eZdZdZeee�d�Zdd�Zdd�Z	dd�Z
d	d
�ZdS)r2zg
    Stub for L{Runner}.

    Keep track of calls to some methods without actually doing anything.
    )�defaultcCs|j�d�dS)Nr.�r5r{r'r)r)r*r.lszDummyRunner.killIfRequestedcCs|j�d�dS)Nr/r�r'r)r)r*r/pszDummyRunner.startLoggingcCs|j�d�dS)Nr0r�r'r)r)r*r0tszDummyRunner.startReactorcCs|j�d�dS)Nr1r�r'r)r)r*r1xszDummyRunner.reactorExitedN)r_r`rar�rr�listr5r.r/r0r1r)r)r)r*r2asr2c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r;z]
    Stub for L{PIDFile}.

    Tracks context manager entry/exit without doing anything.
    cCst�|�d|_d|_dS�NF)rrdr=r>r'r)r)r*rd�s
zDummyPIDFile.__init__cCs
d|_|SrB)r=r'r)r)r*�	__enter__�szDummyPIDFile.__enter__cCs
d|_dSrB�r>)r(ZexcTypeZexcValue�	tracebackr)r)r*�__exit__�szDummyPIDFile.__exit__N)r_r`rar�rdr�r�r)r)r)r*r;}sr;c@s"eZdZdZdd�Zddd�ZdS)rzs
    Stub for L{exit} that remembers whether it's been called and, if it has,
    what arguments it was given.
    cCs
d|_dSr�r�r'r)r)r*rd�szDummyExit.__init__NcCs |jr
t�||_||_d|_dSrB)r>�AssertionErrorrErG)r(rErGr)r)r*�__call__�s
zDummyExit.__call__)N�r_r`rar�rdr�r)r)r)r*r�src@s eZdZdZdd�Zdd�ZdS)rzv
    Stub for L{os.kill} that remembers whether it's been called and, if it has,
    what arguments it was given.
    cCs
g|_dSr[)rIr'r)r)r*rd�szDummyKill.__init__cCs|j�||f�dSr[)rIr{)r(rZsigr)r)r*r��szDummyKill.__call__Nr�r)r)r)r*r�src@seZdZdZdd�ZdS)r$zQ
    Stub for L{sys} which provides L{BytesIO} streams as stdout and stderr.
    cCs||_||_dSr[)r#r)r(r#rr)r)r*rd�szDummyStandardIO.__init__N)r_r`rar�rdr)r)r)r*r$�sr$c@seZdZdZdd�ZdS)r%zV
    Stub for L{warnings} which provides a C{showwarning} method that is a no-op.
    cOsdS)z\
        Do nothing.

        @param args: ignored.
        @param kwargs: ignored.
        Nr))�args�kwargsr)r)r*�showwarning�szDummyWarningsModule.showwarningN)r_r`rar�r�r)r)r)r*r%�sr%)*r��signalr�iorrR�attrrrrZtwisted.loggerrrr	r
rrZtwisted.test.proto_helpersr
r7r�_exitrZ_pidfilerrrZtest_pidfilerZtwisted.trial.unittestZtwistedZtrialZunittestZTestCaserr2r;rnrrr$r%r)r)r)r*�<module>s, E