a 5êdg_ã@s¾ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZddlmZejZGdd„de jƒZdd„Zed krºeƒdS) éN)Úsupport)Ú script_helper)Ú socket_helperc@sÌeZdZdd„Zdd„Zdd„Ze d¡dd „ƒZd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Ze eed ƒd!¡d"d#„ƒZd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"d:d;„Z#dd?„Z%d@dA„Z&dBdC„Z'dDdE„Z(dFdG„Z)GdHdI„dIƒZ*GdJdK„dKƒZ+dLdM„Z,dNdO„Z-dPdQ„Z.e eedRƒo€eedSƒdT¡dUdV„ƒZ/dfdXdY„Z0dZd[„Z1d\d]„Z2d^d_„Z3d`da„Z4dbdc„Z5ddde„Z6dWS)gÚ TestSupportcCs t d¡| tjtjd¡dS)NÚftplibÚfoo)rÚ import_moduleÚ assertRaisesÚunittestÚSkipTest©Úself©rú-/usr/local/lib/python3.9/test/test_support.pyÚtest_import_modules zTestSupport.test_import_modulecCst d¡dS)Nr)rZimport_fresh_moduler rrrÚtest_import_fresh_modulesz$TestSupport.test_import_fresh_modulecCs.| t |d¡|j¡| tjtj|d¡dS)NÚtest_get_attributer)Ú assertEqualrZ get_attributerr r r r rrrrsÿzTestSupport.test_get_attributezfailing buildbotscCs| t ¡tj¡dS©N)rrZget_original_stdoutÚsysÚstdoutr rrrÚtest_get_original_stdout#sz$TestSupport.test_get_original_stdoutcCs2ddl}| dtj¡t d¡| dtj¡dS)NrÚsched)rÚassertInrÚmodulesrZunloadÚ assertNotIn)r rrrrÚ test_unload's zTestSupport.test_unloadcCsTttdƒ}Wdƒn1s 0Yt t¡| tj t¡¡t t¡dS)NÚw)ÚopenÚTESTFNrÚunlinkÚ assertFalseÚosÚpathÚexists)r ÚfrrrÚ test_unlink-s   zTestSupport.test_unlinkcCsbtjd}tj |d¡}t |¡t |¡t |¡| tj |¡¡t  tdd¡t |¡Wdƒn1sv0Yt |¡t |¡t  |t j t j B¡t  tdd¡t |¡Wdƒn1sÖ0Y| tj |¡¡t |¡t |¡t  |d¡t  tdd¡t |¡Wdƒn1sB0Y| tj |¡¡dS)NÚdZsubdirÚverboser)rrr"r#ÚjoinÚmkdirÚrmtreer!r$Ú swap_attrÚchmodÚstatÚS_IRUSRÚS_IXUSR)r ÚdirpathZ subdirpathrrrÚ test_rmtree4s(    (  (   *zTestSupport.test_rmtreec CsÈtd}t|dƒ}td|dWdƒn1s40Ytj dtj¡t  ¡zNt tƒ}|  ttj ¡t  t¡| ttj ¡Wtjd=t  |¡t  d¡ntjd=t  |¡t  d¡0dS)Nz.pyrzfoo = 1©ÚfilerÚ __pycache__)rrÚprintrr#Úinsertr"ÚcurdirÚ importlibÚinvalidate_cachesÚ __import__rrrZforgetrr r+)r Z mod_filenamer%ÚmodrrrÚ test_forgetLs  *   þ zTestSupport.test_forgetcCst tjdf¡}| ¡dS)Nr)ÚsocketÚ create_serverrÚHOSTÚclose©r ÚsrrrÚ test_HOST]szTestSupport.test_HOSTcCs$t ¡}t tj|f¡}| ¡dSr)rZfind_unused_portr>r?r@rA)r ÚportrCrrrÚtest_find_unused_portasz!TestSupport.test_find_unused_portcCs&t ¡}t |¡| ¡| ¡dSr)r>rZ bind_portÚlistenrArBrrrÚtest_bind_portfs zTestSupport.test_bind_portc Cs®t ¡}tj |¡}zˆtj |d¡}| tj |¡¡t  |¡.}|  ||¡|  tj |¡¡Wdƒn1st0Y| tj |¡¡Wt  |¡n t  |¡0dS)z8Test that temp_dir() creates and destroys its directory.ZtempN) ÚtempfileÚmkdtempr"r#Úrealpathr)r!ÚisdirrÚtemp_dirrÚ assertTruer+)r Ú parent_dirr#Ú temp_pathrrrÚ test_temp_dirns   0zTestSupport.test_temp_dircCsPt ¡"}| tj |¡¡Wdƒn1s00Y| tj |¡¡dS)zTest passing no path.N)rrMrNr"r#rLr!)r rPrrrÚtest_temp_dir__path_none}s 0z$TestSupport.test_temp_dir__path_nonec Csndd„}t ¡}tj |¡}z@| tj |¡¡| t||¡| tj |¡¡Wt   |¡n t   |¡0dS)z-Test passing a directory that already exists.cSs6t |¡}tdƒ‚Wdƒn1s(0YdS©Nzshould not get here)rrMÚ Exception)r#rPrrrÚ call_temp_dir…s zMTestSupport.test_temp_dir__existing_dir__quiet_default..call_temp_dirN) rIrJr"r#rKrNrLr ÚFileExistsErrorÚshutilr+)r rUr#rrrÚ*test_temp_dir__existing_dir__quiet_defaultƒs z6TestSupport.test_temp_dir__existing_dir__quiet_defaultc Csìt ¡}tj |¡}z’t ¡Z}tj|dd}| ||¡Wdƒn1sP0Ydd„|j Dƒ}Wdƒn1s~0Y|  tj  |¡¡Wt   |¡n t   |¡0| t|ƒd|¡|d}|  | d|›d ¡|¡dS) z=Test passing a directory that already exists with quiet=True.T©ÚquietNcSsg|]}t|jƒ‘qSr©ÚstrÚmessage©Ú.0rrrrÚ œózGTestSupport.test_temp_dir__existing_dir__quiet_true..érz5tests may fail, unable to create temporary directory ú: )rIrJr"r#rKrÚcheck_warningsrMrÚwarningsrNrLrWr+ÚlenÚ startswith)r r#ÚrecorderrPreÚwarnrrrÚ'test_temp_dir__existing_dir__quiet_true“s   *. ÿþz3TestSupport.test_temp_dir__existing_dir__quiet_trueÚforkztest requires os.forkcCst dt d¡¡dS)z?Test that a forked child process does not remove the directory.ú-caÐ import os from test import support with support.temp_cwd() as temp_path: pid = os.fork() if pid != 0: # parent process # wait for the child to terminate support.wait_process(pid, exitcode=0) # Make sure that temp_path is still present. When the child # process leaves the 'temp_cwd'-context, the __exit__()- # method of the context must not remove the temporary # directory. if not os.path.isdir(temp_path): raise AssertionError("Child removed temp_path.") N)rZassert_python_okÚtextwrapÚdedentr rrrÚtest_temp_dir__forked_child¨sz'TestSupport.test_temp_dir__forked_childc CsŠt ¡}t ¡V}t |¡,}| ||¡| t ¡|¡Wdƒn1sN0YWdƒn1sl0Y| t ¡|¡dSr)r"ÚgetcwdrrMÚ change_cwdr)r Ú original_cwdrPÚnew_cwdrrrÚtest_change_cwdÂs    LzTestSupport.test_change_cwdcCsht ¡}dd„}t ¡,}tj |d¡}| t||¡Wdƒn1sJ0Y| t ¡|¡dS)z&Test passing a non-existent directory.cSs6t |¡}tdƒ‚Wdƒn1s(0YdSrS)rrqrT)r#rsrrrÚcall_change_cwdÐs zFTestSupport.test_change_cwd__non_existent_dir..call_change_cwdÚdoes_not_existN) r"rprrMr#r)r ÚFileNotFoundErrorr)r rrrurOZnon_existent_dirrrrÚ!test_change_cwd__non_existent_dirÌs ÿ"z-TestSupport.test_change_cwd__non_existent_dirc Csøt ¡}t ¡ }tj |d¡}t ¡j}tj|dd,}| ||¡| t ¡|¡Wdƒn1sj0Ydd„|j Dƒ}Wdƒn1s˜0YWdƒn1s¶0Y| t |ƒd|¡|d}|  |  d |›d ¡|¡dS) z6Test passing a non-existent directory with quiet=True.rvTrYNcSsg|]}t|jƒ‘qSrr[r^rrrr`årazMTestSupport.test_change_cwd__non_existent_dir__quiet_true..rbrúBtests may fail, unable to change the current working directory to rc) r"rprrMr#r)rdrqrrerfrNrg)r rrrOZbad_dirrhrsrerirrrÚ-test_change_cwd__non_existent_dir__quiet_trueÛs   .L þýz9TestSupport.test_change_cwd__non_existent_dir__quiet_truec Cs¦td}t ¡N}tj|ddWdƒn1s60Ydd„|jDƒ}Wdƒn1sd0Y| t|ƒd|¡|d}| | d |›d ¡|¡dS) z0Check the warning message when os.chdir() fails.Z_does_not_existT)r#rZNcSsg|]}t|jƒ‘qSrr[r^rrrr`öraz>TestSupport.test_change_cwd__chdir_warning..rbrryrc) rrrdrqrerrfrNrg)r r#rhÚmessagesÚmsgrrrÚtest_change_cwd__chdir_warningðs . þýz*TestSupport.test_change_cwd__chdir_warningcCsrt ¡}tjtd(| tj t ¡¡t¡Wdƒn1sB0Y| tj  t¡¡| t ¡|¡dS)N©Úname) r"rprÚtemp_cwdrrr#Úbasenamer!r$)r ÚhererrrÚ test_temp_cwds 6zTestSupport.test_temp_cwdcCsvt ¡}tjdd>}| ||¡| tj |¡¡| t ¡|¡Wdƒn1sX0Y| t ¡|¡dS)z Test passing None to temp_cwd().Nr~) r"rprr€ZassertNotEqualrNr#rLr)r rrrsrrrÚtest_temp_cwd__name_none s  .z$TestSupport.test_temp_cwd__name_nonecCs| t ddddœ¡d¡dS)Néérb)r…r†rbz{1: 1, 2: 2, 3: 3})rrZsortdictr rrrÚ test_sortdictszTestSupport.test_sortdictcCsTt ¡}| t¡}t |d¡Wdƒn1s40Y| |jjtj ¡dS)Nsfoo) rZ make_bad_fdr ÚOSErrorr"ÚwriterÚ exceptionÚerrnoÚEBADF)r ÚfdÚcmrrrÚtest_make_bad_fds *zTestSupport.test_make_bad_fdcCsLtj|dddd| t¡t |d¡Wdƒn1s>0YdS)Nz def classrbé)ÚlinenoÚoffsetzx=1)rZcheck_syntax_errorr ÚAssertionErrorr rrrÚtest_check_syntax_errors z#TestSupport.test_check_syntax_errorcCs@ddl}t d¡| d¡Wdƒn1s20YdS)NrZasyncore)r9rZ CleanImportr)r r9rrrÚtest_CleanImport s zTestSupport.test_CleanImportcCsht dd¡,| dtj¡| dtj¡Wdƒn1s>0Y| dtj¡| dtj¡dS)NrZbar)rZ DirsOnSysPathrrr#rr rrrÚtest_DirsOnSysPath%s ,zTestSupport.test_DirsOnSysPathcCsDt ¡}tdƒWdƒn1s&0Y| | ¡d¡dS)NÚhelloúhello )rZcaptured_stdoutr6rÚgetvalue)r rrrrÚtest_captured_stdout,s &z TestSupport.test_captured_stdoutcCsJt ¡}tdtjdWdƒn1s,0Y| | ¡d¡dS)Nr—r3r˜)rZcaptured_stderrr6rÚstderrrr™)r r›rrrÚtest_captured_stderr1s ,z TestSupport.test_captured_stderrcCsRt ¡*}| d¡| d¡tƒ}Wdƒn1s80Y| |d¡dS)Nr˜rr—)rZcaptured_stdinr‰ÚseekÚinputr)r ÚstdinZcapturedrrrÚtest_captured_stdin6s    $zTestSupport.test_captured_stdincCs t ¡dSr)rÚ gc_collectr rrrÚtest_gc_collect>szTestSupport.test_gc_collectcCs| t ¡t¡dSr)ZassertIsInstancerZpython_is_optimizedÚboolr rrrÚtest_python_is_optimizedAsz$TestSupport.test_python_is_optimizedcCs Gdd„dƒ}|ƒ}d|_t |dd¡*}| |jd¡| |d¡Wdƒn1sX0Y| |jd¡t |dd¡(}| |jd¡| |¡Wdƒn1s¬0Y| t|dƒ¡t |dd¡|`Wdƒn1sî0Y| t|dƒ¡dS)Nc@s eZdZdS)z'TestSupport.test_swap_attr..ObjN)Ú__name__Ú __module__Ú __qualname__rrrrÚObjEsr¨rbÚxrÚy)r©rr,rrªÚ assertIsNoner!Úhasattr)r r¨Úobjr©rªrrrÚtest_swap_attrDs*("zTestSupport.test_swap_attrcCsúddi}t |dd¡,}| |dd¡| |d¡Wdƒn1sH0Y| |dd¡t |dd¡*}| |dd¡| |¡Wdƒn1s 0Y| d|¡t |dd¡|d=Wdƒn1sà0Y| d|¡dS)Nr©rbrrª)rZ swap_itemrr«r)r ÚDr©rªrrrÚtest_swap_itemUs*( $zTestSupport.test_swap_itemc@seZdZdZdZdZdZdS)zTestSupport.RefClassN)r¥r¦r§Ú attribute1Ú attribute2Z_hidden_attribute1Ú __magic_1__rrrrÚRefClasscsr´c@seZdZdZdZdZdZdS)zTestSupport.OtherClassN)r¥r¦r§r²Ú attribute3r³Ú __magic_2__rrrrÚ OtherClassisr·cCsBt |j|j¡}| dh|¡t |j|j¡}| ddh|¡dS)Nr±rµr¶)rÚdetect_api_mismatchr´r·r)r Ú missing_itemsrrrÚtest_detect_api_mismatchosÿÿz$TestSupport.test_detect_api_mismatchcCsPgd¢}tj|j|j|d}| tƒ|¡tj|j|j|d}| tƒ|¡dS)N)r±rµr¶Z not_in_either)Úignore)rr¸r´r·rÚset)r r»r¹rrrÚ test_detect_api_mismatch__ignorexs ÿ ÿz,TestSupport.test_detect_api_mismatch__ignorecCsXdh}dh}tj|t||dddh}hd£}tj|td||d| ttj|t¡dS)NÚtempdirÚtemplate)ÚextraÚ blacklistZTextTestResultZinstallHandler>Z TestProgramZ load_testsZ BaseTestSuite)zunittest.resultz unittest.casezunittest.suitezunittest.loaderz unittest.mainzunittest.runnerzunittest.signalszunittest.async_case)rZ check__all__rIr r r“)r rÀrÁrrrÚtest_check__all__ƒs ýù zTestSupport.test_check__all__ÚwaitpidÚWNOHANGz need os.waitpid() and os.WNOHANGcCsât ¡t ¡}|dkr"t d¡t ¡}t ¡tj}tj}zŽdt_t   ¡}t ¡|krd|  d¡t j }z|t _ t ¡W|t _ n|t _ 0tjr”q t d¡qNd|}| || ¡¡| tj¡W|t_n|t_0t ¡dS)NrFÚtimeoutgš™™™™™¹?z2Warning -- reap_children() reaped child process %s)rÚ reap_childrenr"rkÚ_exitÚtimeÚ monotonicZ SHORT_TIMEOUTZenvironment_alteredÚioÚStringIOZfailrÚ __stderr__Úsleeprr™rN)r ÚpidÚt0ÚdeadlineZ was_alteredr›Ú old_stderrr|rrrÚtest_reap_children™s2     zTestSupport.test_reap_childrenNcCs†d|›d|›d}tjg|¢d‘|‘}dd„tj ¡Dƒ}tj|tjtjd|d}|dur^|}|  |j   ¡t |ƒ¡|  |j d ¡dS) Nzfrom test.support import z ; print(repr(z()))rlcSs i|]\}}| d¡s||“qS)ZPYTHON)rg)r_ÚkeyÚvaluerrrÚ Ís  ÿz-TestSupport.check_options..T)rr›Úuniversal_newlinesÚenvr)rÚ executabler"ÚenvironÚitemsÚ subprocessÚrunÚPIPEÚDEVNULLrrÚrstripÚreprÚ returncode)r ÚargsÚfuncÚexpectedÚcodeÚcmdr×ÚprocrrrÚ check_optionsÊsüzTestSupport.check_optionscCs²gdgdgdgdgdgdgdgdgd gd gd gd d ggd¢d dgd dgd dgd dgd dgfD]<}|j|d| |d¡Wdƒq\1sŽ0Yq\| gd¢ddg¡dS)Nz-Bú-sz-Sú-Ez-vz-bz-qú-Iz-bbz-vvvú-Wignoreú-XÚdev)rìrírîÚ faulthandlerÚ importtimeÚ showrefcountÚ tracemallocz tracemalloc=3©ÚoptsZargs_from_interpreter_flags)rërêré©ZsubTestrè©r rôrrrÚ test_args_from_interpreter_flagsÙs2è, ÿz,TestSupport.test_args_from_interpreter_flagsc CsTgdgdgdgfD]<}|j|d| |d¡Wdƒq1sD0YqdS)Nz-Oz-OOz-OOOOróZ!optim_args_from_interpreter_flagsrõrörrrÚ&test_optim_args_from_interpreter_flagsûsûz2TestSupport.test_optim_args_from_interpreter_flagscCsôGdd„dƒ}|dƒ}|dƒ}t tdd¡Æt g¡| t |¡¡| t |¡¡t dd¡| t |¡¡| t |¡¡t | ¡gd¡| t |¡¡| t |¡¡t dgd¡| t |¡¡| t |¡¡t dgd¡| t |¡¡| t |¡¡t dgd¡| t |¡¡t d gd¡| t |¡¡t d gd¡| t |¡¡| t |¡¡t | ¡| ¡gd¡| t |¡¡| t |¡¡t d d gd¡| t |¡¡| t |¡¡Wdƒn1sü0Yt tdd¡Ètjgd | t |¡¡| t |¡¡t dd¡| t |¡¡| t |¡¡t d| ¡g¡| t |¡¡| t |¡¡t ddg¡| t |¡¡| t |¡¡t ddg¡| t |¡¡| t |¡¡t ddg¡| t |¡¡t dd g¡| t |¡¡t dd g¡| t |¡¡| t |¡¡t d| ¡| ¡g¡| t |¡¡| t |¡¡t dd d g¡| t |¡¡| t |¡¡Wdƒn1sæ0YdS)Nc@seZdZdd„Zdd„ZdS)z)TestSupport.test_match_test..TestcSs ||_dSr©Útest_id)r rúrrrÚ__init__ sz2TestSupport.test_match_test..Test.__init__cSs|jSrrùr rrrÚid sz,TestSupport.test_match_test..Test.idN)r¥r¦r§rûrürrrrÚTestsrýz"test.test_os.FileTests.test_accessz'test.test_os.Win32ErrorTests.test_chdirZ_match_test_funcZtest_osztest_*Z filetestsZ FileTestsz*test_os.*.test_*Ú test_accessZ DONTMATCH)Úignore_patterns)rr,Zset_match_testsrNZ match_testrür!)r rýrþZ test_chdirrrrÚtest_match_testsz  0  zTestSupport.test_match_testc CsNt ¡}t ttj¡}zt ¡}Wt |¡n t |¡0| ||d¡dS)Nrb)rZfd_countr"rÚ__file__ÚO_RDONLYrAr)r ÚstartrZmorerrrÚ test_fd_countps  zTestSupport.test_fd_countcCsFt ¡}tj}z|t_t |¡W|t_n|t_0| | ¡|¡dSr)rÊrËrrÌrZ print_warningrr™)r r|rär›rÑrrrÚcheck_print_warning|s zTestSupport.check_print_warningcCs| dd¡| dd¡dS)Nr|zWarning -- msg za bzWarning -- a Warning -- b )rr rrrÚtest_print_warningˆs ÿÿzTestSupport.test_print_warning)N)7r¥r¦r§rrrr Úskiprrr&r2r=rDrFrHrQrRrXrjZ skipUnlessr¬r"rortrxrzr}rƒr„r‡rr”r•r–ršrœr r¢r¤r®r°r´r·rºr½rÂrÒrèr÷rørrrrrrrrrsh      ÿ / " i  rcCstg}tj|ŽdSr)rrZ run_unittest)ZtestsrrrÚ test_main§srÚ__main__)r‹r9rÊr"rWr>r.rÛrrIrmrÈr ÚtestrZ test.supportrrrZTestCaserrr¥rrrrÚs2