o }5hVe@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZddlmZddlmZejZGdd d e jZed krre dSdS) N)support) import_helper) os_helper) script_helper) socket_helper)warnings_helperc@seZdZeddZeddZddZddZd d Zd d Z e d ddZ ddZ ddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Ze eed&d'd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Z d4d5Z!d6d7Z"d8d9Z#d:d;Z$dd?Z&d@dAZ'dBdCZ(dDdEZ)dFdGZ*dHdIZ+dJdKZ,dLdMZ-GdNdOdOZ.GdPdQdQZ/dRdSZ0dTdUZ1dVdWZ2e eedXoeedYdZd[d\Z3dld^d_Z4d`daZ5dbdcZ6dddeZ7dfdgZ8dhdiZ9djdkZ:d]S)m TestSupportcCsDttj}tjddd|_tjddd|_ttj|dks JdS)Nztest.support.warnings_helperz.*used in test_support.*)likeztest.test_supportz!.*You should NOT be seeing this.*)lenwarningsfiltersrignore_deprecations_from_warnings_helper_token_test_support_tokenclsorig_filter_lenr(/usr/lib/python3.10/test/test_support.py setUpClasss zTestSupport.setUpClasscCs4ttj}t|j|jttj|dksJdS)Nr )r r r rclear_ignored_deprecationsrrrrrr tearDownClass&s zTestSupport.tearDownClasscCsdtjdd}ttdtdd|D}Wdn1s"wY|t|d|dS)z9Test support.ignore_deprecations_from() silences warningsT)recordzYou should NOT be seeing this.cSg|]}t|jqSrstrmessage.0wrrr 4zDTestSupport.test_ignored_deprecations_are_silent..Nr)r catch_warningsr_warn_about_deprecationwarnDeprecationWarning assertEqualr )self warning_objsmessagesrrr$test_ignored_deprecations_are_silent/s  z0TestSupport.test_ignored_deprecations_are_silentcCs td|tjtjddS)Nftplibfoo)r import_module assertRaisesunittestSkipTestr(rrrtest_import_module7s zTestSupport.test_import_modulecCstddS)Nr,)rimport_fresh_moduler2rrrtest_import_fresh_module<sz$TestSupport.test_import_fresh_modulecCs.|t|d|j|tjtj|ddS)Ntest_get_attributer-)r'r get_attributer6r/r0r1r2rrrr6?szTestSupport.test_get_attributezfailing buildbotscCs|ttjdSN)r'rget_original_stdoutsysstdoutr2rrrtest_get_original_stdoutDsz$TestSupport.test_get_original_stdoutcCs2ddl}|dtjtd|dtjdS)Nrsched)r=assertInr:modulesrunload assertNotIn)r(r=rrr test_unloadHs zTestSupport.test_unloadcCsXttddd}Wdn1swYtt|tjtttdS)Nr utf-8encoding)openTESTFNrunlink assertFalseospathexists)r(frrr test_unlinkNs  zTestSupport.test_unlinkcCs`tjd}tj|d}t|t|t||tj|t t dd t|Wdn1s;wYt|t|t |t j t jBt t dd t|Wdn1skwY|tj|t|t|t |dt t dd t|Wdn1swY|tj|dS)Ndsubdirverboser)rrGrJrKjoinmkdirrmtreerIrLr swap_attrchmodstatS_IRUSRS_IXUSR)r(dirpath subdirpathrrr test_rmtreeUs.            zTestSupport.test_rmtreec Cstd}t|ddd}td|dWdn1swYtjdtjt z(t t}| ttj t t|ttj Wtjd=t|tddStjd=t|tdw) Nz.pyr rCrDzfoo = 1filer __pycache__)rGrFprintr:rKinsertrJcurdir importlibinvalidate_caches __import__r>r?rforgetrArrHrT)r( mod_filenamerMmodrrr test_forgetms"    zTestSupport.test_forgetcCsttjdf}|dS)Nr)socket create_serverrHOSTcloser(srrr test_HOST~s zTestSupport.test_HOSTcCs$t}ttj|f}|dSr8)rfind_unused_portrjrkrlrm)r(portrorrrtest_find_unused_ports z!TestSupport.test_find_unused_portcCs&t}t|||dSr8)rjr bind_portlistenrmrnrrrtest_bind_ports  zTestSupport.test_bind_portc Cst}tj|}zEtj|d}|tj|t |}| ||| tj|Wdn1s:wY|tj|Wt |dSt |w)z8Test that temp_dir() creates and destroys its directory.tempN) tempfilemkdtemprJrKrealpathrRrIisdirrtemp_dirr' assertTruerT)r( parent_dirrK temp_pathrrr test_temp_dirs   zTestSupport.test_temp_dircCsPt}|tj|Wdn1swY|tj|dS)zTest passing no path.N)rr|r}rJrKr{rI)r(rrrrtest_temp_dir__path_nones z$TestSupport.test_temp_dir__path_nonec Csldd}t}tj|}z!|tj||t|||tj|Wt |dSt |w)z-Test passing a directory that already exists.cS(t|}td1s wYdSNzshould not get here)rr| Exception)rKrrrr call_temp_dir zMTestSupport.test_temp_dir__existing_dir__quiet_default..call_temp_dirN) rxryrJrKrzr}r{r/FileExistsErrorshutilrT)r(rrKrrr*test_temp_dir__existing_dir__quiet_defaults z6TestSupport.test_temp_dir__existing_dir__quiet_defaultc Cst}tj|}zIt-}tj|dd}| ||Wdn1s(wYdd|j D}Wdn1s?wY| tj |Wt |nt |w| t|d||d}| |d|d |dS) z=Test passing a directory that already exists with quiet=True.TquietNcSrrrrrrrr!r"zGTestSupport.test_temp_dir__existing_dir__quiet_true..rz5tests may fail, unable to create temporary directory : )rxryrJrKrzrcheck_warningsrr|r'r r}r{rrTr startswith)r(rKrecorderrr r%rrr'test_temp_dir__existing_dir__quiet_trues$   z3TestSupport.test_temp_dir__existing_dir__quiet_trueforkztest requires os.forkcCstdtddS)z?Test that a forked child process does not remove the directory.-ca import os from test import support from test.support import os_helper with os_helper.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)rassert_python_oktextwrapdedentr2rrrtest_temp_dir__forked_childsz'TestSupport.test_temp_dir__forked_childc Cst}t+}t|}||||t|Wdn1s'wYWdn1s6wY|t|dSr8)rJgetcwdrr| change_cwdr')r( original_cwdrnew_cwdrrrtest_change_cwds   zTestSupport.test_change_cwdcCsht}dd}t}tj|d}|t||Wdn1s%wY|t|dS)z&Test passing a non-existent directory.cSrr)rrr)rKrrrrcall_change_cwdrzFTestSupport.test_change_cwd__non_existent_dir..call_change_cwddoes_not_existN) rJrrr|rKrRr/FileNotFoundErrorr')r(rrr~non_existent_dirrrr!test_change_cwd__non_existent_dirs z-TestSupport.test_change_cwd__non_existent_dirc Cst}tP}tj|d}t5}tj|dd}| ||| t|Wdn1s5wYdd|j D}Wdn1sLwYWdn1s[wY| t |d||d}| | d |d |dS) z6Test passing a non-existent directory with quiet=True.rTrNcSrrrrrrrr!r"zMTestSupport.test_change_cwd__non_existent_dir__quiet_true..rrBtests may fail, unable to change the current working directory to r)rJrrr|rKrRrrrr'r r r}r)r(rr~bad_dirrrr r%rrr-test_change_cwd__non_existent_dir__quiet_trues&    z9TestSupport.test_change_cwd__non_existent_dir__quiet_truec Cstd}t'}tj|ddWdn1swYdd|jD}Wdn1s2wY|t|d||d}|| d |d |dS) z0Check the warning message when os.chdir() fails._does_not_existT)rKrNcSrrrrrrrr!r"z>TestSupport.test_change_cwd__chdir_warning..rrrr) rGrrrrr r'r r}r)r(rKrr*msgrrrtest_change_cwd__chdir_warnings  z*TestSupport.test_change_cwd__chdir_warningcCsrt}tjtd|tjttWdn1s!wY|tj t|t|dS)Nname) rJrrtemp_cwdrGr'rKbasenamerIrL)r(hererrr test_temp_cwd#s zTestSupport.test_temp_cwdcCsvt}tjdd}||||tj||t|Wdn1s,wY|t|dS)z Test passing None to temp_cwd().Nr) rJrrrassertNotEqualr}rKr{r')r(rrrrrtest_temp_cwd__name_none+s z$TestSupport.test_temp_cwd__name_nonecCs|tddddddS)Nr r)rr rz{1: 1, 2: 2, 3: 3})r'rsortdictr2rrr test_sortdict4szTestSupport.test_sortdictcCsTt}|t}t|dWdn1swY||jjtj dS)Nsfoo) r make_bad_fdr/OSErrorrJwriter' exceptionerrnoEBADF)r(fdcmrrrtest_make_bad_fd7s  zTestSupport.test_make_bad_fdcCsNtj|dddd|tt|dWddS1s wYdS)Nz def classr)linenooffsetzx=1)rcheck_syntax_errorr/AssertionErrorr2rrrtest_check_syntax_error=s "z#TestSupport.test_check_syntax_errorcCsBddl}td|dWddS1swYdS)Nrpprint)rcr CleanImportr.)r(rcrrrtest_CleanImportBs  "zTestSupport.test_CleanImportcCshtdd|dtj|dtjWdn1swY|dtj|dtjdS)Nr-bar)r DirsOnSysPathr>r:rKrAr2rrrtest_DirsOnSysPathGs zTestSupport.test_DirsOnSysPathcCsDt }tdWdn1swY||ddS)Nhellohello )rcaptured_stdoutr`r'getvalue)r(r;rrrtest_captured_stdoutNs  z TestSupport.test_captured_stdoutcCsJt}tdtjdWdn1swY||ddS)Nrr]r)rcaptured_stderrr`r:stderrr'r)r(rrrrtest_captured_stderrSs z TestSupport.test_captured_stderrcCsRt}|d|dt}Wdn1swY||ddS)Nrrr)rcaptured_stdinrseekinputr')r(stdincapturedrrrtest_captured_stdinXs   zTestSupport.test_captured_stdincCs tdSr8)r gc_collectr2rrrtest_gc_collect`s zTestSupport.test_gc_collectcCs|ttdSr8)assertIsInstancerpython_is_optimizedboolr2rrrtest_python_is_optimizedcsz$TestSupport.test_python_is_optimizedcCs Gddd}|}d|_t|dd}||jd||dWdn1s,wY||jdt|dd}||jd||Wdn1sVwY|t|dt|dd |`Wdn1swwY|t|ddS)Nc@s eZdZdS)z'TestSupport.test_swap_attr..ObjN)__name__ __module__ __qualname__rrrrObjgsrrxry)rrrUr'r assertIsNonerIhasattr)r(robjrrrrrtest_swap_attrfs" zTestSupport.test_swap_attrcCsddi}t|dd}||dd||dWdn1s$wY||ddt|dd}||dd||Wdn1sPwY|d|t|dd |d=Wdn1spwY|d|dS)Nrrrr)r swap_itemr'rrA)r(Drrrrrtest_swap_itemws  zTestSupport.test_swap_itemc@eZdZdZdZdZdZdS)zTestSupport.RefClassN)rrr attribute1 attribute2_hidden_attribute1 __magic_1__rrrrRefClass rc@r)zTestSupport.OtherClassN)rrrr attribute3r __magic_2__rrrr OtherClassrrcCsBt|j|j}|dh|t|j|j}|ddh|dS)Nrrr)rdetect_api_mismatchrrr')r( missing_itemsrrrtest_detect_api_mismatchsz$TestSupport.test_detect_api_mismatchcCsPgd}tj|j|j|d}|t|tj|j|j|d}|t|dS)N)rrr not_in_either)ignore)rrrrr'set)r(rrrrr test_detect_api_mismatch__ignores  z,TestSupport.test_detect_api_mismatch__ignorecCsXdh}dh}tj|t||dddh}hd}tj|td||d|ttj|tdS)Ntempdirtemplate)extra not_exportedTextTestResultinstallHandler> load_tests TestProgram BaseTestSuite)zunittest.resultz unittest.casezunittest.suitezunittest.loaderz unittest.mainzunittest.runnerzunittest.signalszunittest.async_case)r check__all__rxr0r/r)r(rrrrrtest_check__all__s  zTestSupport.test_check__all__waitpidWNOHANGz need os.waitpid() and os.WNOHANGcCstt}|dkrtdt}ttj}tj}zHdt_t } t|kr3| dt j }z |t _ tW|t _ n|t _ wtjrKntdq(d|}||||tjW|t_n|t_wtdS)NrFTtimeoutg?z2Warning -- reap_children() reaped child process %s)r reap_childrenrJr_exittime monotonic SHORT_TIMEOUTenvironment_alteredioStringIOfailr: __stderr__sleepr>rr})r(pidt0deadline was_alteredr old_stderrrrrrtest_reap_childrens6      zTestSupport.test_reap_childrenNcCsd|d|d}tjg|d|}ddtjD}tj|tjtjd|d}|dur/|}| |j t || |j d dS) Nzfrom test.support import z ; print(repr(z()))rcSs i|] \}}|ds||qS)PYTHON)r)rkeyvaluerrr s  z-TestSupport.check_options..T)r;runiversal_newlinesenvr)r: executablerJenvironitems subprocessrunPIPEDEVNULLr'r;rstriprepr returncode)r(argsfuncexpectedcodecmdrprocrrr check_optionsszTestSupport.check_optionscCsgdgdgdgdgdgdgdgdgd gd gd gd d ggdd dgd dgd dgd dgd dgfD]}|j|d||dWdn1sGwYq.|gdddgdS)Nz-B-sz-S-Ez-vz-bz-q-Iz-bbz-vvv-Wignore-Xdev)r3r4r5 faulthandler importtime showrefcount tracemallocz tracemalloc=3optsargs_from_interpreter_flags)r2r1r0subTestr/r(r;rrr test_args_from_interpreter_flagss6 z,TestSupport.test_args_from_interpreter_flagsc CsTgdgdgdgfD]}|j|d||dWdn1s"wYq dS)Nz-Oz-OOz-OOOOr:!optim_args_from_interpreter_flagsr=r?rrr&test_optim_args_from_interpreter_flagssz2TestSupport.test_optim_args_from_interpreter_flagscCsGddd}|d}|d}ttddtg|t||t|tdd|t||t|t|gd|t||t|tdgd|t||t|tdgd|t||t|tdgd|t|td gd|t|td gd|t||t|t||gd|t||t|td d gd|t||t|Wdn1swYttddtjgd |t||t|tdd|t||t|td|g|t||t|tddg|t||t|tddg|t||t|tddg|t|tdd g|t|tdd g|t||t|td||g|t||t|tdd d g|t||t|WddS1swYdS)Nc@seZdZddZddZdS)z)TestSupport.test_match_test..TestcSs ||_dSr8test_id)r(rDrrr__init__+s z2TestSupport.test_match_test..Test.__init__cSs|jSr8rCr2rrrid.sz,TestSupport.test_match_test..Test.idN)rrrrErFrrrrTest*s rGz"test.test_os.FileTests.test_accessz'test.test_os.Win32ErrorTests.test_chdir_match_test_functest_osztest_* filetests FileTestsz*test_os.*.test_* test_access DONTMATCH)ignore_patterns)rrUset_match_testsr} match_testrFrI)r(rGrL test_chdirrrrtest_match_test)s~  /  $zTestSupport.test_match_testc CsNt}tttj}z t}Wt|nt|w|||ddS)Nr)rfd_countrJrF__file__O_RDONLYrmr')r(startrmorerrr test_fd_counts  zTestSupport.test_fd_countcCsFt}tj}z |t_t|W|t_n|t_w|||dSr8)rrr:rr print_warningr'r)r(rr+rrrrrcheck_print_warnings zTestSupport.check_print_warningcCs|dd|dddS)NrzWarning -- msg za bzWarning -- a Warning -- b )rZr2rrrtest_print_warnings zTestSupport.test_print_warningr8);rrr classmethodrrr+r3r5r6r0skipr<rBrNr\rirprsrvrrrr skipUnlessrrJrrrrrrrrrrrrrrrrrrrrrrrrrr/r@rBrRrXrZr[rrrrrst          /" i r__main__)rrcrrJrrjrWr"r:rxrr r0r testr test.supportrrrrrrGTestCaserrmainrrrrs<      3