+
    Dfj                         R t ^ RIt^ RIHtHtHt ^ RIHtHtH	t	 ^ RI
Ht ^ RIHtHtHt ^ RIHt ^ RIHt ^RIHt R	 R
 lt ! R R]4      tR# )z&
Tests for L{twisted.python.systemd}.
N)DictMappingSequence)assert_thatequal_tonot_)given)dictionariesintegerslists)	ListenFDs)SynchronousTestCase)systemdDescriptorNamesc                ^    V ^8  d   QhR\         R\        R\        \        \        3,          /# )   countpidreturn)intobjectr   str)formats   "B/usr/lib/python3/dist-packages/twisted/python/test/test_systemd.py__annotate__r      s)      C f c3h     c                    \         P                  P                  4       p\        V 4      VR&   RP	                  \        V 4       Uu. uF  q3 R2NK	  	  up4      VR&   \        V4      VR&   V# u upi )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copyr   joinrange)r   r   resultns   &&  r   buildEnvironmentr'      sf     ZZ__Fu:F<"xxe(M13g(MNFs8F<M )Ns   A,c            	         a  ] tR t^%t o Rt]! ]! ]! 4       ^ ^
R7      4      V 3R lR l4       tV 3R lR lt	V 3R lR lt
V 3R	 lR
 ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR lt]! ]! ]! ^ ^
R7      RR7      4      V 3R lR l4       t]! ]! ]! 4       ]! ^ R7      ^
R7      4      V 3R lR l4       t]! ]! ]! ^ ^
R7      RR7      4      V 3R lR l4       tRtV tR# ) ListenFDsTestszN
Apply tests to L{ListenFDs}, constructed based on an environment dictionary.
)min_sizemax_sizec                4   < V ^8  d   QhRS[ S[,          RR/# )r   namesr   N)r   r   )r   __classdict__s   "r   r   ListenFDsTests.__annotate__+   s#     I IXc] It Ir   c                |   \        V4      p\        \        \        P                  \        P                  V,           4      4      p\        P
                  ! R\        \        P                  ! 4       4      R\        V4      RRP                  V4      /4      p\        V\        \        V\        V4      4      4      4       R# )aX  
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   r   r   r   N)lenlistr$   r   _STARTfromEnvironmentr   r    getpidr#   r   r   tuple)selfr-   numFDsdescriptorsfdss   &&   r   test_fromEnvironmentEquivalence.ListenFDsTests.test_fromEnvironmentEquivalence*   s     U5!1!193C3Cf3LMN''c"))+.c&k #((5/
 	C)Ku"FGHr   c                   < V ^8  d   QhRR/# r   r   N )r   r.   s   "r   r   r/   @   s     Q QT Qr   c           	         V P                  \        R\        ^\        P                  ! 4       4      4       \        P
                  ! 4       pV P                  \        \        ^^4      4      VP                  4       4       R# )z
If the process environment is not explicitly passed to
L{ListenFDs.fromEnvironment}, the real process environment dictionary
is used.
r!   N)
patchr    r'   r5   r   r4   assertEqualr2   r$   inheritedDescriptors)r7   sddaemons   & r   test_defaultEnviron"ListenFDsTests.test_defaultEnviron@   sT     	

2y"21biik"BC,,.eAuo.0M0M0OPr   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/   J   s     < < <r   c                F   \        ^\        P                  ! 4       4      p\        P                  ! VR7      p\        P                  ! VR7      pV P                  \        \        ^^4      4      VP                  4       4       V P                  . VP                  4       4       R# )z
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.
r!   N)	r'   r    r5   r   r4   rB   r2   r$   rC   )r7   envfirstseconds   &   r   test_secondEnvironment%ListenFDsTests.test_secondEnvironmentJ   ss     q"))+.))#6**37eAqk*E,F,F,HIV88:;r   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/   W   s     
> 
>D 
>r   c                    \        ^\        P                  ! 4       ^,           4      p\        P                  ! VR7      pV P                  . VP                  4       4       R# )a&  
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.
rI   Nr'   r    r5   r   r4   rB   rC   r7   rJ   rD   s   &  r   test_mismatchedPID!ListenFDsTests.test_mismatchedPIDW   sC     q"))+/2,,S9X::<=r   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/   c   s     
> 
> 
>r   c                    \        ^\        P                  ! 4       4      pVR \        P                  ! VR7      pV P                  . VP                  4       4       R# )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.
r   rI   NrQ   rR   s   &  r   test_missingPIDVariable&ListenFDsTests.test_missingPIDVariablec   sG     q"))+.,,S9X::<=r   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/   o   s     > >D >r   c                    \        ^R4      p\        P                  ! VR7      pV P                  . VP	                  4       4       R# )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.
hello, worldrI   N)r'   r   r4   rB   rC   rR   s   &  r   test_nonIntegerPIDVariable)ListenFDsTests.test_nonIntegerPIDVariableo   s9    
 q.1,,S9X::<=r   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/   x   s     	> 	> 	>r   c                    \        ^\        P                  ! 4       4      pVR VR \        P                  ! VR7      pV P                  . VP                  4       4       R# )zz
If the I{LISTEN_FDS} and I{LISTEN_FDNAMES} environment variables
are not present, no inherited descriptors are reported.
r   r   rI   NrQ   rR   s   &  r   test_missingFDSVariable&ListenFDsTests.test_missingFDSVariablex   sP    
 q"))+. !,,S9X::<=r   c                   < V ^8  d   QhRR/# r>   r?   )r   r.   s   "r   r   r/      s     > >D >r   c                    \        ^\        P                  ! 4       4      pRVR&   \        P                  ! VR7      pV P                  . VP                  4       4       R# )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.
r[   r   rI   NrQ   rR   s   &  r   test_nonIntegerFDSVariable)ListenFDsTests.test_nonIntegerFDSVariable   sI    
 q"))+.*L,,S9X::<=r   )	min_value	max_valueT)uniquec                4   < V ^8  d   QhRS[ S[,          RR/# r   r9   r   Nr   r   )r   r.   s   "r   r   r/      s     
: 
:Xc] 
:t 
:r   c                    \        \        \        V4      4      p\        W4      pVP	                  4       p\        V\        V4      4       VP                  ^4       \        V\        \        V4      4      4       R# )zU
L{ListenFDs.inheritedDescriptors} returns a copy of the inherited
descriptors list.
N)	r6   mapr   r   rC   r   r   appendr   )r7   r9   r-   r:   fdsCopys   &&   r   test_inheritedDescriptors(ListenFDsTests.test_inheritedDescriptors   s\     c#{+,+**,K'!23qKhw&7!89r   )rf   )r+   c                :   < V ^8  d   QhRS[ S[S[3,          RR/# )r   expectedr   N)r   r   r   )r   r.   s   "r   r   r/      s(     
I 
IwsCx7H 
IT 
Ir   c                    \        VP                  4       4      pV UUu. uF  w  r4VNK	  	  pppV UUu. uF  w  rFVNK	  	  ppp\        Wu4      p\        VP	                  4       \        V4      4       R# u uppi u uppi )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)r2   itemsr   r   inheritedNamedDescriptorsr   )	r7   rs   ru   name_r-   fdr9   r:   s	   &&       r   test_inheritedNamedDescriptors-ListenFDsTests.test_inheritedNamedDescriptors   sk     X^^%&%*+U'$U+',-uearu-+C113Xh5GH ,-s
   A4A:c                4   < V ^8  d   QhRS[ S[,          RR/# rj   rk   )r   r.   s   "r   r   r/      s     
 
# 
4 
r   c                   \        \        \        V4      4      p\        W4      pV P	                  VP                  4       VP                  4       4       V P	                  VP                  4       VP                  4       4       R# )zh
Any subsequent calls to C{inheritedDescriptors} and
C{inheritedNamedDescriptors} return the same list.
N)r6   rm   r   r   rB   rC   rv   )r7   r9   r-   rD   s   &&  r   test_repeatedListenFDsTests.test_repeated   sk     c#{+,[0))+X-J-J-L	
 	..0(2T2T2V	
r   r?   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r;   rE   rM   rS   rW   r\   r`   rd   r
   rp   r	   rz   r~   __static_attributes____classdictcell__)r.   s   @r   r)   r)   %   s      5')ACDI EI*Q Q< <
> 
>
> 
>> >	> 	>> > 5A4TBC
: D
: <.0(Q2GRTUV
I W
I 5A4TBC
 D
r   r)   )r   r    typingr   r   r   hamcrestr   r   r   
hypothesisr   hypothesis.strategiesr	   r
   r   twisted.python.systemdr   twisted.trial.unittestr   
strategiesr   r'   r)   r?   r   r   <module>r      sA   
 
 * * 0 0  ? ? , 6 . O
( O
r   