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/twist/test/__pycache__/test_twist.cpython-38.pyc
U


W[��@s�dZddlmZddlmZmZddlmZddlm	Z	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZdd
lmZddlmZddlZGdd�dejjj�ZGdd�dejjj�ZdS)z0
Tests for L{twisted.application.twist._twist}.
�)�stdout)�LogLevel�jsonFileLogObserver)�
MemoryReactor�)�IService�MultiService)�
ExitStatus)�Runner)�	DummyExit)�_twist�)�TwistOptions)�Twist)�SignalCapturingMemoryReactorNc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
TwistTestsz
    Tests for L{Twist}.
    cCs|��dS�N)�patchInstallReactor��self�r�K/usr/lib/python3/dist-packages/twisted/application/twist/test/test_twist.py�setUpszTwistTests.setUpcCst�|_|�td|j�dS)zX
        Patch L{_twist.exit} so we can capture usage and prevent actual exits.
        �exitN)rr�patchrrrrr�	patchExit"szTwistTests.patchExitcs$i�_�fdd�}��td|�dS)zo
        Patch C{_options.installReactor} so we can capture usage and prevent
        actual installs.
        cst�}|�j|<|Sr)r�installedReactors)�_�name�reactorrrr�installReactor1s
z6TwistTests.patchInstallReactor.<locals>.installReactorr N)rrr)rr rrrr*szTwistTests.patchInstallReactorcs$g�_�fdd�}��td|�dS)zo
        Patch L{MultiService.startService} so we can capture usage and prevent
        actual starts.
        cs�j�|�dSr)�
serviceStarts�append)�servicerrr�startService@sz2TwistTests.patchStartService.<locals>.startServicer$N)r!rr)rr$rrr�patchStartService9szTwistTests.patchStartServicecCst�ddg�}|�|t�dS)zI
        L{Twist.options} given valid arguments returns options.
        �twist�webN)r�optionsZassertIsInstancer)rr(rrr�test_optionsValidArgumentsFsz%TwistTests.test_optionsValidArgumentscCs\|��t�ddg�|�|jjtj�|�|jj	�
d��|�|jj	�d�t
����dS)z�
        L{Twist.options} given invalid arguments exits with
        L{ExitStatus.EX_USAGE} and an error/usage message.
        r&z--bogus-bagelszError: z

{}N)rrr(ZassertIdenticalrZstatusr	�EX_USAGE�
assertTrue�message�
startswith�endswith�formatrrrrr�test_optionsInvalidArgumentsOs
�z'TwistTests.test_optionsInvalidArgumentscCs6t�ddg�}t�|jd|j�}|�t�|��dS)z:
        L{Twist.service} returns an L{IService}.
        r&r'N)rr(r#�plugins�
subOptionsr+rZ
providedBy)rr(r#rrr�test_service_szTwistTests.test_servicecCsvt�ddg�}|d}tj|j|j|jd�}|��t�||�|�|j	|g�|�|j
dd|jdifg�dS)	z�
        L{Twist.startService} starts the service and registers a trigger to
        stop the service when the reactor shuts down.
        r&r'r)Zpluginr(ZbeforeZshutdownrN)rr(r#r1Z
subCommandr2r%r$�assertEqualr!ZtriggersZstopService)rr(rr#rrr�test_startServicehs
��zTwistTests.test_startServicec	s�g�|�td�fdd��|�tddd��t�dddd	g�}t�|�|�t��d
�|��dt|jdt	j
ttd
��dS)zi
        L{Twist.run} runs the runner with arguments corresponding to the given
        options.
        �__init__cs
��|�Sr)r")r�args�ZargsSeenrr�<lambda>��z%TwistTests.test_run.<locals>.<lambda>�runcSsdSrrrrrrr9�r:r&�--reactor=default�--log-format=jsonr'�r�default�rZdefaultLogLevelZlogFile�fileLogObserverFactoryN)
rr
rr(r;r4�len�dictrr�inforr)rZtwistOptionsrr8r�test_run�s8
���
��zTwistTests.test_runc	s�|��g�G�fdd�dt�}|�td|�t�ddddg�|�t|j�d�|�t��d�|��dj	t
|jd	tj
ttd
��|��djd�dS)zy
        L{Twist.main} runs the runner with arguments corresponding to the given
        command line arguments.
        cs eZdZ�fdd�Zdd�ZdS)z$TwistTests.test_main.<locals>.Runnercs||_d|_��|�dS)Nr)r7�runsr")r�kwargs�Zrunnersrrr6�sz-TwistTests.test_main.<locals>.Runner.__init__cSs|jd7_dS)Nr>)rFrrrrr;�sz(TwistTests.test_main.<locals>.Runner.runN)�__name__�
__module__�__qualname__r6r;rrHrrr
�sr
r&r<r=r'r>rr?r@N)r%�objectrrr�mainr4rBr!r7rCrrrDrrrF)rr
rrHr�	test_main�s,	���	zTwistTests.test_mainN)rIrJrK�__doc__rrrr%r)r0r3r5rErNrrrrrs
		rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�TwistExitTestszr
    Tests to verify that the Twist script takes the expected actions related
    to signals and the reactor.
    cs:d�_�fdd�}��td|�dd�}��td|�dS)NFcs
d�_dS)z�
            Fake to capture whether L{twisted.application._exitWithSignal
            was called.

            @param sig: Signal value
            @type sig: C{int}
            TN)�exitWithSignalCalled)Zsigrrr�fakeExitWithSignal�sz0TwistExitTests.setUp.<locals>.fakeExitWithSignalZ_exitWithSignalcSsdS)z�
            Prevent Runner from adding new log observers or other
            tests outside this module will fail.

            @param _: Unused self param
            Nr)rrrr�startLogging�sz*TwistExitTests.setUp.<locals>.startLoggingrS)rQrrr
)rrRrSrrrr�s

zTwistExitTests.setUpcCs<t�}d|_t�}||d<t|d<t�|�|�|j�dS)zg
        _exitWithSignal is not called if the reactor's _exitSignal attribute
        is zero.
        NrrA)r�_exitSignalrrrr;�assertFalserQ�rrr(rrr�%test_twistReactorDoesntExitWithSignal�s
z4TwistExitTests.test_twistReactorDoesntExitWithSignalcCs6t�}t�}||d<t|d<t�|�|�|j�dS)z�
        _exitWithSignal is not called if the runner's reactor does not
        implement L{twisted.internet.interfaces._ISupportsExitSignalCapturing}
        rrAN)rrrrr;rUrQrVrrr�$test_twistReactorHasNoExitSignalAttr�s
z3TwistExitTests.test_twistReactorHasNoExitSignalAttrcCs<t�}d|_t�}||d<t|d<t�|�|�|j�dS)zb
        _exitWithSignal is called if the runner's reactor exits due
        to a signal.
        r
rrAN)rrTrrrr;r+rQrVrrr� test_twistReactorExitsWithSignals
z/TwistExitTests.test_twistReactorExitsWithSignalN)rIrJrKrOrrWrXrYrrrrrP�s

rP)rO�sysrZtwisted.loggerrrZtwisted.test.proto_helpersrr#rrZrunner._exitr	Zrunner._runnerr
Zrunner.test.test_runnerrr&rZ_optionsrrZtwisted.test.test_twistdrZtwisted.trial.unittestZtwistedZtrialZunittestZTestCaserrPrrrr�<module>s.