U €1g™Hã@sÎdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl m Z ddl mZddl mZddlmZddlmZddlmZdd lmZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl m Z ddl m!Z!ddl m"Z"ddl m#Z#ddl m$Z$ddl m%Z%ddl m&Z&ddl m'Z'ddl m(Z(ddl m)Z)ddl m*Z*ddl m+Z+dd l m,Z,dd!l m-Z-dd"l m.Z.dd#l m/Z/dd$l m0Z0dd%l m1Z1dd&l m2Z2dd'l m3Z3dd(l m4Z4Gd)d*„d*eƒZ5Gd+d,„d,eƒZ6Gd-d.„d.eƒZ7Gd/d0„d0eƒZ8Gd1d2„d2eƒZ9e)j:j;d3d4Gd5d6„d6eƒƒZGd;d<„d.fooé)rÚlistÚrangeÚAssertionErrorÚ call_count©ÚselfÚsleepr6r2r3r5Útest_retry_successEs   z%TestRetryDecorator.test_retry_successc sTtdddd‡fdd„ƒ}ttdƒƒ‰t t¡ |ƒW5QRX|jdksPt‚dS)Nr*r+r,csˆrˆ ¡ddqdSr/r0r2r3r2r5r6Ws z2TestRetryDecorator.test_retry_failure..fooé)rr8r9rÚraisesÚZeroDivisionErrorr;r:r<r2r3r5Útest_retry_failureTs    z%TestRetryDecorator.test_retry_failurec CsBttdddd„ƒ}t t¡ |ƒW5QRX|jdks>t‚dS)Nr+)Ú exceptionr.cSst‚dS©N)Ú TypeErrorr2r2r2r5r6esz2TestRetryDecorator.test_exception_arg..foor)rÚ ValueErrorrrArFr;r:r<r2r2r5Útest_exception_argcs    z%TestRetryDecorator.test_exception_argc CsDtdddddd„ƒ}t t¡ |ƒW5QRX|jdks@t‚dS)Nr*r,cSs dddSr/r2r2r2r2r5r6qsz4TestRetryDecorator.test_no_interval_arg..foor©rrrArBr;r:r<r2r2r5Útest_no_interval_argms    z'TestRetryDecorator.test_no_interval_argc CsDtdddddd„ƒ}t t¡ |ƒW5QRX|jdks@t‚dS)Nr*r+r,cSs dddSr/r2r2r2r2r5r6{sz0TestRetryDecorator.test_retries_arg..foorIr<r2r2r5Útest_retries_argys    z#TestRetryDecorator.test_retries_argc Cs&t t¡tdddW5QRXdS)Nr*r+)r-Útimeout)rrArGr)r=r>r2r2r5Útest_retries_and_timeout_argsƒs z0TestRetryDecorator.test_retries_and_timeout_argsN) Ú__name__Ú __module__Ú __qualname__rÚpatchr?rCrHrJrKrMr2r2r2r5r)Ds     r)c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)ÚTestSyncTestUtilsc Cs`tt ¡ƒtt ¡ƒd}tjdtdgƒd&t   tj ¡t|ƒW5QRXW5QRXdS)NiŸ†úpsutil.tests.retry.__iter__r©Z return_value) r(ÚosÚgetpidÚmaxÚpsutilZpidsrrQÚiterrrAZ NoSuchProcess)r=Znopidr2r2r5Útest_wait_for_pidŠs  z#TestSyncTestUtils.test_wait_for_pidc CsD| ¡}t|dƒ}| d¡W5QRXt|ƒtj |¡r@t‚dS)NÚwr6©Ú get_testfnÚopenÚwriter'rUÚpathÚexistsr:©r=ÚtestfnÚfr2r2r5Útest_wait_for_file‘s  z$TestSyncTestUtils.test_wait_for_filec Cs>| ¡}t|dƒW5QRXt|ddtj |¡r:t‚dS)Nr[T)Úempty)r]r^r'rUr`rar:©r=rcr2r2r5Útest_wait_for_file_empty˜s    z*TestSyncTestUtils.test_wait_for_file_emptyc CsJ| ¡}tjdtdgƒd$t t¡t|ƒW5QRXW5QRXdS)NrSrrT)r]rrQrYrrAÚIOErrorr'rgr2r2r5Útest_wait_for_file_no_fileŸs z,TestSyncTestUtils.test_wait_for_file_no_filec CsH| ¡}t|dƒ}| d¡W5QRXt|ddtj |¡sDt‚dS)Nr[r6F)Údeleter\rbr2r2r5Útest_wait_for_file_no_delete¥s   z.TestSyncTestUtils.test_wait_for_file_no_deletecCstdd„ƒdS)NcSsdS©Nr+r2r2r2r2r5Ú­óz3TestSyncTestUtils.test_call_until..r©r=r2r2r5Útest_call_until¬sz!TestSyncTestUtils.test_call_untilN) rNrOrPrZrerhrjrlrqr2r2r2r5rR‰s rRc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚTestFSTestUtilsc Cs&ttƒ}|jdkst‚W5QRXdS)NÚr)rÚ__file__Úmoder:©r=rdr2r2r5Útest_open_text²s zTestFSTestUtils.test_open_textc Cs&ttƒ}|jdkst‚W5QRXdS)NÚrb)rrtrur:rvr2r2r5Útest_open_binary¶s z TestFSTestUtils.test_open_binarycCs<| ¡}t|ƒtj |¡s t‚t|ƒtj |¡s8t‚dSrE)r]r!rUr`Úisdirr:rgr2r2r5Útest_safe_mkdirºs zTestFSTestUtils.test_safe_mkdirc Cs¦| ¡}t|dƒ ¡t|ƒtj |¡r.t‚t|ƒt |¡t|ƒtj |¡rXt‚t j dt t j dƒd.}t t ¡t|ƒW5QRX|js˜t‚W5QRXdS)Nr[zpsutil.tests.os.statÚ)Z side_effect)r]r^Úcloser"rUr`rar:ÚmkdirrrQÚOSErrorÚerrnoÚEINVALrrAZcalled)r=rcÚmr2r2r5Útest_safe_rmpathÁs   ÿ z TestFSTestUtils.test_safe_rmpathc Cs\| ¡}t ¡}t |¡t|ƒ t ¡tj ||¡ks>t‚W5QRXt ¡|ksXt‚dSrE)r]rUÚgetcwdr~rr`Újoinr:)r=rcÚbaser2r2r5Ú test_chdirÕs   $zTestFSTestUtils.test_chdirN)rNrOrPrwryr{rƒr‡r2r2r2r5rr±s rrc@s>eZdZdd„Zdd„Zejje dddd„ƒZ d d „Z d S) ÚTestProcessUtilscCsN| ¡}t |j¡}| ¡s t‚tƒ| ¡r2t‚tjjr>t‚tjj rJt‚dSrE) Úspawn_testprocrXÚProcessÚpidÚ is_runningr:rÚtestsZ _pids_startedZ_subprocesses_started)r=ZsubpÚpr2r2r5Útest_reap_childrenßs    z#TestProcessUtils.test_reap_childrencCsä| ¡\}}|j|jkst‚| ¡s(t‚| ¡s4t‚t ¡ ¡}||gksNt‚t ¡jdd}t|ƒdksnt‚||kszt‚||ks†t‚| ¡t   ¡ksšt‚| ¡|jks¬t‚t |ƒ| ¡rÀt‚| ¡sÌt‚t |ƒ| ¡ràt‚dS)NT)Ú recursiveé) Zspawn_children_pairr‹r:rŒrXrŠÚchildrenÚlenÚppidrUrVr%)r=ÚchildZ grandchildr’r2r2r5Útest_spawn_children_pairès"        z)TestProcessUtils.test_spawn_children_pairú POSIX only©ÚreasoncCs"| ¡\}}| ¡tjkst‚dSrE)Ú spawn_zombieÚstatusrXZ STATUS_ZOMBIEr:)r=Z_parentÚzombier2r2r5Útest_spawn_zombieýs z"TestProcessUtils.test_spawn_zombiecCsî| ¡}t|ƒ| |j¡t|ƒt | ¡j¡}t|ƒ| |j¡t|ƒtddg}tj|tj tj t d}t|ƒ| |j¡t|ƒ| ¡j}t|ƒ| |j¡t|ƒt rê|  ¡\}}t|ƒt|ƒ| |j¡| |j¡dS)Nz-cz3import time; [time.sleep(0.1) for x in range(100)];)ÚstdoutÚstderrÚenv) r‰r%Z assertPidGoner‹rXrŠr ÚPopenÚ subprocessÚPIPErrrš)r=rŽÚcmdr‹Úparentrœr2r2r5Útest_terminates>  ýü     zTestProcessUtils.test_terminateN) rNrOrPrr–rÚmarkÚskipifrrr¦r2r2r2r5rˆÞs   rˆc@sleZdZdd„Zejje dddd„ƒZdd„Z ejje ddejje pNe d dd d „ƒƒZ d d „Z dS)Ú TestNetUtilsc Cs>tƒ}t td|fd¡}| ¡d|ks0t‚W5QRXdS)Nr|©Úaddrr+)rÚ contextlibÚclosingrÚ getsocknamer:)r=ÚportÚsr2r2r5r+szTestNetUtils.bind_socketr—r˜c Cs¼| ¡}t|ƒ}t |¡\|jtjks,t‚|jtj ks.funrÓré é)ÚtimesÚ warmup_timesé)Úexecuter:)r=rÕr2rÔr5Ú test_timeszs zTestMemLeakClass.test_timesc CsÌt t¡|jdd„ddW5QRXt t¡|jdd„ddW5QRXt t¡|jdd„ddW5QRXt t¡|jd d„dd W5QRXt t¡|jd d„dd W5QRXdS) NcSsdS©Nrr2r2r2r2r5rn…roz1TestMemLeakClass.test_param_err..r©rØcSsdSrÝr2r2r2r2r5rn‡roéÿÿÿÿcSsdSrÝr2r2r2r2r5rn‰ro)rÙcSsdSrÝr2r2r2r2r5rn‹ro)Ú tolerancecSsdSrÝr2r2r2r2r5rnro)r-)rrArGrÛrpr2r2r5Útest_param_errƒs     zTestMemLeakClass.test_param_errz skipped on CIr˜zskipped during test coveragec CsFg}|fdd„}z,tjtdd|j|ddW5QRXW5~XdS)NcSs| dd¡dS)NZøxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxé©Úappend©Úlsr2r2r5rÕ•sz+TestMemLeakClass.test_leak_mem..funz extra-mem©ÚmatchédrÞ)rrAr:rÛ)r=rærÕr2r2r5Ú test_leak_mems  zTestMemLeakClass.test_leak_memc sJ‡‡fdd„}g‰trdnd}tjtd|dˆ |¡W5QRXdS)Ncs"ttƒ}ˆ |j¡ˆ |¡dSrE)r^rtZ addCleanupr}rä)rd©Úboxr=r2r5rÕ s z1TestMemLeakClass.test_unclosed_files..funÚfdÚhandlez unclosed rç)rrrAr:rÛ)r=rÕrÃr2rër5Útest_unclosed_filesŸs  z$TestMemLeakClass.test_unclosed_filescs>‡fdd„}g‰d}|j||dddtˆƒ|dks:t‚dS)Ncsˆ dd¡dS)NZxxxxxxxxxxxxxxxxxxxxxxxxrârãr2rår2r5rÕ«sz,TestMemLeakClass.test_tolerance..funréri€ )rØrÙràr+)rÛr“r:)r=rÕrØr2rår5Útest_toleranceªs ÿzTestMemLeakClass.test_tolerancec Csddd„}| t|¡t t¡| t|¡W5QRXdd„}t t¡| t|¡W5QRXdS)NcSs dddSr/r2r2r2r2r5Úfun_1¶sz2TestMemLeakClass.test_execute_w_exc..fun_1cSsdSrEr2r2r2r2r5Úfun_2½sz2TestMemLeakClass.test_execute_w_exc..fun_2)Z execute_w_excrBrrArr:)r=rñròr2r2r5Útest_execute_w_excµs   z#TestMemLeakClass.test_execute_w_excN)rNrOrPr rÜrárr§r¨r r rêrïrðrór2r2r2r5rÒxs     rÒc@sVeZdZdd„Zdd„Zdd„Zdd„Zejj e d d d d „ƒZ d d„Z dd„Z dS)ÚTestFakePytestcCs(t ¡}| |¡t ¡}| |¡}|SrE)ÚunittestZ TestSuiteZaddTestZTextTestRunnerÚrun)r=ÚklassÚsuiteÚrunnerÚresultr2r2r5Úrun_test_classÅs   zTestFakePytest.run_test_classc Cs¸t t¡}ddW5QRXt|jtƒs.t‚tjtdd}tdƒ‚W5QRXz&tjtdd}tdƒ‚W5QRXWn2tk r¨}zt|ƒdks˜t‚W5d}~XYn X| d¡‚dS)Nr+rr6rçÚbarz"foo" does not match "bar"úexception not raised) rrArBÚ isinstanceÚvaluer:rGÚstrÚfail)r=ÚcmÚerrr2r2r5Ú test_raisesÌs "zTestFakePytest.test_raisescCsVtjjdddd„ƒ}|ƒdks$t‚tjjddGdd„dƒƒ}|ƒ ¡dksRt‚dS)NrÐrÑcSsdSrmr2r2r2r2r5r6Ýsz%TestFakePytest.test_mark..foor+c@seZdZdd„ZdS)z%TestFakePytest.test_mark..FoocSsdSrmr2rpr2r2r5rüåsz)TestFakePytest.test_mark..Foo.barN)rNrOrPrür2r2r2r5ÚFooãsr)rr§Ú xdist_groupr:rü)r=r6rr2r2r5Ú test_markÜs    zTestFakePytest.test_markcCs–Gdd„dtjƒ}| |dƒ¡}| ¡s,t‚t|jƒdks>t‚|jdddksTt‚Gdd„dtjƒ}| |dƒ¡}| ¡s€t‚t|jƒdks’t‚dS)Nc@s$eZdZejjddddd„ƒZdS)ú,TestFakePytest.test_skipif..TestCaseTr™r˜cSsddks t‚dSrm©r:rpr2r2r5r6ìsú0TestFakePytest.test_skipif..TestCase.fooN©rNrOrPrr§r¨r6r2r2r2r5ÚTestCaseësr r6r+rr™c@s$eZdZejjddddd„ƒZdS)rFr™r˜cSsddks t‚dSrmr rpr2r2r5r6ösr Nr r2r2r2r5r õs©rõr rûZ wasSuccessfulr:r“Zskipped©r=r rúr2r2r5Ú test_skipifês  zTestFakePytest.test_skipifznot PY3r˜cCsXGdd„dtjƒ}| |dƒ¡}| ¡s,t‚t|jƒdks>t‚|jdddksTt‚dS)Nc@seZdZdd„ZdS)z*TestFakePytest.test_skip..TestCasecSst d¡ddkst‚dS)Nr™r+r)rÚskipr:rpr2r2r5r6s z.TestFakePytest.test_skip..TestCase.fooN)rNrOrPr6r2r2r2r5r sr r6r+rr™r rr2r2r5Ú test_skipþs  zTestFakePytest.test_skipc Cs¼|jtd}t |¡ttj |d¡dƒW5QRXttj |d¡dƒ}| t  d¡  ¡¡W5QRXt j   tjd|¡6| td¡t ¡}| ¡dks¤t‚W5QRXW5QRXdS) N)Údirz __init__.pyr[z test_file.pyz¬ import unittest class TestCase(unittest.TestCase): def test_passed(self): pass r zFake pytest module was usedr+)r]r rUr~r^r`r…r_ÚtextwrapÚdedentÚlstriprrQÚobjectrXrZassertWarnsRegexÚ UserWarningrÚmainZcountTestCasesr:)r=Ztmpdirrdrør2r2r5Ú test_main s   ÿzTestFakePytest.test_mainc Csìt t¡tjdtddW5QRXz*t t¡tjdtddW5QRXWntk rdYn X| d¡‚tjtddtjdtddW5QRXz.tjtddtjdtddW5QRXWntk rÜYn X| d¡‚dS)Nr6r+)Ú stacklevelrýrçrü)rZwarnsrÚwarningsÚwarnÚDeprecationWarningr:rrpr2r2r5Ú test_warnss    zTestFakePytest.test_warnsN)rNrOrPrûrrrrr§r¨rrrrr2r2r2r5rôÄs rôc@seZdZdd„Zdd„ZdS)ÚTestTestingUtilscCsLt ¡}t|ƒ}| ¡dd„| |j¡Dƒdd}|ƒ| ¡ksHt‚dS)NcSsg|]}|ddkr|‘qS)r+r”r2©Ú.0Úxr2r2r5Ú ?s z;TestTestingUtils.test_process_namespace..r)rXrŠrÚtestrYÚgettersr”r:)r=rŽÚnsrÕr2r2r5Útest_process_namespace;s z'TestTestingUtils.test_process_namespacecCs:tƒ}dd„| |j¡Dƒdd}|ƒt ¡ks6t‚dS)NcSsg|]}|ddkr|‘qS)r+Ú net_if_addrsr2r r2r2r5r#Ds z:TestTestingUtils.test_system_namespace..r)r#rYr%rXr(r:)r=r&rÕr2r2r5Útest_system_namespaceBsz&TestTestingUtils.test_system_namespaceN)rNrOrPr'r)r2r2r2r5r:src@seZdZdd„ZdS)ÚTestOtherUtilscCs.tt dd¡dddƒƒst‚ttƒƒr*t‚dS)Nr6za b cr+r‘r7)rrÆÚ namedtupler:Útuplerpr2r2r5Útest_is_namedtupleIsz!TestOtherUtils.test_is_namedtupleN)rNrOrPr-r2r2r2r5r*Hsr*)@Ú__doc__rÆr¬r€rUr³r¶r¢rrõrrXZ psutil.testsrrrZpsutil._commonrrrZpsutil._compatrr r r r r rrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)rRrrrˆr©r§rrÒrôrr*r2r2r2r5Úsx                                      E(-LN Kv