a ze3e@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZejZGddde jZddZed kre dS) N)support) script_helper) socket_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.test_supportz.*used in test_support.*)Zlikez!.*You should NOT be seeing this.*)lenwarningsfiltersrZignore_deprecations_from_warnings_helper_token_test_support_tokenclsZorig_filter_lenrE/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_support.py setUpClasss zTestSupport.setUpClasscCs4ttj}t|j|jttj|dks0JdS)Nr)rrr rZclear_ignored_deprecationsr r r rrr tearDownClass#s  zTestSupport.tearDownClasscCsbtjdd0}ttdtdd|D}Wdn1sB0Y|t|d|dS)z9Test support.ignore_deprecations_from() silences warningsT)recordzYou should NOT be seeing this.cSsg|]}t|jqSrstrmessage.0wrrr 1zDTestSupport.test_ignored_deprecations_are_silent..Nr)rcatch_warnings_warn_about_deprecationwarnDeprecationWarning assertEqualr)selfZ warning_objsmessagesrrr$test_ignored_deprecations_are_silent,s  ,z0TestSupport.test_ignored_deprecations_are_silentcCs td|tjtjddS)Nftplibfoo)r import_module assertRaisesunittestSkipTestr rrrtest_import_module4s zTestSupport.test_import_modulecCstddS)Nr#)rZimport_fresh_moduler)rrrtest_import_fresh_module8sz$TestSupport.test_import_fresh_modulecCs.|t|d|j|tjtj|ddS)Ntest_get_attributer$)rrZ get_attributer,r&r'r(r)rrrr,;szTestSupport.test_get_attributezfailing buildbotscCs|ttjdSN)rrZget_original_stdoutsysstdoutr)rrrtest_get_original_stdout@sz$TestSupport.test_get_original_stdoutcCs2ddl}|dtjtd|dtjdS)Nrsched)r1assertInr.modulesrZunload assertNotIn)r r1rrr test_unloadDs zTestSupport.test_unloadcCsTttd}Wdn1s 0Ytt|tjtttdS)Nr)openTESTFNrunlink assertFalseospathexists)r frrr test_unlinkJs   zTestSupport.test_unlinkcCsbtjd}tj|d}t|t|t||tj|t tddt|Wdn1sv0Yt|t|t |t j t j Bt tddt|Wdn1s0Y|tj|t|t|t |dt tddt|Wdn1sB0Y|tj|dS)NdZsubdirverboser)rr7r:r;joinmkdirrmtreer9r< swap_attrchmodstatS_IRUSRS_IXUSR)r dirpathZ subdirpathrrr test_rmtreeQs(    (  (   *zTestSupport.test_rmtreec Cstd}t|d}td|dWdn1s40Ytjdtjt zNt t}| ttj t t|ttj Wtjd=t |t dntjd=t |t d0dS)Nz.pyrzfoo = 1filer __pycache__)r7r6printr.r;insertr:curdir importlibinvalidate_caches __import__r2r3rZforgetr4r8rC)r Z mod_filenamer=modrrr test_forgetis  *    zTestSupport.test_forgetcCsttjdf}|dS)Nr)socket create_serverrHOSTcloser srrr test_HOSTzszTestSupport.test_HOSTcCs$t}ttj|f}|dSr-)rZfind_unused_portrVrWrXrY)r portr[rrrtest_find_unused_port~sz!TestSupport.test_find_unused_portcCs&t}t|||dSr-)rVrZ bind_portlistenrYrZrrrtest_bind_ports zTestSupport.test_bind_portc Cst}tj|}ztj|d}|tj|t |.}| ||| tj|Wdn1st0Y|tj|Wt |n t |0dS)z8Test that temp_dir() creates and destroys its directory.ZtempN) tempfilemkdtempr:r;realpathrAr9isdirrtemp_dirr assertTruerC)r parent_dirr; temp_pathrrr test_temp_dirs   0zTestSupport.test_temp_dircCsPt"}|tj|Wdn1s00Y|tj|dS)zTest passing no path.N)rrerfr:r;rdr9)r rhrrrtest_temp_dir__path_nones 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|}tdWdn1s(0YdSNzshould not get here)rre Exception)r;rhrrr call_temp_dirs zMTestSupport.test_temp_dir__existing_dir__quiet_default..call_temp_dirN) rarbr:r;rcrfrdr&FileExistsErrorshutilrC)r rmr;rrr*test_temp_dir__existing_dir__quiet_defaults z6TestSupport.test_temp_dir__existing_dir__quiet_defaultc Cst}tj|}ztZ}tj|dd}|||Wdn1sP0Ydd|j D}Wdn1s~0Y| tj |Wt |n t |0|t|d||d}| |d|d |dS) z=Test passing a directory that already exists with quiet=True.TquietNcSsg|]}t|jqSrrrrrrrrzGTestSupport.test_temp_dir__existing_dir__quiet_true..rz5tests may fail, unable to create temporary directory : )rarbr:r;rcrcheck_warningsrerrrfrdrorCr startswith)r r;recorderrhrrrrr'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 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_oktextwrapdedentr)rrrtest_temp_dir__forked_childsz'TestSupport.test_temp_dir__forked_childc Cst}tV}t|,}||||t|Wdn1sN0YWdn1sl0Y|t|dSr-)r:getcwdrre change_cwdr)r original_cwdrhnew_cwdrrrtest_change_cwds    LzTestSupport.test_change_cwdcCsht}dd}t,}tj|d}|t||Wdn1sJ0Y|t|dS)z&Test passing a non-existent directory.cSs6t|}tdWdn1s(0YdSrk)rrrl)r;rrrrcall_change_cwds zFTestSupport.test_change_cwd__non_existent_dir..call_change_cwddoes_not_existN) r:r~rrer;rAr&FileNotFoundErrorr)r rrrgZnon_existent_dirrrr!test_change_cwd__non_existent_dirs "z-TestSupport.test_change_cwd__non_existent_dirc Cst}t}tj|d}tj}tj|dd,}||||t|Wdn1sj0Ydd|j D}Wdn1s0YWdn1s0Y|t |d||d}| | d |d |dS) z6Test passing a non-existent directory with quiet=True.rTrqNcSsg|]}t|jqSrrrrrrrrzMTestSupport.test_change_cwd__non_existent_dir__quiet_true..rsrBtests may fail, unable to change the current working directory to rt) r:r~rrer;rArurrrrrfrv)r rrgZbad_dirrwrrrrrr-test_change_cwd__non_existent_dir__quiet_trues   .L z9TestSupport.test_change_cwd__non_existent_dir__quiet_truec Cstd}tN}tj|ddWdn1s60Ydd|jD}Wdn1sd0Y|t|d||d}||d |d |dS) z0Check the warning message when os.chdir() fails.Z_does_not_existT)r;rrNcSsg|]}t|jqSrrrrrrrrz>TestSupport.test_change_cwd__chdir_warning..rsrrrt) r7rrurrrrrfrv)r r;rwr!msgrrrtest_change_cwd__chdir_warning s . z*TestSupport.test_change_cwd__chdir_warningcCsrt}tjtd(|tjttWdn1sB0Y|tj t|t|dS)Nname) r:r~rtemp_cwdr7rr;basenamer9r<)r hererrr test_temp_cwds 6zTestSupport.test_temp_cwdcCsvt}tjdd>}||||tj||t|Wdn1sX0Y|t|dS)z Test passing None to temp_cwd().Nr) r:r~rrZassertNotEqualrfr;rdr)r rrrrrtest_temp_cwd__name_none&s  .z$TestSupport.test_temp_cwd__name_nonecCs|tddddddS)Nrrs)rrrsz{1: 1, 2: 2, 3: 3})rrZsortdictr)rrr test_sortdict/szTestSupport.test_sortdictcCsTt}|t}t|dWdn1s40Y||jjtj dS)Nsfoo) rZ make_bad_fdr&OSErrorr:writer exceptionerrnoEBADF)r fdcmrrrtest_make_bad_fd2s *zTestSupport.test_make_bad_fdcCsLtj|dddd|tt|dWdn1s>0YdS)Nz def classrs)linenooffsetzx=1)rZcheck_syntax_errorr&AssertionErrorr)rrrtest_check_syntax_error8s z#TestSupport.test_check_syntax_errorcCs@ddl}td|dWdn1s20YdS)NrZasyncore)rQrZ CleanImportr%)r rQrrrtest_CleanImport=s zTestSupport.test_CleanImportcCshtdd,|dtj|dtjWdn1s>0Y|dtj|dtjdS)Nr$Zbar)rZ DirsOnSysPathr2r.r;r4r)rrrtest_DirsOnSysPathBs ,zTestSupport.test_DirsOnSysPathcCsDt}tdWdn1s&0Y||ddS)Nhellohello )rZcaptured_stdoutrNrgetvalue)r r/rrrtest_captured_stdoutIs &z TestSupport.test_captured_stdoutcCsJt}tdtjdWdn1s,0Y||ddS)NrrKr)rZcaptured_stderrrNr.stderrrr)r rrrrtest_captured_stderrNs ,z TestSupport.test_captured_stderrcCsRt*}|d|dt}Wdn1s80Y||ddS)Nrrr)rZcaptured_stdinrseekinputr)r stdinZcapturedrrrtest_captured_stdinSs    $zTestSupport.test_captured_stdincCs tdSr-)r gc_collectr)rrrtest_gc_collect[szTestSupport.test_gc_collectcCs|ttdSr-)ZassertIsInstancerZpython_is_optimizedboolr)rrrtest_python_is_optimized^sz$TestSupport.test_python_is_optimizedcCs Gddd}|}d|_t|dd*}||jd||dWdn1sX0Y||jdt|dd(}||jd||Wdn1s0Y|t|dt|dd|`Wdn1s0Y|t|ddS)Nc@s eZdZdS)z'TestSupport.test_swap_attr..ObjN)__name__ __module__ __qualname__rrrrObjbsrrsxry)rrrDrr assertIsNoner9hasattr)r robjrrrrrtest_swap_attras*("zTestSupport.test_swap_attrcCsddi}t|dd,}||dd||dWdn1sH0Y||ddt|dd*}||dd||Wdn1s0Y|d|t|dd|d=Wdn1s0Y|d|dS)Nrrsrr)rZ swap_itemrrr4)r Drrrrrtest_swap_itemrs*( $zTestSupport.test_swap_itemc@seZdZdZdZdZdZdS)zTestSupport.RefClassN)rrr attribute1 attribute2Z_hidden_attribute1 __magic_1__rrrrRefClasssrc@seZdZdZdZdZdZdS)zTestSupport.OtherClassN)rrrr attribute3r __magic_2__rrrr OtherClasssrcCsBt|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)rrrZ not_in_either)ignore)rrrrrset)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 blacklistZTextTestResultZinstallHandler>Z load_testsZ BaseTestSuiteZ TestProgram)zunittest.resultz unittest.casezunittest.suitezunittest.loaderz unittest.mainzunittest.runnerzunittest.signalszunittest.async_case)rZ check__all__rar'r&r)r rrrrrtest_check__all__s  zTestSupport.test_check__all__waitpidWNOHANGz need os.waitpid() and os.WNOHANGcCstt}|dkr"tdt}ttj}tj}zdt_t }t|krd| dt j }z|t _ tW|t _ n|t _ 0tjrqtdqNd|}||||tjW|t_n|t_0tdS)NrFtimeoutg?z2Warning -- reap_children() reaped child process %s)r reap_childrenr:ry_exittime monotonicZ SHORT_TIMEOUTZenvironment_alteredioStringIOZfailr. __stderr__sleepr2rrf)r pidt0deadlineZ was_alteredr old_stderrrrrrtest_reap_childrens2     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()))rzcSs i|]\}}|ds||qS)ZPYTHON)rv)rkeyvaluerrr s  z-TestSupport.check_options..T)r/runiversal_newlinesenvr)r. executabler:environitems subprocessrunPIPEDEVNULLrr/rstriprepr returncode)r argsfuncexpectedcodecmdrprocrrr check_optionsszTestSupport.check_optionscCsgdgdgdgdgdgdgdgdgd gd gd gd d ggdd dgd dgd dgd dgd dgfD]<}|j|d||dWdq\1s0Yq\|gdddgdS)Nz-B-sz-S-Ez-vz-bz-q-Iz-bbz-vvv-Wignore-Xdev)rrr faulthandler importtime showrefcount tracemallocz tracemalloc=3optsZargs_from_interpreter_flags)rrrZsubTestrr rrrr test_args_from_interpreter_flagss2, z,TestSupport.test_args_from_interpreter_flagsc CsTgdgdgdgfD]<}|j|d||dWdq1sD0YqdS)Nz-Oz-OOz-OOOOrZ!optim_args_from_interpreter_flagsrrrrr&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|Wdn1s0Yttddtjgd |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|Wdn1s0YdS)Nc@seZdZddZddZdS)z)TestSupport.test_match_test..TestcSs ||_dSr-test_id)r rrrr__init__&sz2TestSupport.test_match_test..Test.__init__cSs|jSr-rr)rrrid)sz,TestSupport.test_match_test..Test.idN)rrrrrrrrrTest%sr 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)rrDZset_match_testsrfZ match_testrr9)r r r Z test_chdirrrrtest_match_test$sz  0  zTestSupport.test_match_testc CsNt}tttj}zt}Wt|n t|0|||ddS)Nrs)rZfd_countr:r6__file__O_RDONLYrYr)r startrZmorerrr test_fd_counts  zTestSupport.test_fd_countcCsFt}tj}z|t_t|W|t_n|t_0|||dSr-)rrr.rrZ print_warningrr)r rrrrrrrcheck_print_warnings zTestSupport.check_print_warningcCs|dd|dddS)NrzWarning -- msg za bzWarning -- a Warning -- b )rr)rrrtest_print_warnings zTestSupport.test_print_warning)N);rrr classmethodrrr"r*r+r,r'skipr0r5r>rJrUr\r^r`rirjrprxZ skipUnlessrr:r}rrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrsr         / " i  rcCstjdtdddS)NzThis is used in test_support test to ensure support.ignore_deprecations_from() works as expected. You should not be seeing this.r) stacklevel)rrrrrrrrs r__main__)rrQrr:rorVrFrr.rar{rr'rtestrZ test.supportrrr7ZTestCaserrrmainrrrrs4   2