+
    üÐ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ð ´´c¼3°hµñ ó    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   € ô �Z‰Z�_‰_Ó€FÜ˜u›:€Fˆ<ÑØ"Ÿx™xÄÀeÄÓ(MÁ¸1¨3¨g«ÁÑ(MÓN€FÐÑÜ˜s›8€Fˆ<ÑØ€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±X¹cµ]ð 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Ñ!1´9×3CÑ3CÀfÕ3LÓ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   € ð 	�
‰
”2�yÔ"2°1´b·i²i³kÓ"BÔCÜ×,Ò,Ó.ˆØ×Ñœœe A u›oÓ.°×0MÑ0MÓ0OÖ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ˆØ×Ñœœe A q›kÓ*¨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   ø€ ÷ 
:ñ 
:±X¹cµ]ð 
:À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¤¤h¨wÓ&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±w¹sÁC¸xÕ7Hð 
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ˆÑ+Ù',Ô-¡u™e˜a“r¡uˆÑ-Ü˜Ó+ˆÜ�C×1Ñ1Ó3´X¸hÓ5GÖ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°(×2TÑ2TÓ2Vö	
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°Ô4¸TÔBÓC÷
:ó Dð
:ñ ‰<Ñ.Ó0±(ÀQÔ2GÐRTÔUÓV÷
Ió Wð
Iñ ‰5‘ A°Ô4¸TÔ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   