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 TestSupportcCs.ttj}tjddd|_tjddd|_dS)Nztest.test_supportz.*used in test_support.*)Zlikez!.*You should NOT be seeing this.*)lenwarningsfiltersrZignore_deprecations_from_warnings_helper_token_test_support_tokenclsZorig_filter_lenr E/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_support.py setUpClasss zTestSupport.setUpClasscCsttj}t|j|jdSN)rrrrZclear_ignored_deprecationsr r r r r r tearDownClass#s  zTestSupport.tearDownClasscCsbtjdd0}ttdtdd|D}Wdn1sB0Y|t|d|dS)NT)recordzYou should NOT be seeing this.cSsg|]}t|jqSr strmessage.0wr r r 1zDTestSupport.test_ignored_deprecations_are_silent..r)rcatch_warnings_warn_about_deprecationwarnDeprecationWarning assertEqualr)selfZ warning_objsmessagesr r r$test_ignored_deprecations_are_silent,s  ,z0TestSupport.test_ignored_deprecations_are_silentcCs td|tjtjddS)Nftplibfoo)r import_module assertRaisesunittestSkipTestr r r rtest_import_module4s zTestSupport.test_import_modulecCstddS)Nr#)rZimport_fresh_moduler)r r rtest_import_fresh_module8sz$TestSupport.test_import_fresh_modulecCs.|t|d|j|tjtj|ddS)Ntest_get_attributer$)rrZ get_attributer,r&r'r(r)r r rr,;szTestSupport.test_get_attributezfailing buildbotscCs|ttjdSr)rrZget_original_stdoutsysstdoutr)r r rtest_get_original_stdout@sz$TestSupport.test_get_original_stdoutcCs2ddl}|dtjtd|dtjdS)Nrsched)r0assertInr-modulesrZunload assertNotIn)r r0r r r test_unloadDs zTestSupport.test_unloadcCsTttd}Wdn1s 0Ytt|tjtttdS)Nr)openTESTFNrunlink assertFalseospathexists)r fr r r 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)rr6r9r:joinmkdirrmtreer8r; swap_attrchmodstatS_IRUSRS_IXUSR)r dirpathZ subdirpathr r r 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__)r6r5printr-r:insertr9curdir importlibinvalidate_caches __import__r1r2rZforgetr3r7rB)r Z mod_filenamer<modr r r test_forgetis  *    zTestSupport.test_forgetcCsttjdf}|dS)Nr)socket create_serverrHOSTcloser sr r r test_HOSTzszTestSupport.test_HOSTcCs$t}ttj|f}|dSr)rZfind_unused_portrUrVrWrX)r portrZr r rtest_find_unused_port~sz!TestSupport.test_find_unused_portcCs&t}t|||dSr)rUrZ bind_portlistenrXrYr r rtest_bind_ports zTestSupport.test_bind_portc Cst}tj|}ztj|d}|tj|t |.}| ||| tj|Wdn1st0Y|tj|Wt |n t |0dS)NZtemp) tempfilemkdtempr9r:realpathr@r8isdirrtemp_dirr assertTruerB)r parent_dirr: temp_pathr r r test_temp_dirs   0zTestSupport.test_temp_dircCsPt"}|tj|Wdn1s00Y|tj|dSr)rrdrer9r:rcr8)r rgr r rtest_temp_dir__path_nones 0z$TestSupport.test_temp_dir__path_nonec Csndd}t}tj|}z@|tj||t|||tj|Wt |n t |0dS)NcSs6t|}tdWdn1s(0YdSNzshould not get here)rrd Exception)r:rgr r r call_temp_dirs zMTestSupport.test_temp_dir__existing_dir__quiet_default..call_temp_dir) r`rar9r:rbrercr&FileExistsErrorshutilrB)r rlr:r r r*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) NTquietcSsg|]}t|jqSr rrr r rrrzGTestSupport.test_temp_dir__existing_dir__quiet_true..rz5tests may fail, unable to create temporary directory : )r`rar9r:rbrcheck_warningsrdrrrercrnrBr startswith)r r:recorderrgrrr r r'test_temp_dir__existing_dir__quiet_trues   *. z3TestSupport.test_temp_dir__existing_dir__quiet_trueforkztest requires os.forkcCstdtddS)N-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.") )rZassert_python_oktextwrapdedentr)r r rtest_temp_dir__forked_childsz'TestSupport.test_temp_dir__forked_childc Cst}tV}t|,}||||t|Wdn1sN0YWdn1sl0Y|t|dSr)r9getcwdrrd change_cwdr)r original_cwdrgnew_cwdr r rtest_change_cwds    LzTestSupport.test_change_cwdcCsht}dd}t,}tj|d}|t||Wdn1sJ0Y|t|dS)NcSs6t|}tdWdn1s(0YdSrj)rr~rk)r:rr r rcall_change_cwds zFTestSupport.test_change_cwd__non_existent_dir..call_change_cwddoes_not_exist) r9r}rrdr:r@r&FileNotFoundErrorr)r rrrfZnon_existent_dirr r r!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) NrTrpcSsg|]}t|jqSr rrr r rrrzMTestSupport.test_change_cwd__non_existent_dir__quiet_true..rrrBtests may fail, unable to change the current working directory to rs) r9r}rrdr:r@rtr~rrrreru)r rrfZbad_dirrvrrrr r r-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) NZ_does_not_existT)r:rqcSsg|]}t|jqSr rrr r rrrz>TestSupport.test_change_cwd__chdir_warning..rrrrrs) r6rrtr~rrrreru)r r:rvr!msgr r rtest_change_cwd__chdir_warning s . z*TestSupport.test_change_cwd__chdir_warningcCsrt}tjtd(|tjttWdn1sB0Y|tj t|t|dSN)name) r9r}rtemp_cwdr6rr:basenamer8r;)r herer r r test_temp_cwds 6zTestSupport.test_temp_cwdcCsvt}tjdd>}||||tj||t|Wdn1sX0Y|t|dSr) r9r}rrZassertNotEqualrer:rcr)r rrr r rtest_temp_cwd__name_none&s  .z$TestSupport.test_temp_cwd__name_nonecCs|tddddddS)Nrr)rrrrz{1: 1, 2: 2, 3: 3})rrZsortdictr)r r r test_sortdict/szTestSupport.test_sortdictcCsTt}|t}t|dWdn1s40Y||jjtj dS)Nsfoo) rZ make_bad_fdr&OSErrorr9writer exceptionerrnoEBADF)r fdcmr r rtest_make_bad_fd2s *zTestSupport.test_make_bad_fdcCsLtj|dddd|tt|dWdn1s>0YdS)Nz def classrr)linenooffsetzx=1)rZcheck_syntax_errorr&AssertionErrorr)r r rtest_check_syntax_error8s z#TestSupport.test_check_syntax_errorcCs@ddl}td|dWdn1s20YdS)NrZasyncore)rPrZ CleanImportr%)r rPr r rtest_CleanImport=s zTestSupport.test_CleanImportcCshtdd,|dtj|dtjWdn1s>0Y|dtj|dtjdS)Nr$Zbar)rZ DirsOnSysPathr1r-r:r3r)r r rtest_DirsOnSysPathBs ,zTestSupport.test_DirsOnSysPathcCsDt}tdWdn1s&0Y||ddS)Nhellohello )rZcaptured_stdoutrMrgetvalue)r r.r r rtest_captured_stdoutIs &z TestSupport.test_captured_stdoutcCsJt}tdtjdWdn1s,0Y||ddS)NrrJr)rZcaptured_stderrrMr-stderrrr)r rr r rtest_captured_stderrNs ,z TestSupport.test_captured_stderrcCsRt*}|d|dt}Wdn1s80Y||ddS)Nrrr)rZcaptured_stdinrseekinputr)r stdinZcapturedr r rtest_captured_stdinSs    $zTestSupport.test_captured_stdincCs tdSr)r gc_collectr)r r rtest_gc_collect[szTestSupport.test_gc_collectcCs|ttdSr)ZassertIsInstancerZpython_is_optimizedboolr)r r rtest_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__r r r rObjbsrrrxry)rrrCrr assertIsNoner8hasattr)r robjrrr r rtest_swap_attras*("zTestSupport.test_swap_attrcCsddi}t|dd,}||dd||dWdn1sH0Y||ddt|dd*}||dd||Wdn1s0Y|d|t|dd|d=Wdn1s0Y|d|dS)Nrrrrr)rZ swap_itemrrr3)r Drrr r rtest_swap_itemrs*( $zTestSupport.test_swap_itemc@seZdZdZdZdZdZdS)zTestSupport.RefClassN)rrr attribute1 attribute2Z_hidden_attribute1 __magic_1__r r r rRefClasssrc@seZdZdZdZdZdZdS)zTestSupport.OtherClassN)rrrr attribute3r __magic_2__r r r r OtherClasssrcCsBt|j|j}|dh|t|j|j}|ddh|dS)Nrrr)rdetect_api_mismatchrrr)r missing_itemsr r rtest_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 rrr r r 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 TestProgramZ BaseTestSuiteZ load_tests)zunittest.resultz unittest.casezunittest.suitezunittest.loaderz unittest.mainzunittest.runnerzunittest.signalszunittest.async_case)rZ check__all__r`r'r&r)r rrr r rtest_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_childrenr9rx_exittime monotonicZ SHORT_TIMEOUTZenvironment_alteredioStringIOZfailr- __stderr__sleepr1rre)r pidt0deadlineZ was_alteredr old_stderrrr r rtest_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()))rycSs i|]\}}|ds||qS)ZPYTHON)ru)rkeyvaluer r r s  z-TestSupport.check_options..T)r.runiversal_newlinesenvr)r- executabler9environitems subprocessrunPIPEDEVNULLrr.rstriprepr returncode)r argsfuncexpectedcodecmdrprocr r r 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 rr r r test_args_from_interpreter_flagss2, z,TestSupport.test_args_from_interpreter_flagsc CsTgdgdgdgfD]<}|j|d||dWdq1sD0YqdS)Nz-Oz-OOz-OOOOrZ!optim_args_from_interpreter_flagsrrr r r&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 ||_dSrtest_id)r rr r r__init__&sz2TestSupport.test_match_test..Test.__init__cSs|jSrrr)r r rid)sz,TestSupport.test_match_test..Test.idN)rrrrrr r r rTest%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)rrCZset_match_testsreZ match_testrr8)r r r Z test_chdirr r rtest_match_test$sz  0  zTestSupport.test_match_testc CsNt}tttj}zt}Wt|n t|0|||ddS)Nrr)rZfd_countr9r5__file__O_RDONLYrXr)r startrZmorer r r test_fd_counts  zTestSupport.test_fd_countcCsFt}tj}z|t_t|W|t_n|t_0|||dSr)rrr-rrZ print_warningrr)r rrrrr r rcheck_print_warnings zTestSupport.check_print_warningcCs|dd|dddS)NrzWarning -- msg za bzWarning -- a Warning -- b )rr)r r rtest_print_warnings zTestSupport.test_print_warning)N);rrr classmethodrrr"r*r+r,r'skipr/r4r=rIrTr[r]r_rhrirorwZ skipUnlessrr9r|rrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrr r r rrsr         / " 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)rrrr r r rrs r__main__)rrPrr9rnrUrErr-r`rzrr'rtestrZ test.supportrrr6ZTestCaserrrmainr r r rs4   2