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


W[�@s�dZddlmZmZddlZddlmZddlmZGdd�de	�Z
Gdd	�d	e	�ZGd
d�de	�ZGdd
�d
ee
e�Z
Gdd�dee
e�ZdS)z&
Tests for L{twisted.python.systemd}.
�)�division�absolute_importN)�TestCase)�	ListenFDsc@s eZdZdZdd�Zdd�ZdS)�InheritedDescriptorsMixinz�
    Mixin for a L{TestCase} subclass which defines test methods for some kind of
    systemd sd-daemon class.  In particular, it defines tests for a
    C{inheritedDescriptors} method.
    cCs&|�dd�}|�dddg|���dS)z�
        C{inheritedDescriptors} returns a list of integers giving the file
        descriptors which were inherited from systemd.
        ����	N��	getDaemon�assertEqual�inheritedDescriptors��self�sddaemon�r�B/usr/lib/python3/dist-packages/twisted/python/test/test_systemd.py�test_inheritedDescriptorssz3InheritedDescriptorsMixin.test_inheritedDescriptorscCs$|�dd�}|�|��|���dS)zW
        Any subsequent calls to C{inheritedDescriptors} return the same list.
        rrNrrrrr�
test_repeateds
�z'InheritedDescriptorsMixin.test_repeatedN)�__name__�
__module__�__qualname__�__doc__rrrrrrrs	rc@seZdZdZdd�ZdS)�MemoryOnlyMixinz�
    Mixin for a L{TestCase} subclass which creates creating a fake, in-memory
    implementation of C{inheritedDescriptors}.  This provides verification that
    the fake behaves in a compatible way with the real implementation.
    cCstt|||��S)a
        Invent C{count} new I{file descriptors} (actually integers, attached to
        no real file description), starting at C{start}.  Construct and return a
        new L{ListenFDs} which will claim those integers represent inherited
        file descriptors.
        )r�range)r�start�countrrrr0szMemoryOnlyMixin.getDaemonN)rrrrrrrrrr*src@s eZdZdZdd�Zdd�ZdS)�EnvironmentMixinaV
    Mixin for a L{TestCase} subclass which creates a real implementation of
    C{inheritedDescriptors} which is based on the environment variables set by
    systemd.  To facilitate testing, this mixin will also create a fake
    environment dictionary and add keys to it to make it look as if some
    descriptors have been inherited.
    cCs&tj��}t|�|d<t|�|d<|S)z�
        Create a copy of the process environment and add I{LISTEN_FDS} and
        I{LISTEN_PID} (the environment variables set by systemd) to it.
        �
LISTEN_FDS�
LISTEN_PID)�os�environ�copy�str)rr�pid�resultrrr�initializeEnvironmentCs
z&EnvironmentMixin.initializeEnvironmentcCs|�|t���}tj||d�S)a

        Create a new L{ListenFDs} instance, initialized with a fake environment
        dictionary which will be set up as systemd would have set it up if
        C{count} descriptors were being inherited.  The descriptors will also
        start at C{start}.
        )r"r)r'r!�getpidr�fromEnvironment)rrr�fakeEnvironmentrrrrNszEnvironmentMixin.getDaemonN)rrrrr'rrrrrr;src@seZdZdZdS)�MemoryOnlyTestszb
    Apply tests to L{ListenFDs}, explicitly constructed with some fake file
    descriptors.
    N)rrrrrrrrr+Zsr+c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�EnvironmentTestszV
    Apply tests to L{ListenFDs}, constructed based on an environment dictionary.
    cCsV|�dt���}tj|d�}tj|d�}|�ttdd��|���|�g|���dS)zV
        Only a single L{Environment} can extract inherited file descriptors.
        r�r"�N)	r'r!r(rr)r
�listrr)rr*�first�secondrrr�test_secondEnvironmentfs
z'EnvironmentTests.test_secondEnvironmentcCs4|�dt��d�}tj|d�}|�g|���dS)z�
        If the current process PID does not match the PID in the environment, no
        inherited descriptors are reported.
        r�r-N�r'r!r(rr)r
r�rr*rrrr�test_mismatchedPIDqsz#EnvironmentTests.test_mismatchedPIDcCs6|�dt���}|d=tj|d�}|�g|���dS)zz
        If the I{LISTEN_PID} environment variable is not present, no inherited
        descriptors are reported.
        rr r-Nr4r5rrr�test_missingPIDVariable{sz(EnvironmentTests.test_missingPIDVariablecCs,|�dd�}tj|d�}|�g|���dS)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.
        r�hello, worldr-N)r'rr)r
rr5rrr�test_nonIntegerPIDVariable�sz+EnvironmentTests.test_nonIntegerPIDVariablecCs6|�dt���}|d=tj|d�}|�g|���dS)zz
        If the I{LISTEN_FDS} environment variable is not present, no inherited
        descriptors are reported.
        rrr-Nr4r5rrr�test_missingFDSVariable�sz(EnvironmentTests.test_missingFDSVariablecCs0|�dt���}tj|d�}|�g|���dS)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.
        r8r-Nr4r5rrr�test_nonIntegerFDSVariable�sz+EnvironmentTests.test_nonIntegerFDSVariablecCsB|�tdtt���dd��t��}|�ttdd��|�	��dS)z�
        If the process environment is not explicitly passed to
        L{Environment.__init__}, the real process environment dictionary is
        used.
        r"�5)r rrr	N)
Zpatchr!r$r(rr)r
r/rrrrrr�test_defaultEnviron�s
��z$EnvironmentTests.test_defaultEnvironN)rrrrr2r6r7r9r:r;r=rrrrr,bs


r,)rZ
__future__rrr!Ztwisted.trial.unittestrZtwisted.python.systemdr�objectrrrr+r,rrrr�<module>s