D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
lib
/
python3.8
/
test
/
__pycache__
/
Filename :
test_support.cpython-38.pyc
back
Copy
U �������gv`����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlmZ�d�dlmZ�ejZG�dd��de j�Zdd��Zedkr�e���dS�) �����N)�support)� script_helperc�������������������@���s���e�Zd�Zdd��Zdd��Zdd��Ze�d�dd ���Zd d��Z dd ��Z dd��Zdd��Zdd��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#d<d=��Z$d>d?��Z%d@dA��Z&dBdC��Z'dDdE��Z(dFdG��Z)G�dHdI��dI�Z*G�dJdK��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�TestSupportc�����������������C���s ���t��d��|��tjt�jd��d�S�)N�ftplib�foo)r���� import_module�assertRaises�unittest�SkipTest��self��r ����'/usr/lib/python3.8/test/test_support.py�test_import_module���s���� zTestSupport.test_import_modulec�����������������C���s���t��d��d�S�)Nr���)r���Zimport_fresh_moduler���r ���r ���r����test_import_fresh_module���s����z$TestSupport.test_import_fresh_modulec�����������������C���s.���|���t�|�d�|�j��|��tjtj|�d��d�S�)N�test_get_attributer���)�assertEqualr���Z get_attributer���r���r ���r ���r���r ���r ���r���r������s�����zTestSupport.test_get_attributezfailing buildbotsc�����������������C���s���|���t���tj��d�S��N)r���r���Zget_original_stdout�sys�stdoutr���r ���r ���r����test_get_original_stdout#���s����z$TestSupport.test_get_original_stdoutc�����������������C���s2���dd�l�}|��dtj��t�d��|��dtj��d�S�)Nr����sched)r����assertInr����modulesr���Zunload�assertNotIn)r���r���r ���r ���r����test_unload'���s���� zTestSupport.test_unloadc�������������� ���C���s@���t�td��}W�5�Q�R�X�t�t��|��tj�t���t�t��d�S�)N�w)�open�TESTFNr����unlink�assertFalse�os�path�exists)r����fr ���r ���r����test_unlink-���s ���� zTestSupport.test_unlinkc�������������� ���C���s$��t�jd�}tj�|d�}t�|��t�|��t��|��|��tj�|���t�� t�dd���t��|��W�5�Q�R�X�t�|��t�|��t� |tjtj B���t�� t�dd���t��|��W�5�Q�R�X�|��tj�|���t�|��t�|��t� |d��t�� t�dd���t��|��W�5�Q�R�X�|��tj�|���d�S�)N�dZsubdir�verboser���)r���r���r!���r"����join�mkdir�rmtreer ���r#���� swap_attr�chmod�stat�S_IRUSR�S_IXUSR)r����dirpathZ subdirpathr ���r ���r����test_rmtree4���s(���� zTestSupport.test_rmtreec�������������� ���C���s����t�d�}t|d��}td|d��W�5�Q�R�X�tj�dtj��t� ���z2t t��}|��t�tj��t �t���|��t�tj��W�5�tjd=�t �|��t �d��X�d�S�)Nz.pyr���zfoo = 1��filer����__pycache__)r���r����printr���r"����insertr!����curdir� importlib�invalidate_cachesr���r���r*���� __import__r���r���Zforgetr���)r���Zmod_filenamer$����modr ���r ���r����test_forgetL���s���� zTestSupport.test_forgetc�����������������C���s���t��tjdf�}|����d�S�)Nr���)�socket� create_serverr����HOST�close�r����sr ���r ���r���� test_HOST]���s����zTestSupport.test_HOSTc�����������������C���s$���t����}t�t�j|f�}|����d�S�r���)r���Zfind_unused_portr=���r>���r?���r@���)r���ZportrB���r ���r ���r����test_find_unused_porta���s����z!TestSupport.test_find_unused_portc�����������������C���s&���t�����}t�|��|����|����d�S�r���)r=���r���Z bind_portZlistenr@���rA���r ���r ���r����test_bind_portf���s���� zTestSupport.test_bind_portc�������������� ���C���s����t����}tj�|�}zjtj�|d�}|��tj� |���t� |��$}|��||��|��tj� |���W�5�Q�R�X�|��tj� |���W�5�t�|��X�dS�)z8Test that temp_dir() creates and destroys its directory.ZtempN) �tempfile�mkdtempr!���r"����realpathr���r*���r(���r ����isdir�temp_dirr���� assertTrue)r���� parent_dirr"���� temp_pathr ���r ���r���� test_temp_dirn���s����zTestSupport.test_temp_dirc�������������� ���C���s<���t�����}|��tj�|���W�5�Q�R�X�|��tj�|���dS�)zTest passing no path.N)r���rJ���rK���r!���r"���rI���r ���)r���rM���r ���r ���r����test_temp_dir__path_none}���s���� z$TestSupport.test_temp_dir__path_nonec�������������� ���C���sd���dd��}t����}tj�|�}z6|��tj�|���|�� t ||��|��tj�|���W�5�t�|��X�dS�)z-Test passing a directory that already exists.c�������������� ���S���s"���t��|���}td��W�5�Q�R�X�d�S��Nzshould not get here)r���rJ���� Exception)r"���rM���r ���r ���r���� call_temp_dir����s����zMTestSupport.test_temp_dir__existing_dir__quiet_default.<locals>.call_temp_dirN)rF���rG���r!���r"���rH����shutilr*���rK���rI���r����FileExistsError)r���rR���r"���r ���r ���r����*test_temp_dir__existing_dir__quiet_default����s����z6TestSupport.test_temp_dir__existing_dir__quiet_defaultc�������������� ���C���s����t����}tj�|�}z`t����<}tj |dd��}|�� ||��W�5�Q�R�X�dd��|jD��}W�5�Q�R�X�|��tj� |���W�5�t�|��X�|�� t|�d|��|d�}|��|�d|�d��|��d S�) z=Test passing a directory that already exists with quiet=True.T��quietc�����������������S���s���g�|�]}t�|j��qS�r �����str�message��.0r���r ���r ���r���� <listcomp>����s�����zGTestSupport.test_temp_dir__existing_dir__quiet_true.<locals>.<listcomp>����r���z5tests may fail, unable to create temporary directory �: N)rF���rG���r!���r"���rH���rS���r*���r����check_warningsrJ���r����warningsrK���rI����len� startswith)r���r"����recorderrM���ra����warnr ���r ���r����'test_temp_dir__existing_dir__quiet_true����s���� �z3TestSupport.test_temp_dir__existing_dir__quiet_true�forkztest requires os.forkc�����������������C���s���t��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 (child has pid == 0) # wait for the child to terminate (pid, status) = os.waitpid(pid, 0) if status != 0: raise AssertionError(f"Child process failed with exit " f"status indication 0x{status:x}.") # 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)r���Zassert_python_ok�textwrapZdedentr���r ���r ���r����test_temp_dir__forked_child����s����z'TestSupport.test_temp_dir__forked_childc�������������� ���C���sb���t����}t����8}t�|��"}|��||��|��t����|��W�5�Q�R�X�W�5�Q�R�X�|��t����|��d�S�r���)r!����getcwdr���rJ���� change_cwdr���)r����original_cwdrM����new_cwdr ���r ���r����test_change_cwd����s���� $zTestSupport.test_change_cwdc�������������� ���C���sT���t����}dd��}t����"}t�j�|d�}|��t||��W�5�Q�R�X�|��t����|��dS�)z&Test passing a non-existent directory.c�������������� ���S���s"���t��|���}td��W�5�Q�R�X�d�S�rP���)r���rl���rQ���)r"���rn���r ���r ���r����call_change_cwd����s����zFTestSupport.test_change_cwd__non_existent_dir.<locals>.call_change_cwd�does_not_existN) r!���rk���r���rJ���r"���r(���r����FileNotFoundErrorr���)r���rm���rp���rL���Znon_existent_dirr ���r ���r����!test_change_cwd__non_existent_dir����s���� �z-TestSupport.test_change_cwd__non_existent_dirc�����������������C���s����t����}t����n}t�j�|d�}t����L}tj|dd��"}|��||��|��t����|��W�5�Q�R�X�dd��|j D��}W�5�Q�R�X�W�5�Q�R�X�|��t |�d|��|d�}|��|�d|�d ��|��d S�)z6Test passing a non-existent directory with quiet=True.rq���TrV���c�����������������S���s���g�|�]}t�|j��qS�r ���rX���r[���r ���r ���r���r]�������s�����zMTestSupport.test_change_cwd__non_existent_dir__quiet_true.<locals>.<listcomp>r^���r����Btests may fail, unable to change the current working directory to r_���N) r!���rk���r���rJ���r"���r(���r`���rl���r���ra���rb���rK���rc���)r���rm���rL���Zbad_dirrd���rn���ra���re���r ���r ���r����-test_change_cwd__non_existent_dir__quiet_true����s���� $�z9TestSupport.test_change_cwd__non_existent_dir__quiet_truec�������������� ���C���s~���t�d�}t����0}tj|dd���W�5�Q�R�X�dd��|jD��}W�5�Q�R�X�|��t|�d|��|d�}|��|�d|�d ��|��d S�)z0Check the warning message when os.chdir() fails.Z_does_not_existT)r"���rW���c�����������������S���s���g�|�]}t�|j��qS�r ���rX���r[���r ���r ���r���r]�������s�����z>TestSupport.test_change_cwd__chdir_warning.<locals>.<listcomp>r^���r���rt���r_���N) r���r���r`���rl���ra���r���rb���rK���rc���)r���r"���rd���Zmessages�msgr ���r ���r����test_change_cwd__chdir_warning����s���� �z*TestSupport.test_change_cwd__chdir_warningc�������������� ���C���s^���t����}tjtd���|��t�j�t�����t��W�5�Q�R�X�|��t�j� t���|��t����|��d�S�)N��name) r!���rk���r����temp_cwdr���r���r"����basenamer ���r#���)r����herer ���r ���r���� test_temp_cwd��s ����"zTestSupport.test_temp_cwdc�������������� ���C���sb���t����}tjdd��4}|��||��|��t�j�|���|��t����|��W�5�Q�R�X�|��t����|��dS�)z Test passing None to temp_cwd().Nrx���) r!���rk���r���rz���ZassertNotEqualrK���r"���rI���r���)r���rm���rn���r ���r ���r����test_temp_cwd__name_none��s����z$TestSupport.test_temp_cwd__name_nonec�����������������C���s���|���t�dddd��d��d�S�)N��������r^���)r���r����r^���z{1: 1, 2: 2, 3: 3})r���r���Zsortdictr���r ���r ���r���� test_sortdict��s����zTestSupport.test_sortdictc�������������� ���C���s@���t����}|��t��}t�|d��W�5�Q�R�X�|��|jjtj ��d�S�)Ns���foo) r���Zmake_bad_fdr����OSErrorr!����writer���Z exception�errnoZEBADF)r����fd�cmr ���r ���r����test_make_bad_fd��s����zTestSupport.test_make_bad_fdc�������������� ���C���s8���t�j|�dddd��|��t���t��|�d��W�5�Q�R�X�d�S�)Nz def classr^�������)�lineno�offsetzx=1)r���Zcheck_syntax_errorr����AssertionErrorr���r ���r ���r����test_check_syntax_error��s����z#TestSupport.test_check_syntax_errorc�������������� ���C���s,���dd�l�}t�d���|�d��W�5�Q�R�X�d�S�)Nr���Zasyncore)r8���r���ZCleanImportr���)r���r8���r ���r ���r����test_CleanImport#��s����zTestSupport.test_CleanImportc�������������� ���C���sT���t��dd��"�|��dtj��|��dtj��W�5�Q�R�X�|��dtj��|��dtj��d�S�)Nr���Zbar)r���Z DirsOnSysPathr���r���r"���r���r���r ���r ���r����test_DirsOnSysPath(��s ����zTestSupport.test_DirsOnSysPathc�������������� ���C���s0���t�����}td��W�5�Q�R�X�|��|���d��d�S�)N�hello�hello )r���Zcaptured_stdoutr5���r����getvalue)r���r���r ���r ���r����test_captured_stdout/��s���� z TestSupport.test_captured_stdoutc�������������� ���C���s6���t�����}tdtjd��W�5�Q�R�X�|��|���d��d�S�)Nr����r2���r����)r���Zcaptured_stderrr5���r����stderrr���r����)r���r����r ���r ���r����test_captured_stderr4��s���� z TestSupport.test_captured_stderrc�������������� ���C���s>���t����� }|�d��|�d��t��}W�5�Q�R�X�|��|d��d�S�)Nr����r���r����)r���Zcaptured_stdinr�����seek�inputr���)r����stdinZcapturedr ���r ���r����test_captured_stdin9��s ���� zTestSupport.test_captured_stdinc�����������������C���s���t�����d�S�r���)r���Z gc_collectr���r ���r ���r����test_gc_collectA��s����zTestSupport.test_gc_collectc�����������������C���s���|���t���t��d�S�r���)ZassertIsInstancer���Zpython_is_optimized�boolr���r ���r ���r����test_python_is_optimizedD��s����z$TestSupport.test_python_is_optimizedc�������������� ���C���s����G�dd��d�}|��}d|_�t�|dd�� }|��|j�d��|��|d��W�5�Q�R�X�|��|j�d��t�|dd��}|��|jd��|��|��W�5�Q�R�X�|��t|d���t�|dd�� �|`W�5�Q�R�X�|��t|d���d�S�)Nc�������������������@���s���e�Zd�ZdS�)z'TestSupport.test_swap_attr.<locals>.ObjN)�__name__� __module__�__qualname__r ���r ���r ���r����ObjH��s���r����r^����xr�����y)r����r���r+���r���r�����assertIsNoner ����hasattr)r���r�����objr����r����r ���r ���r����test_swap_attrG��s����zTestSupport.test_swap_attrc�������������� ���C���s����ddi}t��|dd��"}|��|d�d��|��|d��W�5�Q�R�X�|��|d�d��t��|dd�� }|��|d�d��|��|��W�5�Q�R�X�|��d|��t��|dd���|d=�W�5�Q�R�X�|��d|��d�S�)Nr����r^���r����r����)r���Z swap_itemr���r����r���)r����Dr����r����r ���r ���r����test_swap_itemX��s����zTestSupport.test_swap_itemc�������������������@���s���e�Zd�ZdZdZdZdZdS�)zTestSupport.RefClassN)r����r����r����� attribute1� attribute2Z_hidden_attribute1�__magic_1__r ���r ���r ���r����RefClassf��s���r����c�������������������@���s���e�Zd�ZdZdZdZdZdS�)zTestSupport.OtherClassN)r����r����r����r����� attribute3r�����__magic_2__r ���r ���r ���r���� OtherClassl��s���r����c�����������������C���sB���t��|�j|�j�}|��dh|��t��|�j|�j�}|��ddh|��d�S�)Nr����r����r����)r����detect_api_mismatchr����r����r���)r���� missing_itemsr ���r ���r����test_detect_api_mismatchr��s������z$TestSupport.test_detect_api_mismatchc�����������������C���sT���ddddg}t�j|�j|�j|d�}|��t��|��t�j|�j|�j|d�}|��t��|��d�S�)Nr����r����r����Z not_in_either)�ignore)r���r����r����r����r����set)r���r����r����r ���r ���r���� test_detect_api_mismatch__ignore{��s����������z,TestSupport.test_detect_api_mismatch__ignorec�����������������C���sZ���dh}dh}t�j|�t||d��ddh}dddh}t�j|�td ||d��|��tt�j|�t��d�S�) NZtempdir�template)�extra� blacklistZTextTestResultZinstallHandlerZ load_testsZTestProgramZ BaseTestSuite)zunittest.resultz unittest.casezunittest.suitezunittest.loaderz unittest.mainzunittest.runnerzunittest.signalszunittest.async_case)r���Zcheck__all__rF���r ���r���r����)r���r����r����r ���r ���r����test_check__all__���s ����� � zTestSupport.test_check__all__�waitpid�WNOHANGz need os.waitpid() and os.WNOHANGc�����������������C���s����t�����t���}|dkr"t�d��t���}t���d�}t�j}z�dt�_t� ��}t���|krb|�� d��tj}z|t_t�����W�5�|t_X�t�jr�q�t� d��qLd|�}|��||�����|��t�j��W�5�|t�_X�t�����d�S�)Nr���g������N@FZtimeoutg�������?z2Warning -- reap_children() reaped child process %s)r���Z reap_childrenr!���rg����_exit�time� monotonicZenvironment_altered�io�StringIOZfailr���� __stderr__�sleepr���r����rK���)r����pidZt0ZdeadlineZwas_alteredr����� old_stderrrv���r ���r ���r����test_reap_children���s2���� zTestSupport.test_reap_childrenNc�����������������C���s����d|��d|��d�}t�jf|d|f�}dd��tj���D��}tj|tjtjd|d�}|d�kr\|}|�� |j ���t|���|�� |j d ��d�S�) Nzfrom test.support import z ; print(repr(z()))rh���c�����������������S���s ���i�|�]\}}|��d��s||�qS�)ZPYTHON)rc���)r\����key�valuer ���r ���r���� <dictcomp>���s���� ��z-TestSupport.check_options.<locals>.<dictcomp>T)r���r����Zuniversal_newlines�envr���)r���� executabler!����environ�items� subprocess�run�PIPEZDEVNULLr���r����rstrip�repr� returncode)r����args�func�expected�code�cmdr�����procr ���r ���r���� check_options���s�����zTestSupport.check_optionsc�����������������C���s����g�dgdgdgdgdgdgdgdgd gd gdgdd gddd gddgddgddgddgddgddgfD�](}|�j�|d���|��|d��W�5�Q�R�X�qd|��dddgddg��d�S�)Nz-Bz-sz-Sz-Ez-vz-bz-qz-Iz-bbz-vvvz-Wignorez-XZdevZfaulthandlerZ importtimeZshowalloccountZshowrefcount�tracemallocz tracemalloc=3��optsZargs_from_interpreter_flags�ZsubTestr�����r���r����r ���r ���r���� test_args_from_interpreter_flags���s4������z,TestSupport.test_args_from_interpreter_flagsc�������������� ���C���s@���g�dgdgdgfD�](}|�j�|d���|��|d��W�5�Q�R�X�qd�S�)Nz-Oz-OOz-OOOOr����Z!optim_args_from_interpreter_flagsr����r����r ���r ���r����&test_optim_args_from_interpreter_flags���s�����z2TestSupport.test_optim_args_from_interpreter_flagsc�������������� ���C���s���G�dd��d�}|d�}|d�}t��t�dd������t��g���|��t��|���|��t��|���t��d�d���|��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��ddgd���|��t��|���|��t��|���W�5�Q�R�X�t��t�dd������t�jg�d ��|��t��|���|��t��|���t��d�d���|��t��|���|��t��|���t��d�|���g��|��t��|���|��t��|���t��d�dg��|��t��|���|��t��|���t��d�dg��|��t��|���|��t��|���t��d�dg��|��t��|���t��d�d g��|��t��|���t��d�d g��|��t��|���|��t��|���t��d�|���|���g��|��t��|���|��t��|���t��d�ddg��|��t��|���|��t��|���W�5�Q�R�X�d�S�)Nc�������������������@���s���e�Zd�Zdd��Zdd��ZdS�)z)TestSupport.test_match_test.<locals>.Testc�����������������S���s ���||�_�d�S�r�����test_id)r���r����r ���r ���r����__init__ ��s����z2TestSupport.test_match_test.<locals>.Test.__init__c�����������������S���s���|�j�S�r���r����r���r ���r ���r����id��s����z,TestSupport.test_match_test.<locals>.Test.idN)r����r����r����r����r����r ���r ���r ���r����Test��s���r����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)Zignore_patterns)r���r+���Zset_match_testsrK���Z match_testr����r ���)r���r����r����Z test_chdirr ���r ���r����test_match_test��sz���� zTestSupport.test_match_testc�������������� ���C���sD���t����}t�ttj�}zt����}W�5�t�|��X�|��||�d��d�S�)Nr^���)r���Zfd_countr!���r����__file__�O_RDONLYr@���r���)r����startr����Zmorer ���r ���r���� test_fd_countt��s����zTestSupport.test_fd_countc�����������������C���s@���t����}tj}z|t_t�|��W�5�|t_X�|��|���|��d�S�r���)r����r����r���r����r���Z print_warningr���r����)r���rv���r����r����r����r ���r ���r����check_print_warning���s����zTestSupport.check_print_warningc�����������������C���s���|���dd��|���dd��d�S�)Nrv���zWarning -- msg za bzWarning -- a Warning -- b )r����r���r ���r ���r����test_print_warning���s������zTestSupport.test_print_warning)N)7r����r����r����r���r���r���r ����skipr���r���r%���r1���r<���rC���rD���rE���rN���rO���rU���rf���Z skipUnlessr����r!���rj���ro���rs���ru���rw���r}���r~���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r ���r ���r ���r���r������sh��� � / #ir���c������������������C���s���t�g}�tj|����d�S�r���)r���r���Zrun_unittest)Ztestsr ���r ���r���� test_main���s����r�����__main__)� contextlibr����r8���r����r!���rS���r=���r-���r����r���rF���ri���r����r ���Ztestr���Ztest.supportr���r���ZTestCaser���r����r����r ���r ���r ���r����<module>���s2��������