Format: application/x-python-code
⬇ Download File (15.1 KB)
   1  o
   2  
   3  ��hy>�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
   4  mZmZddl
   5  mZddlZddlmZddlZddlmZdd	lmZdd
   6  lmZmZmZddlmZddlmZzddlZWn1e y�ddl!Z!d
   7  Z"e!�#e"�ej$e"<zddlZWne y�ddl%Zd\e_&e_'YnwYnwej(Z)e�*�Z+ee+d�Z,dd�Z-dd�Z.ej/dd��Z0ej1�2d�Z3ee3dd���Z4ee3dd���Z5ee3dd���Z6e3dd��Z7ee3dd���Z8ee3d d!���Z9e3d"d#��Z:e3d$d%��Z;e3d&d'��Z<e3d(d)��Z=d*d+�Z>ejd,d-��Z?ejd.d/��Z@eje3d0d1���ZAe3d2d3��ZBed4d5��ZCGd6d7�d7ejD�ZEej1�Fd8gd9��d:d;��ZGed<d=��ZHGd>d?�d?ejD�ZIdS)@zTests for IPython.utils.path.py�N)�contextmanager)�reload)�abspath�join)�patch)�TemporaryDirectory)�paths)�
   8  decorators)�onlyif_unicode_paths�skip_if_not_win32�
   9  skip_win32)�
  10  make_tempfile��path�winreg)NNZ
  11  home_test_dircCst�tj�td��dS)zJSetup testenvironment for the module:
  12  
  13      - Adds dummy home dir tree
  14      �ipythonN)�os�makedirsrr�
  15  HOME_TEST_DIR�rr�Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/tests/test_path.py�setup_module9srcCst�t�dS)zOTeardown testenvironment for the module:
  16  
  17      - Remove dummy home dir tree
  18      N)�shutil�rmtree�TMP_TEST_DIRrrrr�teardown_moduleCsrccs��t��tjtjtjtj	t�
  19  �fadVt\}t_t_t_t_	}t�|�t
  20  t�tt�D]	}||vr6t|=q-t�|�ttd�rCJ�dS)N�frozen)�env�copyr�name�sys�platformr�get_home_dir�IPython�__file__�getcwdZoldstuff�chdirr�list�update�hasattr)ZoldenvZold_wd�keyrrr�environmentOs2��		�
  21  �
  22  r+cCsBt��}|jtdddd�tttd��t_t��}||ksJ�dS)z1Testcase for py2exe logic, un-compressed lib
  23      rTF�ZraisingzLib/IPython/__init__.pyN)	rr"�setattrr rrrr#r$��monkeypatchZunfrozen�home_dirrrr�test_get_home_dir_1rs
  24  r1cCsHt��}|jtdddd�tttd����t_	t�d�}||ks"J�dS)z.Testcase for py2exe logic, compressed lib
  25      rTFr,zLibrary.zip/IPython/__init__.pyN)
  26  rr"r-r rrr�lowerr#r$r.rrr�test_get_home_dir_2�s��
  27  r3cCs.ttd<t�d�}|tj�td�ksJ�dS)z get_home_dir() uses $HOME if set�HOMETN)rrrr"r�realpath)r0rrr�test_get_home_dir_3�s
  28  r6cCsdtvrtd=t�d�}dS)z.get_home_dir() still works if $HOME is not setr4FN)rrr")�homerrr�test_get_home_dir_4�sr8cCs4ttd�td<|�tdd�t�tjtj	d�dS)z@raise HomeDirError if $HOME is specified, but not a writable dir�garbager4r�posixTN)
  29  rrrr-r�pytest�raisesrZHomeDirErrorr"�r/rrr�test_get_home_dir_5�sr>c	Cs�|�tdd�dD]}t�|d�q	Gdd�d�}tjtd|�d��'tjtd	tt�gd��t	�
  30  �}Wd�n1s=wYWd�n1sLwY|tt�ksYJ�dS)
  31  z~Using registry hack for 'My Documents', os=='nt'
  32  
  33      HOMESHARE, HOMEDRIVE, HOMEPATH, USERPROFILE and others are missing.
  34      r�nt)r4Z	HOMESHARE�	HOMEDRIVE�HOMEPATH�USERPROFILENc@s$eZdZdd�Zdd�Zdd�ZdS)z test_get_home_dir_8.<locals>.keycS�dS�Nr��selfrrr�	__enter__��z*test_get_home_dir_8.<locals>.key.__enter__cSrCrDrrErrr�Close�rHz&test_get_home_dir_8.<locals>.key.Closec_rCrDr)�args�kwargsrrr�__exit__�rHz)test_get_home_dir_8.<locals>.key.__exit__N)�__name__�
  35  __module__�__qualname__rGrIrLrrrrr*�sr*�OpenKey)�return_value�QueryValueEx)r-rr�popr�object�wregrrrr")r/r*r0rrr�test_get_home_dir_8�s�
  36  ��rVcCs�|�tddd��|�tddd��|�tdd�|�tdd	�t�d
  37  d�t�dd�t�d
  38  d�t��tj�dd�ks?J�dS)z!test_get_xdg_dir_0, check xdg_dirZ
  39  _writable_dircS�dS)NTrrrrr�<lambda>��z$test_get_xdg_dir_0.<locals>.<lambda>r"cSrW)N�	somewhererrrrrrX�rYrr:r!�linux2�IPYTHON_DIRN�
  40  IPYTHONDIR�XDG_CONFIG_HOMErZ�.config)r-rrr rrS�get_xdg_dirrr=rrr�test_get_xdg_dir_0�sracCsf|�tddd��|�tdd�|�tdd�t�dd	�t�d
  41  d	�t�dd	�t��d	us1J�d	S)z-test_get_xdg_dir_1, check nonexistent xdg_dirr"cS�tSrD�rrrrrrX�rYz$test_get_xdg_dir_1.<locals>.<lambda>rr:r!r[r\Nr]r^)r-rrr rrSr`r=rrr�test_get_xdg_dir_1�srdcCs�|�tddd��|�tdd�|�tdd�t�dd	�t�d
  42  d	�t�dd	�tj�t��d�}tj�|�s=t�	|�t�
  43  �|ksEJ�d	S)
  44  z6test_get_xdg_dir_2, check xdg_dir default to ~/.configr"cSrbrDrcrrrrrX�rYz$test_get_xdg_dir_2.<locals>.<lambda>rr:r!r[r\Nr]r^r_)r-rrr rrSrr"�existsrr`�r/Zcfgdirrrr�test_get_xdg_dir_2�s
  45  rgcCs�|�tddd��|�tdd�|�tdd�t�dd	�t�d
  46  d	�t�dd	�tj�t��d�}tj|d
  47  d�t�	�d	usAJ�d	S)z?test_get_xdg_dir_3, check xdg_dir not used on non-posix systemsr"cSrbrDrcrrrrrX�rYz$test_get_xdg_dir_3.<locals>.<lambda>rr?r!�win32r\Nr]r^r_T)�exist_ok)
  48  r-rrr rrSrr"rr`rfrrr�test_get_xdg_dir_3�srjcCs"t��}t��}t�|j|�}dS)zVarious tests for filefindN)�tempfile�NamedTemporaryFiler�get_ipython_dirrZfilefindr)�fZalt_dirs�trrr�
  49  test_filefind�srpcCsvt��.}tj�t�|�d�}t�|�tj�|d�}t�|�}|��|��ks)J�Wd�dS1s4wYdS)Nzthis is my long path namezTHISIS~1)rrrr�get_long_path_namerr2)�tmpdirZ	long_pathZ
  50  short_pathZevaluated_pathrrr�test_get_long_path_name_win32s
  51  
  52  "�rscCst�d�}|dksJ�dS)Nz
  53  /usr/local)rrq)�prrr�test_get_long_path_names
  54  rucCs�t��}dt_t�dd�t�dd�t�dd�|td<tj�|d�}t�|d�zt	tj�|d�d	d
  55  d��
  56  �Wn	tyCYnwt�
  57  d�tjtd
  58  d��t��}Wd�n1s_wYt�dd�dS)Nr:r\r]r^r4z.ipythonimZ_foo_�w�utf-8��encodingz0I can't create directories that I can't write tozis not a writable location)�match)rk�mkdtemprrrrSrr�mkdir�open�close�IOErrorr;�skipZwarns�UserWarningrrm)rrZipdirrrr�test_not_writable_ipdirs$ �
  59  
  60  �r�cCs6t�t�td��t�d�dksJ�t�d�dksJ�Wd�n1s&wYtd��t�d�dks9J�t�ttjd�Wd�n1sKwYt�ttjd�t�ttjd�d}t|��+t�d�|kspJ�t�d�|ksyJ�t�ttjd�t�ttjd�Wd�dS1s�wYdS)Nzfoo.pyZfoozfoo with spaces.pyzfoo with spacesz"foo with spaces.py"z'foo with spaces.py')	rr&rr
  61  r�get_py_filenamer;r<r)Ztrue_fnrrr�test_get_py_filename3s$
  62  
  63  �
  64  �
  65  "�r�c
  66  Cs@zt�d�WdSty}zt|�WYd}~dSd}~ww)z�When a file doesn't exist, the exception raised should be safe to call
  67      str() on - i.e. in Python 2 it must only have ASCII characters.
  68  
  69      https://github.com/ipython/ipython/issues/875
  70      u
  71  fooéè.pyN)rr�r�str)�exrrr�test_unicode_in_filenameEs��r�c@s\eZdZedd��Zedd��Zeedd���Zdd�Zd	d
  72  �Z	e
  73  dd��Zed
  74  d��Z
  75  dS)�
  76  TestShellGlobcCs�gd�|_gd�|_|j|j|_t�|_|jj}|���|jD]}ttj	�
  77  ||�ddd���q!Wd�dS1s=wYdS)N)Za0Za1Za2)�0bZ1bZ2brvrwrx)�filenames_start_with_a�filenames_end_with_b�	filenamesr�tempdirr�
  78  in_tempdirr}rrrr~)�cls�td�fnamerrr�
  79  setUpClassUs
  80  
  81  
  82  
  83  �"�zTestShellGlob.setUpClasscC�|j��dSrD�r��cleanup)r�rrr�
  84  tearDownClassbszTestShellGlob.tearDownClassc	cs<�t��}zt�|jj�dVWt�|�dSt�|�wrD)rr%r&r�r)r��saverrrr�fs�zTestShellGlob.in_tempdircCsH|���tt�|��t|�ksJ�Wd�dS1swYdSrD)r��sortedrZ	shellglob�rF�patterns�matchesrrr�check_matchps
  85  "�zTestShellGlob.check_matchcCsJdg|jfdg|jfdgdgfgd�|j|j|jdgfdg|jfgS)N�*�a*�*c)r�r�z*br��a[012])r�r�r�rErrr�common_casesus
  86  
  87  
  88  
  89  ���
  90  �zTestShellGlob.common_casescCsL|��dgdgfddgdg|jfdgdgfgD]
  91  \}}|�||�qdS)N�\*r��a\*r��a\[012]r��r�r�r�r�rrr�test_match_posix�s
  92  
  93  ��zTestShellGlob.test_match_posixcCsB|��ddgdg|jfdgdgfgD]
  94  \}}|�||�qdS)Nr�r�r�r�r�rrr�test_match_windows�s
  95  ��z TestShellGlob.test_match_windowsN)rMrNrO�classmethodr�r�rr�r�r�rr�rr�rrrrr�Ss
  96  
  97  
  98  r�zglobstr, unescaped_globstr))z
  99  \*\[\!\]\?z*[!]?)z\\*r�)z\\\*r�)z\\a�\a)r�r�cCst�|�|ks	J�dSrD)rZ
 100  unescape_glob)ZglobstrZunescaped_globstrrrr�test_unescape_glob�sr�c	Cs�t��T}tj�|d�}t�|�tj�|�sJ�t�|�tj�|d�}t|ddd���t�	t
 101  ��
 102  t�|�Wd�n1sBwYWd�dSWd�dS1sZwYdS)Nu∂iruƒilervrwrx)rrrrZensure_dir_exists�isdirr}r~r;r<r)r��drnrrr�test_ensure_dir_exists�s
 103  
 104  ��"�r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
 105  �Zdd�Ze	d
 106  d��Z
 107  e	dd��Ze	dd��Ze	dd��Z
 108  edd��Zdd�ZdS)�TestLinkOrCopycCsTt�|_|�d�|_t|jddd��}|�d�Wd�dS1s#wYdS)N�srcrvrwrxz
 109  Hello, world!)rr��dstr�r}�write)rFrnrrr�setUp�s
 110  "�zTestLinkOrCopy.setUpcCr�rDr�rErrr�tearDown�szTestLinkOrCopy.tearDowncGstjj|jjg|�R�SrD)rrrr�r)rFrJrrrr��szTestLinkOrCopy.dstcCs,t�|�jt�|�jksJd||f��dS)Nz&%r and %r do reference the same indoes�r�stat�st_ino�rF�a�brrr�assert_inode_not_equal��
 111  �z%TestLinkOrCopy.assert_inode_not_equalcCs,t�|�jt�|�jksJd||f��dS)Nz*%r and %r do not reference the same indoesr�r�rrr�assert_inode_equal�r�z!TestLinkOrCopy.assert_inode_equalc	Cs~t|d��0}t|d��}|��|��ksJ�Wd�n1s wYWd�dSWd�dS1s8wYdS)N�rb)r}�read)rFr�r�Za_fZb_frrr�assert_content_equal�s��"�z#TestLinkOrCopy.assert_content_equalcC�*|�d�}t�|j|�|�|j|�dS�N�target)r�r�link_or_copyr�r��rFr�rrr�test_link_successful��
 112  z#TestLinkOrCopy.test_link_successfulcCsJ|�d�}t�|�t�|j|�|�dtj�|j��}|�|j|�dS)NZsome_dir)r�rr|rr�r��basenamer�)rFr�Zexpected_dstrrr�test_link_into_dir�s
 113  
 114  
 115  z!TestLinkOrCopy.test_link_into_dircCs<|�d�}t|ddd���t�|j|�|�|j|�dS)Nr�rvrwrx)r�r}r~rr�r�r�r�rrr�test_target_exists�s
 116  z!TestLinkOrCopy.test_target_existscCsTtj}z"t`|�d�}t�|j|�|�|j|�|�|j|�W|t_dS|t_wr�)r�linkr�rr�r�r�r�)rFZ	real_linkr�rrr�test_no_link�s
 117  zTestLinkOrCopy.test_no_linkcCr�r�)r�rr�r�r�r�rrr�test_windows�r�zTestLinkOrCopy.test_windowscCsV|�d�}t�|j|�t�|j|�|�|j|�tt�|jj	��ddgks)J�dS)Nr�r�)
 118  r�rr�r�r�r�r�listdirr�rr�rrr�test_link_twice�s
 119  
 120  "zTestLinkOrCopy.test_link_twiceN)rMrNrOr�r�r�r�r�r�rr�r�r�r�rr�r�rrrrr��s$
 121  
 122  
 123  
 124  
 125  r�)J�__doc__rrr rkZunittest�
 126  contextlibr�	importlibrZos.pathrrZ
 127  unittest.mockrr;rr#rZIPython.testingr	�decZIPython.testing.decoratorsr
 128  rrZIPython.testing.toolsr
 129  Z
 130  IPython.utilsrrrU�ImportError�typesZwr_name�
 131  ModuleType�modules�_winregrPrR�environrr{rrrrZfixturer+�markZusefixturesZwith_environmentr1r3r6r8r>rVrardrgrjrprsrur�r�r�ZTestCaser�Zparametrizer�r�r�rrrr�<module>s����
 132  
 133  
 134  
 135  
 136  
 137  
 138  
 139  
 140  
 141  
 142  	
 143  
 144  
 145  
 146  
 147  C�
 148  
 149  
 150