%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/application/runner/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/application/runner/test/__pycache__/test_runner.cpython-312.pyc

�

Ϫ�f�8����dZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZmZmZddlZddlmZdd	lmZmZmZmZmZm Z m!Z!dd
l"m#Z#ddl$m%Z%d
dl&m'Z'd
dl(m)Z)m*Z*d
dl%m+Z+Gd�dejXjZj\�Z/ed��Gd�de+��Z0Gd�de)�Z1Gd�d�Z2Gd�d�Z3Gd�d�Z4Gd�d �Z5y)!z2
Tests for L{twisted.application.runner._runner}.
�N)�StringIO)�SIGTERM)�
TracebackType)	�Any�Iterable�List�Optional�TextIO�Tuple�Type�Union�cast)�Factory�attrib�attrs)�
MemoryReactor)�FileLogObserver�FilteringLogObserver�ILogObserver�LogBeginner�LogLevel�LogLevelFilterPredicate�LogPublisher)�FilePath�)�_runner�)�
ExitStatus)�NonePIDFile�PIDFile)�Runnerc���eZdZdZddeedeefd�Zdd�Z	dd�Z
dd�Zdd	�Zdd
�Z
dd�Zdd�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zddedeeddfd�Zy)�RunnerTestsz
    Tests for L{Runner}.
    N�content�returnc�^�t|j��}|�|j|�|S�N)r�mktemp�
setContent)�selfr$�filePaths   �M/usr/lib/python3/dist-packages/twisted/application/runner/test/test_runner.pyr+zRunnerTests.filePath's+���D�K�K�M�*��������(���c���t�|_t�|_|j	t
d|j�|j	t
d|j�d|_|j�d�j�|_t�|_
t�|_t|j|j�|_
t�|_t!�|_t%|j"|jj|j|j�|_|j	t
d|j�|j	t
d|j&�y)N�exit�killi9�
�stderr�globalLogBeginner)�	DummyExitr/�	DummyKillr0�patchr�pid�encode�pidFileContentr�stdoutr2�DummyStandardIO�stdio�DummyWarningsModule�warningsr�globalLogPublisherrr3�r*s r,�setUpzRunnerTests.setUp-s����K��	��K��	��
�
�7�F�D�I�I�.��
�
�7�F�D�I�I�.����!%���
�"�o�4�4�6���
�j����j���$�T�[�[�$�+�+�>��
�+�-��
�".�.���!,��#�#��J�J����J�J��M�M�	"
���	
�
�
�7�H�d�k�k�2��
�
�7�/��1G�1G�Hr-c��tt���}|j�|j|jgd��y)zD
        L{Runner.run} calls the expected methods in order.
        ��reactor)�killIfRequested�startLogging�startReactor�
reactorExitedN)�DummyRunnerr�run�assertEqual�
calledMethods�r*�runners  r,�test_runInOrderzRunnerTests.test_runInOrderOs5���]�_�5���
�
������ � �
�	
r-c�:�t�}tt�|��}|j|j�|j|j
�|j
�|j|j�|j|j
�y)z;
        L{Runner.run} uses the provided PID file.
        �rD�pidFileN)�DummyPIDFiler!r�assertFalse�entered�exitedrJ�
assertTrue�r*rRrNs   r,�test_runUsesPIDFilezRunnerTests.test_runUsesPIDFile`sf���.���
���A��������)�������(��
�
��������(�������'r-c�Z�t|j|j��}d�|_t	t�|��}|j
�|j|jjtj�|j|jjd�y)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.
        c��y�NT�r]r-r,�<lambda>z4RunnerTests.test_runAlreadyRunning.<locals>.<lambda>w��r-rQzAlready running.N)
r r+r9�	isRunningr!rrJrKr/�statusr�	EX_CONFIG�messagerXs   r,�test_runAlreadyRunningz"RunnerTests.test_runAlreadyRunningpsw���$�-�-��(;�(;�<�=��(����
���A���
�
��������)�)�:�+?�+?�@�������*�*�,>�?r-c���tt���}|j�|j|jj
g�|j
|jj�y)z�
        L{Runner.killIfRequested} when C{kill} is false doesn't exit and
        doesn't indiscriminately murder anyone.
        rCN)	r!rrErKr0�callsrTr/rVrMs  r,�test_killNotRequestedz!RunnerTests.test_killNotRequestedsL��
�
��0����� ���������"�-�������)�)�*r-c�N�tt�d��}|j�|j|jj
g�|j|jjtj�|j|jjd�y)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)rDr0zNo PID file specified.N)r!rrErKr0rfr/rar�EX_USAGErcrMs  r,� test_killRequestedWithoutPIDFilez,RunnerTests.test_killRequestedWithoutPIDFile�sq���
��d�;����� ���������"�-�������)�)�:�+>�+>�?�������*�*�,D�Er-c��t|j|j��}tt	�d|��}|j�|j
|jj|jtfg�|j
|jjtj�|j|jj d�y)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        performs a targeted killing of the appropriate process.
        T�rDr0rRN)r r+r9r!rrErKr0rfr7rr/rar�EX_OK�assertIdenticalrcrXs   r,�test_killRequestedWithPIDFilez)RunnerTests.test_killRequestedWithPIDFile�s���
�$�-�-��(;�(;�<�=���
��d�G�L����� ���������D�H�H�g�+>�*?�@�������)�)�:�+;�+;�<����T�Y�Y�.�.��5r-c�Z�t|jd��}dtfd�}||_t	t�d|��}|j
�|j|jjtj�|j|jjd�y)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}.
        Nr%c�6�ttjd��)NzPermission denied)�OSError�errno�EACCESr]r-r,�readz?RunnerTests.test_killRequestedWithPIDFileCantRead.<locals>.read�s���%�,�,�(;�<�<r-TrlzUnable to read PID file.)
r r+�intrur!rrErKr/rar�EX_IOERRrc)r*rRrurNs    r,�%test_killRequestedWithPIDFileCantReadz1RunnerTests.test_killRequestedWithPIDFileCantRead�s���
�$�-�-��-�.��	=�c�	=�����
��d�G�L����� �������)�)�:�+>�+>�?�������*�*�,F�Gr-c�8�t|jd��}tt�d|��}|j	�|j|jjtj�|j|jjd�y)z�
        L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
        containing no value exits with L{ExitStatus.EX_DATAERR}.
        r-Trl�Invalid PID file.N�r r+r!rrErKr/rar�
EX_DATAERRrcrXs   r,�"test_killRequestedWithPIDFileEmptyz.RunnerTests.test_killRequestedWithPIDFileEmpty�sn��
�$�-�-��,�-���
��d�G�L����� �������)�)�:�+@�+@�A�������*�*�,?�@r-c�8�t|jd��}tt�d|��}|j	�|j|jjtj�|j|jjd�y)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 **TrlrzNr{rXs   r,�%test_killRequestedWithPIDFileNotAnIntz1RunnerTests.test_killRequestedWithPIDFileNotAnInt�so��
�$�-�-�(K�L�M���
��d�G�L����� �������)�)�:�+@�+@�A�������*�*�,?�@r-c�`����t�}G�fd�d��|jtd���G�fd�dt��|jtd��G�fd�dt��tt
�tj|��	�}|j�|jt�j�d
�|j�jdt�|jt�j�d
�|j�jdt�|j!�jdj"tj�t%��j&�}|j|��|j!|j(|�y)
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.
        c�>��eZdZUgZeeed<deeddf�fd�Zy)�2RunnerTests.test_startLogging.<locals>.LogBeginner�	observersr%Nc�&��t|��_yr')�listr�)r*r�rs  �r,�beginLoggingTozARunnerTests.test_startLogging.<locals>.LogBeginner.beginLoggingTo�s���(,�Y���%r-)	�__name__�
__module__�__qualname__r�rr�__annotations__rr�)rs�r,rr��s*���,.�I�t�L�)�.�
8���0F�
8�4�
8r-rr3c	�n��eZdZUdZeeed<gZee	ed<e
ed��fdedee	deddf�fd�
Zy)�?RunnerTests.test_startLogging.<locals>.MockFilteringLogObserverN�observer�
predicatesc��yr'r])�events r,r^zHRunnerTests.test_startLogging.<locals>.MockFilteringLogObserver.<lambda>�r_r-�negativeObserverr%c�d��|�_t|��_tj||||�yr')r�r�r�r�__init__)r*r�r�r��MockFilteringLogObservers    �r,r�zHRunnerTests.test_startLogging.<locals>.MockFilteringLogObserver.__init__�s4���5=�(�1�6:�:�6F�(�3�$�-�-��(�J�0@�r-)
r�r�r�r�r	rr�r�rrrrr�)r�s�r,r�r��s`���/3�H�h�|�,�3�8:�J��4�5�:�26�l�DV�1W�	

�&�

�%�%<�=�

�#/�	

�
�

r-r�rc�8��eZdZUdZeeed<deddf�fd�Zy)�:RunnerTests.test_startLogging.<locals>.MockFileLogObserverN�outFiler%c�J��|�_tj||t�yr')r�rr��str)r*r��MockFileLogObservers  �r,r�zCRunnerTests.test_startLogging.<locals>.MockFileLogObserver.__init__�s���.5�#�+��(�(��w��<r-)r�r�r�r�r	r
r�r�)r�s�r,r�r��s%���(,�G�X�f�%�,�
=��
=�4�
=r-r�)rD�defaultLogLevel�logFile�fileLogObserverFactory�rN)rr6rrrr!rr�criticalrFrK�lenr��assertIsInstancer�rrnr�rr�r�)r*r�rNr�rr�r�s    @@@r,�test_startLoggingzRunnerTests.test_startLogging�sg����*��
	8�	8�	
�
�
�7�/���?�	�';�	� 	
�
�
�7�2�4L�M�	=�/�	=��!�O�$�-�-��#6�	
��	����	
����[�2�2�3�Q�7����k�3�3�A�6�8L�M�	
����5�@�@�A�1�E����$�/�/��2�4K�	
�	
���$�/�/��2�B�B�H�DU�DU�	
�
�+�-E�-N�-N�O�����h�(;�<�	
���X�-�-�w�7r-c��t�}t|��}|j�|j|j�y)ze
        L{Runner.startReactor} with the C{reactor} argument runs the given
        reactor.
        rCN)rr!rGrW�hasRun)r*rDrNs   r,�test_startReactorWithReactorz(RunnerTests.test_startReactorWithReactors1��
 �/����(������������'r-c�(�|jdd�y)z�
        L{Runner.startReactor} ensures that C{whenRunning} is called with
        C{whenRunningArguments} when the reactor is running.
        �whenRunningrGN��	_testHookr@s r,�test_startReactorWhenRunningz(RunnerTests.test_startReactorWhenRunning&s��
	
���}�n�5r-c�&�|jd�y)zb
        L{Runner.whenRunning} calls C{whenRunning} with
        C{whenRunningArguments}.
        r�Nr�r@s r,�test_whenRunningWithArgumentsz)RunnerTests.test_whenRunningWithArguments-s��
	
���}�%r-c�&�|jd�y)zf
        L{Runner.whenRunning} calls C{reactorExited} with
        C{reactorExitedArguments}.
        rHNr�r@s r,�test_reactorExitedWithArgumentsz+RunnerTests.test_reactorExitedWithArguments4s��
	
����'r-�
methodName�
callerNamec�X��|�|}tt�t�t���}g�dtddf�fd�}|||�d�|j�i}td
dt	�i|��}t||�}|�|j
t��d�|j
�d	|�y)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.

        @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.
        N)�a�b�c�	argumentsr%c�(���j|�yr')�append)r��
argumentsSeens �r,�hookz#RunnerTests._testHook.<locals>.hookNs���� � ��+r-�	ArgumentsrDr�rr])�dict�object�copyr!r�getattrrKr�)	r*r�r�r�r��runnerArgumentsrN�
hookCallerr�s	        @r,r�zRunnerTests._testHook;s������#�J��6�8�v�x�6�8�<�	��
�	,�f�	,��	,�
���l�)�$�i�n�n�&6�
���
�!�O�
�'6�
���V�Z�0�
�������]�+�Q�/�����q�)�9�5r-r'�r%N)r�r�r��__doc__r	�bytesrr�r+rArOrYrdrgrjrorxr}rr�r�r�r�r�r�r]r-r,r#r#"s���������8�C�=�� I�D
�"(� 
@�	+�F�6�H�$
A�
A�K8�Z	(�6�&�(�"6�C�"6�X�c�]�"6�d�"6r-r#T)�frozenc�V�eZdZdZeeeee���Z	dd�Z
dd�Zdd�Zdd�Z
y)	rIzg
    Stub for L{Runner}.

    Keep track of calls to some methods without actually doing anything.
    )�type�defaultNc�:�|jjd�y)NrE�rLr�r@s r,rEzDummyRunner.killIfRequestedjs�����!�!�"3�4r-c�:�|jjd�y)NrFr�r@s r,rFzDummyRunner.startLoggingm������!�!�.�1r-c�:�|jjd�y)NrGr�r@s r,rGzDummyRunner.startReactorpr�r-c�:�|jjd�y)NrHr�r@s r,rHzDummyRunner.reactorExitedss�����!�!�/�2r-r�)r�r�r�r�rrr�rr�rLrErFrGrHr]r-r,rIrI`s1�����S�	�7�4�=�A�M�5�2�2�3r-rIc�P�eZdZdZd
d�Zdd�Zdeeedeedee	ddfd	�Z
y)rSz]
    Stub for L{PIDFile}.

    Tracks context manager entry/exit without doing anything.
    r%Nc�J�tj|�d|_d|_y�NF)rr�rUrVr@s r,r�zDummyPIDFile.__init__~s�����T�"������r-c��d|_|Sr\)rUr@s r,�	__enter__zDummyPIDFile.__enter__�s������r-�excType�excValue�	tracebackc��d|_yr\�rV)r*r�r�r�s    r,�__exit__zDummyPIDFile.__exit__�s����r-r�)r%rS)r�r�r�r�r�r�r	r�
BaseExceptionrr�r]r-r,rSrSwsP�������$�}�-�.���=�)���M�*�	�

�r-rSc�@�eZdZdZdd�Z	d	deeefdee	ddfd�Z
y)
r4zy
    Stub for L{_exit.exit} that remembers whether it's been called and, if it has,
    what arguments it was given.
    r%Nc��d|_yr�r�r@s r,r�zDummyExit.__init__�s	����r-rarcc�J�|jrJ�||_||_d|_yr\)rVrarc)r*rarcs   r,�__call__zDummyExit.__call__�s%���;�;�����������r-r�r')r�r�r�r�r�r
rvrr	r�r�r]r-r,r4r4�s=���
�HL���C��O�,��7?��}��	
�r-r4c�,�eZdZdZdd�Zdededdfd�Zy)	r5zv
    Stub for L{os.kill} that remembers whether it's been called and, if it has,
    what arguments it was given.
    r%Nc��g|_yr')rfr@s r,r�zDummyKill.__init__�s	��,.��
r-r7�sigc�>�|jj||f�yr')rfr�)r*r7r�s   r,r�zDummyKill.__call__�s���
�
���3��*�%r-r�)r�r�r�r�r�rvr�r]r-r,r5r5�s&���
/�&�C�&�c�&�d�&r-r5c�$�eZdZdZdededdfd�Zy)r;zR
    Stub for L{sys} which provides L{StringIO} streams as stdout and stderr.
    r:r2r%Nc� �||_||_yr')r:r2)r*r:r2s   r,r�zDummyStandardIO.__init__�s�������r-)r�r�r�r�r
r�r]r-r,r;r;�s!����v��v��$�r-r;c�$�eZdZdZdededdfd�Zy)r=zV
    Stub for L{warnings} which provides a C{showwarning} method that is a no-op.
    �args�kwargsr%Nc��y)z\
        Do nothing.

        @param args: ignored.
        @param kwargs: ignored.
        Nr])r�r�s  r,�showwarningzDummyWarningsModule.showwarning�r_r-)r�r�r�r�rr�r]r-r,r=r=�s!����3��#��$�r-r=)6r�rs�ior�signalr�typesr�typingrrrr	r
rrr
r�attrrrr�twisted.trial.unittest�twisted�twisted.internet.testingr�twisted.loggerrrrrrrr�twisted.python.filepathrrNr�_exitr�_pidfilerr r!�trial�unittest�TestCaser#rIrSr4r5r;r=r]r-r,�<module>r�s����
����R�R�R�'�'��2����-���+��{6�'�-�-�(�(�1�1�{6�|	�d��3�&�3��3�,�;��4��&
&�
&����r-

Zerion Mini Shell 1.0