Ë ÏªÍf±ãó°—dZddlZddlmZmZmZddlmZmZm Z ddl m Z ddl m Z mZmZddlmZddlmZd d lmZd ed 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 |«Dcgc]}|›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 „Z dd „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€ð ‰ ”2yÔ"2°1´b·i±i³kÓ"BÔCÜ×,Ñ,Ó.ˆØ ×Ñœœe A u›oÓ.°×0MÑ0MÓ0OÕPr5có>—tdtj««}tj|¬«}tj|¬«}|j t tdd««|j««|j g|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|¬«}|j g|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|¬«}|j g|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|¬«}|j g|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|¬«}|j g|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_inheritedDescriptorss^€ô ”cœ#˜{Ó+Ó,ˆÜ˜  UÓ+ˆØ×*Ñ*Ó,ˆÜK¤¨'Ó!2Ô3؉qÔÜK¤¤h¨wÓ&7Ó!8Õ9r5)rS)r'Úexpectedcóü—t|j««}|Dcgc]\}}|‘Œ }}}|Dcgc]\}}|‘Œ }}}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 r r Útwisted.python.systemdr Útwisted.trial.unittestrÚ strategiesrriÚobjectrr"r$rjr5r!úrss^ðñó  ß*Ñ*ç0Ñ0Ýß?Ñ?å,Ý6Ý.ð ˜Cð  fð °°c¸3°h±ó ô O Ð(õO r5