%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_posixprocess.cpython-312.pyc

�

Ϫ�f�+����UdZddlZddlZddlZddlmZeeed<	ddlZddl	m
Z
dZddl
mZGd�d	�ZGd
�d�ZGd�d
e�ZGd�de�Zy#e$rdZY�:wxYw)z;
Tests for POSIX-based L{IReactorProcess} implementations.
�N)�Optional�platformSkip)�processznon-POSIX platform)�TestCasec�(�eZdZdZd�Zd�Zd�Zd�Zy)�FakeFilez>
    A dummy file object which records when it is closed.
    c� �||_||_y�N)�testcase�fd)�selfrrs   �I/usr/lib/python3/dist-packages/twisted/internet/test/test_posixprocess.py�__init__zFakeFile.__init__ s�� ��
����c�b�|jjj|j�yr
)r�_files�remover�r
s r�closezFakeFile.close$s���
�
���#�#�D�G�G�,rc��|Sr
�rs r�	__enter__zFakeFile.__enter__'s���rc�$�|j�yr
)r)r
�exc_type�	exc_value�	tracebacks    r�__exit__zFakeFile.__exit__*s���
�
�rN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrs����-��rrc� �eZdZdZdZd�Zd�Zy)�FakeResourceModulez�
    Fake version of L{resource} which hard-codes a particular rlimit for maximum
    open files.

    @ivar _limit: The value to return for the hard limit of number of open files.
    �c��||_yr
)�_limit�r
�limits  rrzFakeResourceModule.__init__8s	����rc�D�||jk(rd|jgSddgS)zX
        A fake of L{resource.getrlimit} which returns a pre-determined result.
        r�{i�)�
RLIMIT_NOFILEr&)r
�nos  r�	getrlimitzFakeResourceModule.getrlimit;s+����#�#�#��t�{�{�#�#��S�z�rN)rrr r!r+rr-rrrr#r#.s����M��rr#c�t�eZdZdZeZdZdZdZd�Z	d�Z
d�Zd�Zd�Z
d�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zy)�FDDetectorTestsa�
    Tests for _FDDetector class in twisted.internet.process, which detects
    which function to drop in place for the _listOpenFDs method.

    @ivar devfs: A flag indicating whether the filesystem fake will indicate
        that /dev/fd exists.

    @ivar accurateDevFDResults: A flag indicating whether the /dev/fd fake
        returns accurate open file information.

    @ivar procfs: A flag indicating whether the filesystem fake will indicate
        that /proc/<pid>/fd exists.
    Fc��y)z>
        Fake os.getpid, always return the same thing
        r*rrs r�getpidzFDDetectorTests.getpidZs��rc���tt|j�}|jr|d|j	�fzk(r|S|j
r|dk(r|jr|Sgd�St��)z�
        Fake os.listdir, depending on what mode we're in to simulate behaviour.

        @param arg: the directory to list
        z/proc/%d/fdz/dev/fd)�0�1�2)�map�strr�procfsr1�devfs�accurateDevFDResults�OSError)r
�arg�accurates   r�listdirzFDDetectorTests.listdir`s^���s�D�K�K�(���;�;�3�=�D�K�K�M�3C�#C�D��O��:�:�#��*��(�(���"�"��i�rc
���t|tttd��t|j�z
��}|jj|j�|S)aO
        This is a mock for L{open}.  It keeps track of opened files so extra
        descriptors can be returned from the mock for L{os.listdir} when used on
        one of the list-of-filedescriptors directories.

        A L{FakeFile} is returned which can be closed to remove the new
        descriptor from the open list.
        �)r�min�set�ranger�appendr)r
�fname�mode�fs    r�openfilezFDDetectorTests.openfileosG��
�T�3�s�5��;�/�#�d�k�k�2B�B�C�D�������1�4�4� ��rc�*�dtjd<y)zp
        Make the L{resource} module unimportable for the remainder of the
        current test method.
        N�resource)�sys�modulesrs r�hideResourceModulez"FDDetectorTests.hideResourceModule}s��
#'����J�rc�<�t|�tjd<y)a
        Make a L{FakeResourceModule} instance importable at the L{resource}
        name.

        @param limit: The value which will be returned for the hard limit of
            number of open files by the fake resource module's C{getrlimit}
            function.
        rJN)r#rKrLr's  r�revealResourceModulez$FDDetectorTests.revealResourceModule�s��#5�U�";����J�rc�r�|�	tjd=y|tjd<y#t$rYywxYw)zI
        Restore the original resource module to L{sys.modules}.
        NrJ)rKrL�KeyError)r
�values  r�replaceResourceModulez%FDDetectorTests.replaceResourceModule�s>���=�
��K�K�
�+�',�C�K�K�
�#���
��
�s�*�	6�6c�\�tj�|_|j|j_|j|j_|j
|j_gd�|_|j|jtjjd��y)z�
        Set up the tests, giving ourselves a detector object to play with and
        setting up its testable knobs to refer to our mocked versions.
        �rr$�rJN)r�_FDDetector�detectorr>r1rHr�
addCleanuprSrKrL�getrs r�setUpzFDDetectorTests.setUp�sl��
 �+�+�-��
� $����
�
��#�{�{��
�
��!%����
�
���������2�2�C�K�K�O�O�J�4O�Prc���d�}d�}�fd�}|||g�j_�j|�jj��y)z�
        L{FDDetector._getImplementation} returns the first method from its
        C{_implementations} list which returns results which reflect a newly
        opened file descriptor.
        c��td��)NzThis does not work)�
ValueErrorrrr�failWithExceptionzBFDDetectorTests.test_selectFirstWorking.<locals>.failWithException�s���1�2�2rc�
�gd�S�NrUrrrr�failWithWrongResultszEFDDetectorTests.test_selectFirstWorking.<locals>.failWithWrongResults�����rc�"���jddSr
)rrs�r�correctz8FDDetectorTests.test_selectFirstWorking.<locals>.correct�s����;�;�q�>�!rN�rX�_implementations�assertIs�_getImplementation)r
r_rbres`   r�test_selectFirstWorkingz'FDDetectorTests.test_selectFirstWorking�sH���	3�	�	"�
� ��*
��
�
�&�	
�
�
�g�t�}�}�?�?�A�Brc��d�}d�}||g|j_|j||jj��y)z�
        L{FDDetector._getImplementation} returns the last method from its
        C{_implementations} list if none of the implementations manage to return
        results which reflect a newly opened file descriptor.
        c�
�gd�S)N)���	rrrrrbz=FDDetectorTests.test_selectLast.<locals>.failWithWrongResults�rcrc�
�gd�Srarrrr�failWithOtherWrongResultszBFDDetectorTests.test_selectLast.<locals>.failWithOtherWrongResults�rcrNrf)r
rbrqs   r�test_selectLastzFDDetectorTests.test_selectLast�s@��	�	�
!�%�*
��
�
�&�
	
�
�
�/����1Q�1Q�1S�Trc�8�tj�}|jj}|j�|jj}|j�|jj}|j	||�|j||�y)z�
        Check that the identity of _listOpenFDs changes after running
        _listOpenFDs the first time, but not after the second time it's run.

        In other words, check that the monkey patching actually works.
        N)rrW�_listOpenFDsr�assertNotEqual�assertEqual)r
rX�first�second�thirds     r�!test_identityOfListOpenFDsChangesz1FDDetectorTests.test_identityOfListOpenFDsChanges�s}���&�&�(���%�%�.�.�������&�&�/�/�������%�%�.�.�����E�6�*������'rc���d|_|jt|jj�d|_d|_|j
gd�|jj	��y)z�
        L{_FDDetector._devFDImplementation} raises L{OSError} if there is no
        I{/dev/fd} directory, otherwise it returns the basenames of its children
        interpreted as integers.
        FTrUN)r9�assertRaisesr;rX�_devFDImplementationr:rvrs r�test_devFDImplementationz(FDDetectorTests.test_devFDImplementation�sQ����
����'�4�=�=�#E�#E�F���
�$)��!�����D�M�M�$F�$F�$H�Irc���d|_|jt|jj�d|_|jgd�|jj	��y)z�
        L{_FDDetector._procFDImplementation} raises L{OSError} if there is no
        I{/proc/<pid>/fd} directory, otherwise it returns the basenames of its
        children interpreted as integers.
        FTrUN)r8r|r;rX�_procFDImplementationrvrs r�test_procFDImplementationz)FDDetectorTests.test_procFDImplementation�sI��������'�4�=�=�#F�#F�G��������D�M�M�$G�$G�$I�Jrc�\�|jd�|jttd��t|jj���|jd�|jttd��t|jj���y)z�
        L{_FDDetector._fallbackFDImplementation} uses the L{resource} module if
        it is available, returning a range of integers from 0 to the
        minimum of C{1024} and the hard I{NOFILE} limit.
        iir@N)rOrv�listrCrX�_fallbackFDImplementationrs r�test_resourceFDImplementationz-FDDetectorTests.test_resourceFDImplementation�s~��	
�!�!�#�&������s���d�4�=�=�#J�#J�#L�M�	
�
	
�!�!�$�'������t���t�D�M�M�$K�$K�$M�N�	
rc��|j�|jttd��t|jj���y)z�
        L{_FDDetector._fallbackFDImplementation}, the implementation of last
        resort, succeeds with a fixed range of integers from 0 to 1024 when the
        L{resource} module is not importable.
        r@N)rMrvr�rCrXr�rs r�test_fallbackFDImplementationz-FDDetectorTests.test_fallbackFDImplementations>��	
���!������t���t�D�M�M�$K�$K�$M�N�	
rN)rrr r!r�skipr9r:r8r1r>rHrMrOrSr[rjrrrzr~r�r�r�rrrr/r/Dsi����D��E� ��
�F��
��'�	<�
,�
Q�C�0U�((�&
J�	K�
�$	
rr/c� �eZdZdZeZd�Zd�Zy)�FileDescriptorTestsz<
    Tests for L{twisted.internet.process._listOpenFDs}
    c	� �tj�D]'}	tj|tj��)y#t$rD}|jtj|jd||jfz�Yd}~�sd}~wwxYw)z�
        File descriptors returned by L{_listOpenFDs} are mostly open.

        This test assumes that zero-legth writes fail with EBADF on closed
        file descriptors.
        z2fcntl(%d, F_GETFL) failed with unexpected errno %dN)rrt�fcntl�F_GETFLr;rv�errno�EBADF)r
r�errs   r�test_openFDsz FileDescriptorTests.test_openFDs"sy���&�&�(�		�B�
����B��
�
�.�		���
�� � ��K�K��I�I�H��3�9�9�o�&����
�s�$A�	B
�	:B�B
c�:�ttj�}tj�}|j|j
�|�tj|j
��}|j||j
�kDd�	|j�|j|tj��tj|�|j|tj��y#tj|�wxYw)zB
        L{_listOpenFDs} lists expected file descriptors.
        z>Expected duplicate file descriptor to be greater than originalN)�open�os�devnullrrt�assertIn�fileno�dup�
assertTruer�assertNotIn)r
rG�openfdsrs    r�test_expectedFDsz$FileDescriptorTests.test_expectedFDs4s���
�������&�&�(���
�
�a�h�h�j�'�*��V�V�A�H�H�J�
��	
��������O�L�	
�
	�
�G�G�I��M�M�"�g�2�2�4�5�
�H�H�R�L�����W�1�1�3�4��
�H�H�R�L�s�4D�DN)rrr r!rr�r�r�rrrr�r�s����D��$)5rr�)r!r�r�rK�typingrr7�__annotations__r��twisted.internetrr�ImportError�twisted.trial.unittestrrr#r/r�rrr�<module>r�s���

�	�
���s�m����)��L�+���&��,T
�h�T
�nB5�(�B5��U�(�'�L�(�s�A�A&�%A&

Zerion Mini Shell 1.0