
    ^h>                     R   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
JrJr  SSKJr  SSKrSSKJr  SSKrSSKJr  SS	KJr  SS
KJrJrJr  SSKJr  SSKJr   SSKr\RP                  r)\RT                  " 5       r+\" \+S5      r,S r-S r.S r/S r0\Rb                  S 5       r2\Rf                  Ri                  S5      r5\\5S 5       5       r6\\5S 5       5       r7\\5S 5       5       r8\5S 5       r9\\5S 5       5       r:\\5S 5       5       r;\5S 5       r<\5S 5       r=\5S 5       r>\5S 5       r?S  r@\R0                  S! 5       rA\R2                  S" 5       rB " S# S$\R                  5      rD\5S% 5       rE\S& 5       rF " S' S(\R                  5      rG\Rf                  R                  S)/ S*Q5      S+ 5       rI\S, 5       rJ " S- S.\R                  5      rKg! \  aO    SSK!r!Sr"\!RF                  " \"5      \RH                  \"'    SSKr GN! \  a    SSK%rSu  \l&        \l'          GNf = ff = f)/zTests for IPython.utils.path.py    N)contextmanager)reload)abspathjoin)patch)TemporaryDirectory)paths)
decorators)onlyif_unicode_pathsskip_if_not_win32
skip_win32)make_tempfilepathwinreg)NNhome_test_dirc                  t    [         R                  " [         R                  R                  [        S5      5        g)zBSetup testenvironment for the module:

- Adds dummy home dir tree
ipythonN)osmakedirsr   r   HOME_TEST_DIR     W/home/james-whalen/.local/lib/python3.13/site-packages/IPython/utils/tests/test_path.pysetup_moduler   9   s     KK]I67r   c                  8    [         R                  " [        5        g)zGTeardown testenvironment for the module:

- Remove dummy home dir tree
N)shutilrmtreeTMP_TEST_DIRr   r   r   teardown_moduler    C   s     MM,r   c                      [         R                  5       [        R                  [        R
                  [        R                  [        R                  [        R                  " 5       4qg)a-  Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
N)envcopyr   namesysplatformr   get_home_dirIPython__file__getcwdoldstuffr   r   r   setup_environmentr,   N   s:     
BGGS\\43D3DgFVFVXZXaXaXcdHr   c                  Z   [         u  n [        l        [        l        [
        l        [        l        n[        R                  " U5        [        [
        5        [        [        5       H  nX ;  d  M
  [        U	 M     [        R                  U 5        [        [        S5      (       a  [        ?gg)zJRestore things that were remembered by the setup_environment function
    frozenN)r+   r   r$   r%   r&   r   r'   r(   r)   chdirr   listr"   updatehasattrr.   )oldenvold_wdkeys      r   teardown_environmentr6   X   su     T\PVRWclD$5w7GHHV
4LCyC  JJvsHJ r   c               #   <   #    [        5         S v   [        5         g 7fN)r,   r6   r   r   r   environmentr9   h   s     	s   r9   c                      [         R                  " 5       n S[        l        [	        [        [        S5      5      [        l        [         R                  " 5       nX:X  d   eg)z1Testcase for py2exe logic, un-compressed lib
    TzLib/IPython/__init__.pyN)	r   r'   r%   r.   r   r   r   r(   r)   unfrozenhome_dirs     r   test_get_home_dir_1r>   r   sJ    
   "HCJ tM3LMNG  "Hr   c                      [         R                  " 5       n S[        l        [	        [        [        S5      5      R                  5       [        l	        [         R                  " S5      nX:X  d   eg)z.Testcase for py2exe logic, compressed lib
    TzLibrary.zip/IPython/__init__.pyN)
r   r'   r%   r.   r   r   r   lowerr(   r)   r;   s     r   test_get_home_dir_2rA      sS    
   "HCJtM3TUV\\^G  &Hr   c                      [         [        S'   [        R                  " S5      n U [        R                  R                  [        S   5      :X  d   eg)z get_home_dir() uses $HOME if setHOMETN)r   r"   r   r'   r   realpath)r=   s    r   test_get_home_dir_3rE      s>      CK  &Hrww''F4444r   c                  R    S[         ;   a  [         S	 [        R                  " S5      n g)z.get_home_dir() still works if $HOME is not setrC   FN)r"   r   r'   )homes    r   test_get_home_dir_4rH      s!     }#f+U#Dr   c                      [        [        S-   5      [        S'   S[        l        [
        R                  " [        R                  [        R                  S5        g)z@raise HomeDirError if $HOME is specified, but not a writable dirgarbagerC   posixTN)
r   r   r"   r   r$   pytestraisesr   HomeDirErrorr'   r   r   r   test_get_home_dir_5rO      s:     -	12CKBG
MM$##T%6%6=r   c                     S[         l        S H  n [        R                  U S5        M      " S S5      n [        R
                  " [        SU " 5       S9   [        R
                  " [        S[        [        5      /S9   [        R                  " 5       nSSS5        SSS5        W[        [        5      :X  d   eg! , (       d  f       N,= f! , (       d  f       N5= f)	zvUsing registry hack for 'My Documents', os=='nt'

HOMESHARE, HOMEDRIVE, HOMEPATH, USERPROFILE and others are missing.
nt)rC   	HOMESHARE	HOMEDRIVEHOMEPATHUSERPROFILENc                   &    \ rS rSrS rS rS rSrg) test_get_home_dir_8.<locals>.key   c                     g r8   r   selfs    r   	__enter__*test_get_home_dir_8.<locals>.key.__enter__       r   c                     g r8   r   rZ   s    r   Close&test_get_home_dir_8.<locals>.key.Close   r^   r   c                      g r8   r   )argskwargss     r   __exit__)test_get_home_dir_8.<locals>.key.__exit__   r^   r   r   N)__name__
__module____qualname____firstlineno__r\   r`   re   __static_attributes__r   r   r   r5   rW      s    			r   r5   OpenKey)return_valueQueryValueEx)r   r$   r"   popr   objectwregr   r   r   r'   )r5   r=   s     r   test_get_home_dir_8rr      s     BGLT M  
dICE	:	dN'-:P9Q	R$$& 
S 
; w}---- 
S	R 
;	:s$   )C
=B9C
9
C	C


Cc                  t   [        [        5        S [        l        S [        l        S[        l        S[        l        [        R                  SS5        [        R                  SS5        [        R                  SS5        [        R                  " 5       [        R                  R                  S	S
5      :X  d   eg)z!test_get_xdg_dir_0, check xdg_dirc                     g)NTr   r   s    r   <lambda>$test_get_xdg_dir_0.<locals>.<lambda>   s    dr   c                      g)N	somewherer   r   r   r   ru   rv      s    r   rK   linux2IPYTHON_DIRN
IPYTHONDIRXDG_CONFIG_HOMErx   .config)r   r   _writable_dirr'   r   r$   r%   r&   r"   ro   get_xdg_dirr   r   r   r   test_get_xdg_dir_0r      sz     4L*D,DBGCLGGM4 GGL$GGt$k9!EEEEr   c                     [        [        5        S [        l        S[        l        S[
        l        [        R                  SS5        [        R                  SS5        [        R                  SS5        [        R                  " 5       b   eg)z-test_get_xdg_dir_1, check nonexistent xdg_dirc                      [         $ r8   r   r   r   r   ru   $test_get_xdg_dir_1.<locals>.<lambda>       r   rK   ry   rz   Nr{   r|   )
r   r   r'   r   r$   r%   r&   r"   ro   r   r   r   r   test_get_xdg_dir_1r      sa     4L.DBGCLGGM4 GGL$GGt$%%%r   c                     [        [        5        S [        l        S[        l        S[
        l        [        R                  SS5        [        R                  SS5        [        R                  SS5        [        R                  R                  [        R                  " 5       S5      n [        R                  R                  U 5      (       d  [        R                  " U 5        [        R                  " 5       U :X  d   eg)	z6test_get_xdg_dir_2, check xdg_dir default to ~/.configc                      [         $ r8   r   r   r   r   ru   $test_get_xdg_dir_2.<locals>.<lambda>   r   r   rK   ry   rz   Nr{   r|   r}   )r   r   r'   r   r$   r%   r&   r"   ro   r   existsr   r   cfgdirs    r   test_get_xdg_dir_2r      s     4L.DBGCLGGM4 GGL$GGt$77<<))+Y7F77>>&!!
F'''r   c                     [        [        5        S [        l        S[        l        S[
        l        [        R                  SS5        [        R                  SS5        [        R                  SS5        [        R                  R                  [        R                  " 5       S5      n [        R                  " U S	S
9  [        R                  " 5       b   eg)z?test_get_xdg_dir_3, check xdg_dir not used on non-posix systemsc                      [         $ r8   r   r   r   r   ru   $test_get_xdg_dir_3.<locals>.<lambda>   r   r   rQ   win32rz   Nr{   r|   r}   T)exist_ok)r   r   r'   r   r$   r%   r&   r"   ro   r   r   r   r   s    r   test_get_xdg_dir_3r      s     4L.DBGCLGGM4 GGL$GGt$77<<))+Y7FKK&%%%r   c                      [         R                  " 5       n [        R                  " 5       n[        R
                  " U R                  U5      ng)zVarious tests for filefindN)tempfileNamedTemporaryFiler	   get_ipython_dirr   filefindr$   )falt_dirsts      r   test_filefindr      s2    ##%A$$&Haffh'Ar   c                     [        5        n [        R                  R                  [        R                  " U 5      S5      n[        R
                  " U5        [        R                  R                  U S5      n[        R                  " U5      nUR                  5       UR                  5       :X  d   e S S S 5        g ! , (       d  f       g = f)Nzthis is my long path namezTHISIS~1)r   r   r   r   get_long_path_namer   r@   )tmpdir	long_path
short_pathevaluated_paths       r   test_get_long_path_name_win32r     s    		 GGLL!8!8!@B]^	
I WW\\&*5
00<##%):::: 
		s   B%B::
Cc                  @    [         R                  " S5      n U S:X  d   eg )Nz
/usr/local)r   r   )ps    r   test_get_long_path_namer     s     -Ar   c                   B    \ rS rSr\R
                  \S 5       5       rSrg)TestRaiseDeprecationi  c                    [         R                  " 5       nS[        l        [        R                  SS 5        [        R                  SS 5        [        R                  SS 5        U[        S'   [        R                  R                  US5      n[        R                  " US5         [        [        R                  R                  US5      S	S
S9R                  5         [        R                  " S5        U R                  [        S5         [         R"                  " 5       nS S S 5        [        R                  SS 5        g ! [         a     NWf = f! , (       d  f       N5= f)NrK   rz   r{   r|   rC   z.ipythonim  _foo_wutf-8encodingz0I can't create directories that I can't write tozis not a writable location)r   mkdtempr   r$   r"   ro   r   r   mkdiropencloserL   skipIOErrorassertWarnsRegexUserWarningr	   r   )r[   r   ipdirs      r   test_not_writable_ipdir,TestRaiseDeprecation.test_not_writable_ipdir  s     !!#t$d#!4(FVZ0
	LeW-sWEKKM KKJK"";0LM))+E Nt$  		 NMs   $7D< E<
E	E	
Er   N)	rg   rh   ri   rj   decr   with_environmentr   rk   r   r   r   r   r     s     ^^%  %r   r   c                     [         R                  " [        5        [        S5         [        R
                  " S5      S:X  d   e[        R
                  " S5      S:X  d   e S S S 5        [        S5         [        R
                  " S5      S:X  d   e[        R                  " [        [        R
                  S5        S S S 5        [        R                  " [        [        R
                  S5        [        R                  " [        [        R
                  S5        Sn [        U 5         [        R
                  " S5      U :X  d   e[        R
                  " S5      U :X  d   e[        R                  " [        [        R
                  S5        [        R                  " [        [        R
                  S5        S S S 5        g ! , (       d  f       GN`= f! , (       d  f       GN= f! , (       d  f       g = f)Nzfoo.pyfoozfoo with spaces.pyzfoo with spacesz"foo with spaces.py"z'foo with spaces.py')	r   r/   r   r   r   get_py_filenamerL   rM   r   )true_fns    r   test_get_py_filenamer   6  sK   HH\	x	 ##H-999##E*h666 
! 
u	##E*e333gt33X> 
 MM'4//7
MM'4//:"G	w	##$56'AAA##$89WDDDgt335KLgt335KL	 
 	 
!	  
	 
 	s%   9F93AG#BG9
G
G
G+c                  v     [         R                  " S5        g! [         a  n [        U 5         Sn A gSn A ff = f)zWhen a file doesn't exist, the exception raised should be safe to call
str() on - i.e. in Python 2 it must only have ASCII characters.

https://github.com/ipython/ipython/issues/875
u
   fooéè.pyN)r   r   r   str)exs    r   test_unicode_in_filenamer   H  s.    \* Bs    
838c                   z    \ rS rSr\S 5       r\S 5       r\\S 5       5       rS r	S r
\S 5       r\S 5       rS	rg
)TestShellGlobiV  c                    / SQU l         / SQU l        U R                   U R                  -   U l        [        5       U l        U R                  R
                  nU R                  5          U R                   H9  n[        [        R                  R                  X5      SSS9R                  5         M;     S S S 5        g ! , (       d  f       g = f)N)a0a1a2)0b1b2br   r   r   )filenames_start_with_afilenames_end_with_b	filenamesr   tempdirr$   
in_tempdirr   r   r   r   r   )clstdfnames      r   
setUpClassTestShellGlob.setUpClassX  s    %7"#5 22S5M5MM(*[[^^RWW\\",cGDJJL ' s   &A
B99
Cc                 8    U R                   R                  5         g r8   r   cleanup)r   s    r   tearDownClassTestShellGlob.tearDownClasse  s    r   c              #      #    [         R                  " 5       n [         R                  " U R                  R                  5        S v   [         R                  " U5        g ! [         R                  " U5        f = f7fr8   )r   r*   r/   r   r$   )r   saves     r   r   TestShellGlob.in_tempdiri  sF      yy{	HHS[[%%&HHTNBHHTNs   A9.A A9A66A9c                     U R                  5          [        [        R                  " U5      5      [        U5      :X  d   e S S S 5        g ! , (       d  f       g = fr8   )r   sortedr   	shellglobr[   patternsmatchess      r   check_matchTestShellGlob.check_matchs  s8    __$..23vgFFF s   /A


Ac                     S/U R                   4S/U R                  4S/S/4/ SQU R                   U R                  -   U R                  -   S/-   4S/U R                  4/$ )N*a**c)r   r   z*br   a[012])r   r   r   rZ   s    r   common_casesTestShellGlob.common_casesx  s    UDNN#VT001VdV$dnn(,(C(C'D(,(A(A'B *.'/ 0 Z445	
 		
r   c                     U R                  5       S/S/4SS/S/U R                  -   4S/S/4/-    H  u  pU R                  X5        M     g )N\*r   a\*r   a\[012]r   r   r   r   r   s      r   test_match_posixTestShellGlob.test_match_posix  sc    #'#4#4#63% $$$*E*E!EFz*: $X
 X/$r   c                     U R                  5       SS/S/U R                  -   4S/S/4/-    H  u  pU R                  X5        M     g )Nr   r   r   r   r   s      r   test_match_windows TestShellGlob.test_match_windows  sY    #'#4#4#6 $&D,G,G!GH
|,: $X X/$r   r   N)rg   rh   ri   rj   classmethodr   r   r   r   r   r   r   r   r   r   rk   r   r   r   r   r   V  sy    
M 
M     G


 0 0 0 0r   r   zglobstr, unescaped_globstr))z
\*\[\!\]\?z*[!]?)z\\*r   )z\\\*r   )z\\a\a)r   r   c                 <    [         R                  " U 5      U:X  d   eg r8   )r   unescape_glob)globstrunescaped_globstrs     r   test_unescape_globr     s     g&*;;;;r   c                  6   [        5        n [        R                  R                  U S5      n[        R                  " U5        [        R                  R                  U5      (       d   e[        R                  " U5        [        R                  R                  U S5      n[        USSS9R                  5         [        R                  " [        5         [        R                  " U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nu   ∂iru   ƒiler   r   r   )r   r   r   r   ensure_dir_existsisdirr   r   rL   rM   r   )r   dr   s      r   test_ensure_dir_existsr    s    		GGLLW%q!ww}}Qq!GGLLW%Qg&,,.]]7#""1% $ 
	 $# 
	s$   CD
C9(D
9
D	D


Dc                       \ rS rSrS rS rS rS rS rS r	\
S 5       r\
S	 5       r\
S
 5       r\
S 5       r\S 5       rS rSrg)TestLinkOrCopyi  c                     [        5       U l        U R                  S5      U l        [	        U R                  SSS9 nUR                  S5        S S S 5        g ! , (       d  f       g = f)Nsrcr   r   r   zHello, world!)r   r   dstr  r   write)r[   r   s     r   setUpTestLinkOrCopy.setUp  sE    )+88E?$((C'2aGGO$ 322s   A
A$c                 8    U R                   R                  5         g r8   r   rZ   s    r   tearDownTestLinkOrCopy.tearDown  s    r   c                 l    [         R                  R                  " U R                  R                  /UQ76 $ r8   )r   r   r   r   r$   )r[   rc   s     r   r	  TestLinkOrCopy.dst  s$    ww||DLL--555r   c                     [         R                  " U5      R                  [         R                  " U5      R                  :w  d   U< SU< S35       eg )N and z do reference the same indoesr   statst_inor[   abs      r   assert_inode_not_equal%TestLinkOrCopy.assert_inode_not_equal  s;    GGAJ!2!22	=78!<	=2r   c                     [         R                  " U5      R                  [         R                  " U5      R                  :X  d   U< SU< S35       eg )Nr  z! do not reference the same indoesr  r  s      r   assert_inode_equal!TestLinkOrCopy.assert_inode_equal  s=    GGAJ!2!22	A;<a@	A2r   c                     [        US5       n[        US5       nUR                  5       UR                  5       :X  d   e S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nrb)r   read)r[   r  r  a_fb_fs        r   assert_content_equal#TestLinkOrCopy.assert_content_equal  sL    !T]ca#xxzSXXZ///  ] ]s"   A"%A A"
A	A""
A0c                     U R                  S5      n[        R                  " U R                  U5        U R	                  U R                  U5        g Ntarget)r	  r   link_or_copyr  r  r[   r	  s     r   test_link_successful#TestLinkOrCopy.test_link_successful  s8    hhx $((C(#.r   c                 >   U R                  S5      n[        R                  " U5        [        R                  " U R
                  U5        U R                  S[        R                  R                  U R
                  5      5      nU R                  U R
                  U5        g )Nsome_dir)r	  r   r   r   r)  r  basenamer  )r[   r	  expected_dsts      r   test_link_into_dir!TestLinkOrCopy.test_link_into_dir  sf    hhz"
$((C(xx
BGG,<,<TXX,FG,7r   c                     U R                  S5      n[        USSS9R                  5         [        R                  " U R
                  U5        U R                  U R
                  U5        g )Nr(  r   r   r   )r	  r   r   r   r)  r  r  r*  s     r   test_target_exists!TestLinkOrCopy.test_target_exists  sM    hhx S#(..0$((C(#.r   c                 <   [         R                  n [         ?U R                  S5      n[        R                  " U R
                  U5        U R                  U R
                  U5        U R                  U R
                  U5        U[         l        g ! U[         l        f = fr'  )r   linkr	  r   r)  r  r$  r  )r[   	real_linkr	  s      r   test_no_linkTestLinkOrCopy.test_no_link  sn    GG		 ((8$Cdhh,%%dhh4''#6BGiBGs   A0B Bc                     U R                  S5      n[        R                  " U R                  U5        U R	                  U R                  U5        g r'  )r	  r   r)  r  r$  r*  s     r   test_windowsTestLinkOrCopy.test_windows  s8    hhx $((C(!!$((C0r   c                 X   U R                  S5      n[        R                  " U R                  U5        [        R                  " U R                  U5        U R	                  U R                  U5        [        [        R                  " U R                  R                  5      5      SS/:X  d   eg )Nr(  r  )
r	  r   r)  r  r  r   r   listdirr   r$   r*  s     r   test_link_twiceTestLinkOrCopy.test_link_twice  sy     hhx $((C($((C(#.bjj!2!2348IIIIr   )r  r   N)rg   rh   ri   rj   r  r  r	  r  r  r$  r   r+  r1  r4  r9  r   r<  r@  rk   r   r   r   r  r    s    %6=
A
0
 / /
 8 8 / / 	  	  1 1
Jr   r  )L__doc__r   r   r%   r   unittest
contextlibr   	importlibr   os.pathr   r   unittest.mockr   rL   r   r(   r	   IPython.testingr
   r   IPython.testing.decoratorsr   r   r   IPython.testing.toolsr   IPython.utilsr   r   rq   ImportErrortypeswr_name
ModuleTypemodules_winregrl   rn   environr"   r   r   r   r   r    r,   r6   fixturer9   markusefixturesr   r>   rA   rE   rH   rO   rr   r   r   r   r   r   r   r   TestCaser   r   r   r   parametrizer   r  r  r   r   r   <module>rX     s   %
 
  
   %  !   '   - 
 0 :" 	jj!\?3
8 e    ;;**=9  
   
  	   	  5  5 $ $ >  > .  .. F F 	& 	& ( ( & &( ; ;  
%8,, %4 M M" 
 
@0H%% @0F  	<	< 	& 	&JJX&& JJc  :G ++G4CKK: : .:*t((	::s*   "G +H&=HH"H&!H""H&