gfD,dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z n #e $rdZ YnwxYw ddl Z n #e $rdZ YnwxYwddl Z ddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZd ZdZe jpdZe o eZej ej!e"Z#e j$j%Z%ddZ&GddZ'Gdde j(Z)Gdde j*Z+Gdde+Z,d dZ-dZ.dZ/dZ0e1dkr e0dSdS)!aA Unit test runner, providing new features on top of unittest module: - colourized output - parallel run (UNIX only) - print failures/tracebacks on CTRL+C - re-run failed tests only (make test-failed) Invocation examples: - make test - make test-failed Parallel: - make test-parallel - make test-process ARGS=--parallel )print_functionN)hilite) print_color)term_supports_colors)super) CI_TESTING)import_module_by_path) print_sysinfo) reap_children) safe_rmpathz.failed-tests.txtFc||dkr tjn tj}trt ||||dSt ||dS)Nred)boldfile)r)sysstderrstdout USE_COLORSrprint)msgcolorrrs u/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/tests/runner.pycprintr>sZ |"e^^szzCT555555 ccveZdZeZdgZdejvregddZ dZ dZ dZ dZ d S) TestLoaderztest_memleaks.pyWHEELHOUSE_UPLOADER_USERNAME)z test_osx.pyz test_linux.pyz test_posix.pycNfdtjjDS)Ncg|]Z}|drC|dr.|jv5tjj|[S)test_.py) startswithendswith skip_filesospathjointestdir).0xselfs r z,TestLoader._get_testmods..Osn***<<((*-.ZZ->->*(( T\1--)((r)r'listdirr*)r-s`r _get_testmodszTestLoader._get_testmodsNs:****DL11*** *rc#K|D]f}t|}t|D]E}t||}t |t rt |tjr|VFgdS)zgIterate over all test files in this directory and return all TestCase classes in them. N) r0r dirgetattr isinstancetype issubclassunittestTestCase)r-r(modnameobjs r_iter_testmod_classesz TestLoader._iter_testmod_classesTs&&((  D'--CC  c4((c4(("3(9::III    rctj}|D]&}t|}||'|SN)r7 TestSuiter<loadTestsFromTestCaseaddTest)r-suiter;tests rallzTestLoader.all`sR"$$--//  C(--D MM$     rctj}tjt s|St t d5}|}dddn #1swxYwY|D]6}tj |}| |7|S)Nrt) r7r?r'r(isfileFAILED_TESTS_FNAMEopenreadsplitdefaultTestLoaderloadTestsFromNamerA)r-rBfnamesnrCs r last_failedzTestLoader.last_failedgs"$$w~~011 L $d + + %qFFHHNN$$E % % % % % % % % % % % % % % %  A-??BBD MM$     s'BB Bc|drBtjtj|d}t j|S)Nr#r)r%r'r(splitextbasenamer7rLrM)r-r:s r from_namezTestLoader.from_namessW ==   ?7##BG$4$4T$:$:;;A>D);;DAAArN)__name__ __module__ __qualname__HEREr*r&r'environextendr0r<rDrQrUrrrrGsG$%J%33KKKLLL***      BBBBBrrc6eZdZdZdZdZdZfdZxZS)ColouredResultcftj||tdddS)NOKgreen)r7 TestResult addSuccessr)r-rCs rrczColouredResult.addSuccess{s1&&tT222tWrcltj|||tddddS)NERRORrTr)r7rbaddErrorrr-rCerrs rrgzColouredResult.addErrors8$$T4555wD))))))rchtj|||tdddS)NFAILr)r7rb addFailurerrhs rrlzColouredResult.addFailures3&&tT3777vurctj|||td|zddS)Nz skipped: %sbrown)r7rbaddSkiprstrip)r-rCreasons rrozColouredResult.addSkips@##D$777}v||~~-w77777rcxt|d|dk}t||dS)Nrrerf)rrprintErrorList)r-flavourerrors __class__s rrszColouredResult.printErrorLists<%g.@AAA w/////r) rVrWrXrcrgrlrors __classcell__rvs@rr^r^yst***888000000000rr^cdeZdZdZerenejZfdZ fdZ dZ dZ fdZ dZdZxZS) ColouredTextRunnerz A coloured text runner which also prints failed tests on KeyboardInterrupt and save failed tests in a file so that they can be re-run. c`tj|i|t|_dSr>)r__init__set failed_tnames)r-argskwargsrvs rr|zColouredTextRunner.__init__s1$)&))) UUrc\t|_|jSr>)r _makeResultresult)r-rvs rrzColouredTextRunner._makeResults$gg))++ {rc|jrSttd5}|jD]}||dz ddddS#1swxYwYdSdS)Nwt )r~rIrHwrite)r-rNtnames r_write_last_failedz%ColouredTextRunner._write_last_faileds   *($// *1!/**EGGEDL))))* * * * * * * * * * * * * * * * * * * * *s#AAAc|sF|j|jzD]8}|d}|j|7dSdS)Nr) wasSuccessfulrufailuresidr~add)r-rtrs r _save_resultzColouredTextRunner._save_resultsm##%% .]V_4 . .! "&&u---- . . . .rc t|}|||S#ttf$r5|jj}|tj dwxYw)Nr) rrunrKeyboardInterrupt SystemExitrunnerr printErrorsrexit)r-rBrrvs r_runzColouredTextRunner._runs WW[[''F   f % % %M ":.   ['F    (1++  s !;ABc|r)rrr)r-rBrs rrzColouredTextRunner.runs75!! 6''))*****r)rVrWrX__doc__rr^r7TextTestResult resultclassr|rrrrrrrwrxs@rrzrzs%/K..H4KK##### *** ...     +++++++rrzc@eZdZedZedZdZdS)ParallelRunnercfd}tj|tj_tjt}tj||S)NcR||}tj|j|Sr>)atexitregisterclose)fdmodekwdsstream orig_fdopens rfdopenz+ParallelRunner._parallelize..fdopens+ [T**F OFL ) ) )Mr)r'rconcurrencytestfork_for_testsNWORKERSConcurrentTestSuite)rBrforkerrs @r _parallelizezParallelRunner._parallelizesS     i $*! /9925&AAArctj}tj}|D]}|dkrt|tjr|jdj}n/t|tjr|}ntd|zt|ddr| || |||fS)Nrzcan't recognize type %r _serialrunF) r7r?countTestCasesr4_testsrvr8 TypeErrorr3rA)rBserialparallelrC test_classs r _split_suitezParallelRunner._split_suites#%%%'' ' 'D""$$))D("455 B![^5 D("344 B!  9D @AAAz<77 't$$$$  &&&&!!rc||\}}||}tdtzddt j}||}t j|z }t j}t j |d\}} | r!td| zdtt j}||} t j|z } | s,| d kr| tt|j|j|jf\} } }tt| j| j| jf\}}}t't)jd |j| | ||| j|||| f zt'd |j| jz|| ztfz| o| }||dS) Nz(starting parallel tests using %s workersraTrfr)timeoutzalive processes %srra= +----------+----------+----------+----------+----------+----------+ | | total | failures | errors | skipped | time | +----------+----------+----------+----------+----------+----------+ | parallel | %3s | %3s | %3s | %3s | %.2fs | +----------+----------+----------+----------+----------+----------+ | serial | %3s | %3s | %3s | %3s | %.2fs | +----------+----------+----------+----------+----------+----------+ z&Ran %s tests in %.3fs using %s workers)rrrrtimerpsutilProcesschildren wait_procsr rrrmaplenrruskippedrtextwrapdedenttestsRunr)r-rB ser_suite par_suiterpar par_elapsedorphansgonealiveser ser_elapsed par_failspar_errs par_skips ser_failsser_errs ser_skipsoks rrzParallelRunner.runsd#0077 9%%i00  9HDT # # # # IKKii ""ikkAo .""++--';;; e   '%/ 7 7 7 OOO IKKii ""ikkAo   "" y'?'?'A'AA'E'E OO   ),S3<36:36;3@*A*A& 8Y*-S3<36:36;3@*A*A& 8Y ho<Hi<HiN N O O P P P 6 L3< '{)BH:NN O O O    8S%6%6%8%8 2rN)rVrWrX staticmethodrrrr\rrrrsZ B B\ B""\"&.....rrcd}|rWtjr |dn?t |dn,tdkr |dnt t St t S)Nc,t|dzddS)Nz Running serial tests instead.r)r)rs rwarnzget_runner..warnss55u=====rz$Can't run parallel tests on Windows.z(concurrencytest module is not installed.rzOnly 1 CPU available.) verbosity)rWINDOWSrrr VERBOSITYrz)rrs r get_runnerrs>>>7 > 7 D7 8 8 8 8  $ D; < < < < ]] D( ) ) ) )!I666 6  2 2 22rct|}t}||dSr>)rrUrr)r:rBrs r run_from_namer,s: LL " "4 ( (E \\F JJurcLtjjdSr>)r _psplatformcext set_testingr\rrsetupr2s" '')))))rctd}tj|d}|dddd|d ddd |\}}|jst tt}|rWt|d kr(| tj d S| |d }n0|jr|}n|}trt!t#|j}||dS) Nz*python3 -m psutil.tests [opts] [test-name]zrun unit tests)usage descriptionz --last-failed store_trueFzonly run last failed tests)actiondefaulthelpz --parallelzrun tests in parallelrr)roptparse OptionParser add_option parse_argsrQr rHrr print_usagerrrUrDrr rrr)rparseroptsrloaderrBrs rmainr9se GGG 8E  "rs &%%%%%   MMMM FFFOOO !!!!!!&&&&&&////// ######......&&&&&&&&&&&&$$$$$$  ( 6    "^ 6 4 4 6 6  wrwx0011 2H/B/B/B/B/B/B/B/Bd00000X,000.4+4+4+4+4+04+4+4+nRRRRR'RRRj 3 3 3 3  ***D zDFFFFFs+55>AA