
    0hh                        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rSSKrSSK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JrJrJrJrJrJrJrJrJrJrJrJr  SSKJrJrJrJ r J!r!  SSK"J#r#  SSK$r$SSK%r%SSK&J'r'J(r(   SSK)r)\$RV                  " \
RX                  \
RZ                  :H  =(       d    \
R\                  \
R^                  :g  S5      r0\(       d  \(       d  \(       d  \(       a  \$Rb                  " S5      e\" 5       SS	 j5       r2 " S
 S\$Rf                  \#5      r4 " S S\45      r5\0 " S S\45      5       r6\7S:X  a  \$Rp                  " 5         gg! \* a    Sr) Nf = f)z|
Test harness for the venv module.

Copyright (C) 2011-2012 Vinay Sajip.
Licensed to the PSF under a contributor agreement.
    N)captured_stdoutcaptured_stderr*skip_if_broken_multiprocessing_synchronizeverboserequires_subprocess
is_androidis_apple_mobileis_emscriptenis_wasirequires_venv_with_pipTEST_HOME_DIRrequires_resourcecopy_python_src_ignore)can_symlinkEnvironmentVarGuardrmtreeTESTFNFakePath)ExtraAssertions)patchMockz:cannot run venv.create from within a venv on this platformz&venv is not available on this platformc                    [         R                  " U [         R                  [         R                  0 [        R                  ESS0ES9nUR                  5       u  p4UR                  (       aX  [        (       a+  U(       a$  [        UR                  U=(       d    SS5      5        [         R                  " UR                  XU5      eU(       a$  UR                  US5      UR                  US5      4$ X44$ )N
PYTHONHOME )stdoutstderrenvutf-8backslashreplace)
subprocessPopenPIPEosenvironcommunicate
returncoder   printdecodeCalledProcessError)cmdencodingpouterrs        7/opt/python-3.13.8/usr/lib/python3.13/test/test_venv.pycheck_outputr0   1   s    ,rzz,<,	.A }}HC||7s#**X02DEF++LL#C) 	)JJx!34JJx!34
 	
 8O    c                   P    \ rS rSrSrSrS rS rSS.S jrS	 r	S
 r
SS.S jrSrg)BaseTestD   zBase class for venv tests.i  c                 d   [         R                  R                  [        R                  " 5       5      U l        [         R                  S:X  a  SU l        SU l        SU l	        O-SU l        SS[        R                  " 5        34U l        SU l	        [        R                  n[         R                  R                  U5      S	   U l        [        R                   S
:X  aP  [         R                  R#                  U5      (       a,  [         R                  R%                  U5      (       d  SU l        g SU l        g )NntScriptsLibIncludebinlibpythonincludewin32TF)r#   pathrealpathtempfilemkdtempenv_dirnamebindirr<   r>   	sysconfig_get_python_version_abisys_base_executablesplitexeplatformlexistsexistscannot_link_exe)self
executables     r/   setUpBaseTest.setUpH   s    ww''(8(8(:;77d?#DKDH$DLDK	(I(I(K'LMNDH$DL))
77==,R0LLG#
++GGNN:..#'D #(D r1   c                 .    [        U R                  5        g N)r   rE   rR   s    r/   tearDownBaseTest.tearDown[   s    t||r1   Freal_env_dirc                    U(       a*  [         R                  R                  U R                  5      nOU R                  n[         R                  R	                  X R
                  U R                  5      $ rW   )r#   rA   rB   rE   joinrG   rM   )rR   r\   rE   s      r/   envpyBaseTest.envpy^   sC    gg&&t||4GllGww||G[[$((;;r1   c                     [        5        n[        5        nU" U0 UD6  S S S 5        S S S 5        WR                  5       WR                  5       4$ ! , (       d  f       N6= f! , (       d  f       N?= frW   )r   r   getvalue)rR   funcargskwargsoutputerrors         r/   run_with_captureBaseTest.run_with_capturee   sV    & "ed%f% #   %.."222 #" s!   A 	AA 
A	A  
A.c                 X    [         R                  R                  " U R                  /UQ76 $ rW   )r#   rA   r^   rE   rR   rd   s     r/   get_env_fileBaseTest.get_env_filek   s    ww||DLL0400r1   r   r+   c                    [        U R                  " U6 SUS9 nUR                  5       nS S S 5        U$ ! , (       d  f       W$ = f)Nrrn   )openrl   read)rR   r+   rd   fresults        r/   get_text_file_contentsBaseTest.get_text_file_contentsn   s@    $##T*C(CqVVXF D DCs	   4
A)rG   rQ   rE   rM   r>   r<   N)__name__
__module____qualname____firstlineno____doc__maxDiffrT   rY   r_   rh   rl   ru   __static_attributes__ r1   r/   r3   r3   D   s7    $G)& %* <31 6=  r1   r3   c            	       :   \ rS rSrSrS rS rS rS rS r	S r
S	 r\S
 5       r\S 5       r\\R                   " \" 5       S5      S 5       5       r\R(                  S:X  a  SrO,SSSSS\R,                  SS -  4SS\R,                  SS -  S44rS rS rS rS rS rS r\R                   " \" 5       S5      S 5       r\S 5       r\R                   " \" 5       S5      S  5       r\R@                  " \!RD                  S!:H  S"5      S# 5       r#\R@                  " \!RD                  S!:H  S"5      S$ 5       r$\R                   " \!RD                  S!:H  S%5      S& 5       r%\R                   " \!RD                  S!:H  S%5      S' 5       r&\R                   " \!RD                  S!:H  =(       a    \" 5       S(5      S) 5       r'\S* 5       r(\S+ 5       r)\R@                  " \!RD                  S!:H  S,5      S- 5       r*\R                   " \R(                  S.:H  S/5      S0 5       r+S1 r,\R@                  " \!RD                  S!:H  S,5      \S2 5       5       r-\S3 5       r.\S4 5       r/\S5 5       r0\S6 5       r1\S7 5       r2\S8 5       r3S9 r4\\R                   " \!RD                  S!:H  S%5      S: 5       5       r5S;r6g)<	BasicTests   zTest venv module functionality.c                 ~    U R                   " U6 nU R                  [        R                  R	                  U5      5        g rW   )rl   
assertTruer#   rA   isdir)rR   rd   fns      r/   r   BasicTest.isdirv   s+    %b)*r1   c                     [        U R                  5        U R                  [        R                  U R                  5        U R                  5         g)zA
Test the create function with default arguments and a str path.
N)r   rE   rh   venvcreate_check_output_of_default_createrX   s    r/   test_defaults_with_str_path%BasicTest.test_defaults_with_str_pathz   s4     	t||dkk4<<8,,.r1   c                     [        U R                  5        U R                  [        R                  [        U R                  5      5        U R                  5         g)zG
Test the create function with default arguments and a path-like path.
N)r   rE   rh   r   r   r   r   rX   s    r/   test_defaults_with_pathlike%BasicTest.test_defaults_with_pathlike   s9     	t||dkk8DLL+AB,,.r1   c                 v   U R                  U R                  5        U R                  U R                  5        U R                   " U R                  6   U R	                  S5      n[
        R                  " S5      S:H  =(       a-    [        R                  S:H  =(       a    [        R                  S:g  nU(       a/  U R                  [        R                  R                  U5      5        O.U R                  [        R                  R                  U5      5        U R!                  S5      n[        R"                  n[        R                  R%                  U5      nU R'                  SU-  U5        U R'                  S[        R                  R)                  [        R*                  5      -  U5        [        R                  S	:X  a  S
OSnS[        R*                   SU SU R,                   3nU R'                  Xs5        U R	                  U R                  U R.                  5      n[        R                  R                  U5      (       dK  U R	                  U R                  5      n	[1        SU	-  5        [1        S[        R2                  " U	5      -  5        U R                  [        R                  R                  U5      SU-  5        g )Nlib64P   posixdarwin
pyvenv.cfgz	home = %szexecutable = %sr6   r   z	 --copiesz
command = z -m venvz* --without-pip --without-scm-ignore-files Contents of %r:    %rFile %r should exist.)r   rG   r>   r<   rl   structcalcsizer#   rF   rJ   rN   r   rA   islinkassertFalserP   ru   rK   dirnameassertInrB   rS   rE   rM   r'   listdir)
rR   r,   
conditionsdatarS   rA   copiesr*   r   bds
             r/   r   )BasicTest._check_output_of_default_create   s   

4;;

4<< 

DHHg&s+q0 1rww'7I 1||x/ 	OOBGGNN1-.RWW^^A./**<8))
wwz*kD($/'gg&&s~~678<	>ww}+CNN+8F8 <--1\\N<c t{{DHH5ww~~b!!""4;;/B#b()(RZZ^+,r*,Cb,HIr1   c                    SSSSSSSSS	S
[        5       4/	nU GH  u  p#nU R                  X#US9   [        U R                  5        U(       d  0 nOX40n[        R
                  " S0 UD6n[        5       Ul        [        5       Ul        U R                  UR                  U R                  5        U R                  S5      nU(       a  UR                  S5      (       a  S H  nU R                  USU 35        M     O0[        R                  S:X  a  US:X  a  OU R!                  USU 35        S S S 5        GM     g ! , (       d  f       GM/  = f)N)NNN)z--copiessymlinksF)--without-pipwith_pipF)--system-site-packagessystem_site_packagesT)--clearclearT)	--upgradeupgradeT)--upgrade-depsupgrade_depsT)z--prompt="foobar"promptfoobar--without-scm-ignore-filesscm_ignore_files)optattrvaluer   git)r   r   r   r   z--promptzcommand = .* r6   r   r~   )	frozensetsubTestr   rE   r   
EnvBuilderr   upgrade_dependencies
_setup_piprh   r   ru   endswithassertNotRegexr#   rF   assertRegex)rR   optionsr   r   r   re   br   s           r/   test_config_file_command_key&BasicTest.test_config_file_command_key   s'   +0D&*45)+=y{K

 !(Cu#>t||$F"]FOO-f-)-&#v%%ahh=22<@s||E22 >++D]3%2HI > WWd]tZ'7$$TmC5+AB% ?> !(>>s   C:D88
E	c                    [         R                  R                  U R                  5      S   n[	        U R                  5        [
        R                  " 5       nU R                  UR                  U R                  5        UR                  U R                  5      nU R                  S5      nU R                  UR                  U5        U R                  SU5        [	        U R                  5        [
        R                  " SS9nU R                  UR                  U R                  5        UR                  U R                  5      nU R                  S5      nU R                  UR                  S5        U R                  SU5        [	        U R                  5        [
        R                  " SS9n[         R                  R                  [         R                   " 5       5      nU R                  UR                  U R                  5        UR                  U R                  5      nU R                  S5      nU R                  UR                  U5        U R                  SU-  U5        g )	N   r   z	prompt = z	My prompt)r   zprompt = 'My prompt'
.zprompt = '%s'
)r#   rA   rL   rE   r   r   r   rh   r   ensure_directoriesru   assertEqualr   assertNotInr   basenamegetcwd)rR   env_namebuildercontextr   cwds         r/   test_promptBasicTest.test_prompt   s   77==.q1t||//#gnndll;,,T\\:**<82d+t||//5gnndll;,,T\\:**<85.5t||//-ggryy{+gnndll;,,T\\:**<8-'#-t4r1   c                   ^ ^ [         R                  " 5       nSn[        R                  R	                  [
        R                  5      S   n[
        R                  S:X  aZ  Sn[        R                  R                  [        R                  R                  U5      S   5      R                  S5      (       a  SnOSn[        R                  " 5        n[        R                  R                  [        R                  R                  XBU5      5      m[
        R                  S:X  a<  [        R                  R                  [        R                  R                  T5      5      mUU 4S	 jnUR                  U5      n[!        S
U5         UR#                  U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr;   r   r@   r7   r   _dzpython_d.exez
python.exec           	         > [         R                  R                  U S   5      U S'   TR                  U TSSSSS/5        g )Nr   -mpipinstallr   )r#   rA   normcaser   )r*   re   
expect_exerR   s     r/   pip_cmd_checker<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checker   sG    ))#a&1A  "!#
r1   zvenv.subprocess.check_output)r   r   r#   rA   rL   rJ   rS   rN   r   splitextr   rC   TemporaryDirectoryr^   rB   r   r   r   )rR   r   bin_path
python_exefake_env_dirr   fake_contextr   s   `      @r/   test_upgrade_dependencies#BasicTest.test_upgrade_dependencies   s4   //#WW]]3>>215
<<7" Hww 0 0 <Q ?@II$OO+
)
((*l))\Z@J ||w&WW--bgg.>.>z.JK
 #55lCL5G,,\: H- +*, HG- +*s%   B2F3?F"F3"
F0	,F33
Gc                    [        U R                  5        U R                  [        R                  U R                  5        U R                  5       SS/nSU R                  4SU R                  4S[        R                  4S[        R                  44 Hq  u  p#SU-  US'   [        U5      u  pEU R                  [        R                  " UR                  5       R                  5       5      [        R                  " U5      U5        Ms     g)	z.
Test that the prefix values are as expected.
-cNprefixexec_prefixbase_prefixbase_exec_prefixzimport sys; print(sys.%s)   )r   rE   rh   r   r   r_   rJ   r   r   r0   r   pathlibPathstripr(   )rR   r*   r   expectedr-   r.   s         r/   test_prefixesBasicTest.test_prefixes  s     	t||dkk4<<8zz|T4(t||$DLL)COO,!5!56	!8F
 169CF#C(HCW\\#))+*<*<*>?$\\(3V=!8r1   c                 r   [        U R                  5        U R                  [        R                  U R                  SS9  U R                  5       SS/nSSS[        [        R                  " 5       5      4S[        R                  " 5       4S	[        R                  " 5       4S
[        [        R                  " S5      5      44 HS  u  p#U R                  U5         SU-  US'   [        USS9u  pEU R                  UR                  5       X55        SSS5        MU     SU R                  5       4S[         R"                  44 HT  u  pcU R                  U5         SU S3US'   [        USS9u  pEU R                  UR                  5       X55        SSS5        MV     g! , (       d  f       M  = f! , (       d  f       Mz  = f)B
Test that the sysconfig functions work in a virtual environment.
Fr   r   Nzget_preferred_scheme("prefix")r   zget_default_scheme()r   is_python_build()get_makefile_filename()get_config_h_filename()!get_config_var("Py_GIL_DISABLED")Py_GIL_DISABLED%import sysconfig; print(sysconfig.%s)r   r   rn   rS   rK   import sys; print(sys.))r   rE   rh   r   r   r_   strrH   is_python_buildget_makefile_filenameget_config_h_filenameget_config_varr   r0   r   r   rJ   rK   rR   r*   callr   r-   r.   r   s          r/   test_sysconfigBasicTest.test_sysconfig  s   
 	t||dkk4<<%Hzz|T4( 7, #i&?&?&A"BC&	(G(G(IJ&	(G(G(IJ0))*;<=?	@ND d#@4GA'g>  h< $#	@ 4::<(  !5!56	
ND d#1$q9A'g>  h< $#
	 $# $#s   5F6F'
F$	'
F6	zNeeds symlinksc                 P   [        U R                  5        U R                  [        R                  U R                  SS9  U R                  5       SS/nSSS[        [        R                  " 5       5      4S[        R                  " 5       4S	[        R                  " 5       4S
[        [        R                  " S5      5      44 HS  u  p#U R                  U5         SU-  US'   [        USS9u  pEU R                  UR                  5       X55        SSS5        MU     SU R                  5       44 HT  u  pcU R                  U5         SU S3US'   [        USS9u  pEU R                  UR                  5       X55        SSS5        MV     g! , (       d  f       M  = f! , (       d  f       Mz  = f)r   Tr   r   Nr   r   r   r   r   r   r   r   r   r   rn   rS   r   r   )r   rE   rh   r   r   r_   r   rH   r  r  r  r  r   r0   r   r   r  s          r/   test_sysconfig_symlinks!BasicTest.test_sysconfig_symlinks;  so    	t||dkk4<<$Gzz|T4( 7, #i&?&?&A"BC&	(G(G(IJ&	(G(G(IJ0))*;<=?	@ND d#@4GA'g>  h< $#	@ 4::<(
ND d#1$q9A'g>  h< $#
	 $# $#s   5F6F
F	
F%	r@   ))r7   )r:   r8   )r9   site-packages)r;   )r>   )r<   r<   zpython%d.%dNr   r  c                 F   U H  n[         R                  R                  " U R                  /UQ76 n[         R                  " U5        [         R                  R                  XB5      n[        US5       nUR                  S5        SSS5        M     g! , (       d  f       M  = f)zV
Create some files in the environment which are unrelated
to the virtual environment.
wb   Still here?N)r#   rA   r^   rE   mkdirrq   write)rR   pathsfilenamesubdirsdr   rs   s          r/   create_contentsBasicTest.create_contentsn  sl    
 GT\\4G4AHHQKa*Bb$1'  	   s   2B
B 	c                 &   U R                  U R                  S5        [        R                  " U R                  5        U R                   H  n[
        R                  R                  " U R                  /US-   Q76 nU R                  [
        R                  R                  U5      5        [        US5       nU R                  UR                  5       S5        SSS5        M     [        R                  " SS9nUR                  U R                  5        U R                   H_  n[
        R                  R                  " U R                  /US-   Q76 nU R                  [
        R                  R                  U5      5        Ma     g! , (       d  f       GMG  = f)z5
Test creating environment in an existing directory.
foo)r  rbr  NTr   )r  ENV_SUBDIRSr   r   rE   r#   rA   r^   r   rP   rq   r   rr   r   r   )rR   r  r   rs   r   s        r/   test_overwrite_existing!BasicTest.test_overwrite_existingz  s    	T--u5DLL!''GdllBg.@BBOOBGGNN2./b$1  >:   ( //-t||$''GdllBg.@BBRWW^^B/0 (  s   4!F  
F	c                    [         R                  " U5       H  n[         R                  R                  X5      n[         R                  R	                  U5      (       d$  [         R                  R                  U5      (       a  [         R                  " U5        M  [         R                  R                  U5      (       d  M  [        U5        M     g rW   )	r#   r   rA   r^   r   isfileremover   r   )rR   rA   r   s      r/   clear_directoryBasicTest.clear_directory  sq    **T"Bd'Bww~~b!!RWW^^B%7%7		"r""r
 #r1   c                    U R                   S S  H  n[        R                  R                  " U R                  /UQ76 n[        US5       nUR                  S5        S S S 5        U R                  [        [        4[        R                  U R                  5        U R                  U R                  5        M     g ! , (       d  f       Nc= f)N   r  r1   )r  r#   rA   r^   rE   rq   r  assertRaises
ValueErrorOSErrorr   r   r"  )rR   r  r   rs   s       r/   test_unoverwritable_fails#BasicTest.test_unoverwritable_fails  s    %%bq)Edll3U3Bb$1  z73T[[$,,O  . *s   
B99
C	c                    S GHT  n[         R                  " US9nU R                  UR                  U R                  5        U R                  U R                  5        U R                  U R                  5        U R
                  " U R                  6   U R                  U R                  U R                  5      n[        R                  R                  U5      (       dK  U R                  U R                  5      n[        SU-  5        [        S[        R                  " U5      -  5        U R!                  [        R                  R                  U5      SU-  5        GMW     g)z3
Test upgrading an existing environment directory.
FT)r   r   r   r   N)r   r   rh   r   rE   r   rG   r>   r<   rl   rM   r#   rA   rP   r'   r   r   )rR   r   r   r   r   s        r/   test_upgradeBasicTest.test_upgrade  s     %Goog6G!!'..$,,?JJt{{#JJt||$JJ!""4;;9B77>>"%%&&t{{3'",-hB/0OOBGGNN2.0G"0LM %r1   c                     S H[  u  p[         R                  " SUS9nUR                  U R                  5        U R	                  S5      nU R                  SU-  U5        M]     g)z*
Test isolation from system site-packages
))Ttrue)FfalseT)r   r   r   z"include-system-site-packages = %s
N)r   r   r   rE   ru   r   )rR   sspsr   r   s        r/   test_isolationBasicTest.test_isolation  sT     9FCooDsKGNN4<<(..|<DMM?!CTJ	 9r1   c                    S H  n[         R                  " SUS9nUR                  U R                  5        U R	                  U R
                  U R                  5      nU(       d  Mb  U R                  (       a0  U R                  [        R                  R                  U5      5        M  U R                  [        R                  R                  U5      5        M     g)z#
Test symlinking works as expected
r,  Tr   r   N)r   r   r   rE   rl   rG   rM   rQ   r   r#   rA   r   r   )rR   uslr   r   s       r/   test_symlinkingBasicTest.test_symlinking  s    
 !CooD3?GNN4<<(""4;;9B s'' $$RWW^^B%78OOBGGNN2$67 !r1   c                    [        U R                  5        U R                  [        R                  U R                  5        U R                  SS9n[        USS/5      u  p#U R                  UR                  5       UR                  5       5        g)4
Test that the sys.executable value is as expected.
Tr[   r   !import sys; print(sys.executable)N)
r   rE   rh   r   r   r_   r0   r   r   encode)rR   r_   r-   r.   s       r/   test_executableBasicTest.test_executable  sl    
 	t||dkk4<<8


-/!1 2elln5r1   c                 (   [        U R                  5        [        R                  " SSS9nUR	                  U R                  5        U R                  SS9n[        USS/5      u  p4U R                  UR                  5       UR                  5       5        g)r<  Tr7  r[   r   r=  N)
r   rE   r   r   r   r_   r0   r   r   r>  )rR   r   r_   r-   r.   s        r/   test_executable_symlinks"BasicTest.test_executable_symlinks  st    
 	t||//t<t||$


-/!1 2elln5r1   r6   z&contains invalid characters on Windowsc                 p   [        U R                  5        [        R                  " S5      nUc  U R	                  S5        Sn[
        R                  R                  [
        R                  R                  U R                  5      U5      n[        R                  " SS9nUR                  U5        [
        R                  R                  X0R                  S5      n[
        R                  R                  U R                  S5      n[        US	5       nUR                  S
[        R                   " U5       S35        SSS5        [#        X/5      u  pUR%                  5       n
U R'                  UR)                  5       U
S   ;   5        U R+                  U
S   UR)                  5       5        g! , (       d  f       Nu= f)z;
Test that the template strings are quoted properly (bash)
bashNbash required for this test
"';&&$e|'"Tr  activateztest_special_chars.shwsource r
python -c 'import sys; print(sys.executable)'
python -c 'import os; print(os.environ["VIRTUAL_ENV"])'
deactivate
r   r   r   rE   shutilwhichskipTestr#   rA   r^   rB   r   r   r   rG   rq   r  shlexquoter0   
splitlinesr   r>  assertEndsWith)rR   rE  r   rE   r   rH  test_scriptrs   r-   r.   liness              r/   test_special_chars_bash!BasicTest.test_special_chars_bash  s;   
 	t||||F#<MM78!'',,rww//=xH//-w77<<jAggll4<<1HI+s#qGGgekk(34 5# # $ $
   34 )U1X56E!Hhoo&78 $#s   *F''
F5c                    [        U R                  5        [        R                  " S5      =(       d    [        R                  " S5      nUc  U R	                  S5        Sn[
        R                  R                  [
        R                  R                  U R                  5      U5      n[        R                  " SS9nUR                  U5        [
        R                  R                  X0R                  S5      n[
        R                  R                  U R                  S	5      n[        US
5       nUR                  S[        R                   " U5       S35        SSS5        [#        X/5      u  pUR%                  5       n
U R'                  UR)                  5       U
S   ;   5        U R+                  U
S   UR)                  5       5        g! , (       d  f       Nu= f)z:
Test that the template strings are quoted properly (csh)
tcshcshNzcsh required for this testrG  Tr  zactivate.cshztest_special_chars.cshrI  rJ  rK  r   r   rL  )rR   rZ  r   rE   r   rH  rT  rs   r-   r.   rU  s              r/   test_special_chars_csh BasicTest.test_special_chars_csh  sI   
 	t||ll6"9fll5&9;MM67!'',,rww//=xH//-w77<<nEggll4<<1IJ+s#qGGgekk(34 5# # $ $
   23 )U1X56E!Hhoo&78 $#s   +*G
Gzonly relevant on Windowsc           
      (   [        U R                  5        Sn[        R                  R	                  [        R                  R                  U R                  5      U5      n[        R                  " SS9nUR                  U5        [        R                  R	                  X R                  S5      n[        R                  R	                  U R                  S5      n[        US5       nUR                  SU SU R                   S	U R                   S
35        SSS5        [        U/5      u  pxUR                  5       n	U R                  UR!                  5       U	S   ;   5        U R#                  U	S   UR!                  5       5        g! , (       d  f       Nu= f)z?
Test that the template strings are quoted properly on Windows
z'&&^$eTr  activate.batztest_special_chars.batrI  z@echo off
"z" & z* -c "import sys; print(sys.executable)" & z> -c "import os; print(os.environ['VIRTUAL_ENV'])" & deactivateNr   r   )r   rE   r#   rA   r^   rB   r   r   r   rG   rq   r  rM   r0   rR  r   r>  rS  )
rR   r   rE   r   rH  
test_batchrs   r-   r.   rU  s
             r/   test_special_chars_windows$BasicTest.test_special_chars_windows"  s+   
 	t||'',,rww//=xH//-w77<<nEWW\\$,,0HI
*c"aGG  zxxj Jxxj !!! " #  - )U1X56E!Hhoo&78 #"s   $0F
Fc                    [        U R                  5        [        R                  R	                  [        R                  R                  U R                  5      S5      n[        R                  " SS9nUR                  U5        [        R                  R	                  XR                  S5      n[        USU R                  SS/SS	9u  pEU R                  UR                  5       S
5        g)z 
Test handling of Unicode paths
u   ϼўТλФЙTr  r^  &r   zprint(0)oemrn   0N)r   rE   r#   rA   r^   rB   r   r   r   rG   r0   rM   r   r   )rR   rE   r   rH  r-   r.   s         r/   test_unicode_in_batch_file$BasicTest.test_unicode_in_batch_file9  s    
 	t||'',,rww//=~N//-w77<<nEsDHHdJ7
 	c*r1   zsymlinks on Windowsc                    [        U R                  5        [        R                  R	                  [        R                  R                  U R                  5      S5      n[        S5       n[        5       Ul        [        R                  " SSS9nU R                  UR                  U5      u  pESnU R                  USU SU 35        SSS5        g! , (       d  f       g= f)	z.
Test handling of failed symlinks on Windows.
r   z
os.symlinkTr7  z%'[A-Z]:\\\\(?:[^\\\\]+\\\\)*[^\\\\]+'zUnable to symlink z to N)r   rE   r#   rA   r^   rB   r   r(  side_effectr   r   rh   r   r   )rR   rE   mock_symlinkr   _r.   filepath_regexs          r/   test_failed_symlinkBasicTest.test_failed_symlinkI  s     	t||'',,rww//=vF< L'.yL$ooD4@G**7>>7CFAENS%77GtNK["\] !  s   (AC
Cc                 ,   [        5         [        U R                  5        U R                  [        R
                  U R                  5        [        U R                  SS9SS/5      u  pU R                  UR                  5       SR                  5       5        g)z1
Test that the multiprocessing is able to spawn.
Tr[   r   zrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()r=   N)r   r   rE   rh   r   r   r0   r_   r   r   r>  rR   r-   r.   s      r/   test_multiprocessingBasicTest.test_multiprocessingX  sr     	34t||dkk4<<8!>!  !
 	hoo&78r1   c                 *   [        5         [        U R                  5        U R                  [        R
                  U R                  5        [        R                  R                  [        S5      n[        R                  " U R                  SS9SU/5        g)z7
Test that the multiprocessing is able to spawn itself
z_test_venv_multiprocessing.pyTr[   -IN)r   r   rE   rh   r   r   r#   rA   r^   r   r    
check_callr_   )rR   scripts     r/   test_multiprocessing_recursion(BasicTest.test_multiprocessing_recursionk  sc    
 	34t||dkk4<<8m-LMtzztz<dFKLr1   znot relevant on Windowsc                    [         R                  " S5      nUc  U R                  S5        [        U R                  5        [
        R                  " SS9nUR                  U R                  5        [        R                  R                  U R                  U R                  S5      n[        R                  R                  U R                  S5      n[        US5       nUR                  SU S	35        S S S 5        [        X/5      u  pgU R                  US
R!                  5       5        U R                  US
R!                  5       5        g ! , (       d  f       N]= f)NrE  rF  Tr  rH  ztest_strict.shrI  zset -euo pipefail
source z
deactivate
r   )rM  rN  rO  r   rE   r   r   r   r#   rA   r^   rG   rq   r  r0   r   r>  )rR   rE  r   rH  rT  rs   r-   r.   s           r/   %test_deactivate_with_strict_bash_opts/BasicTest.test_deactivate_with_strict_bash_optsw  s    ||F#<MM78t||//-t||$77<<dkk:Fggll4<<1AB+s#qGG &Z (## $ $   34biik*biik* $#s   E
Er   zonly relevant on macOSc                 $   [        U R                  5        [        R                  " 5       nUR	                  U R                  5        [        U R                  SS9SS/5      u  p#U R                  UR                  5       SR                  5       5        g )NTr[   r   z5import os; print("__PYVENV_LAUNCHER__" in os.environ)False)
r   rE   r   r   r   r0   r_   r   r   r>  )rR   r   r-   r.   s       r/   test_macos_envBasicTest.test_macos_env  sl    t||//#t||$!>C!E Fgnn&67r1   c                    [        U R                  5        U R                  [        R                  -   nU R	                  [
        [        R                  U5        U R	                  [
        [        R                  [        U5      5        g)zV
Test that venv creation fails when the target directory contains
the path separator.
N)	r   rE   r#   pathsepr&  r'  r   r   r   )rR   bad_itempaths     r/   test_pathsep_errorBasicTest.test_pathsep_error  sS    
 	t||||bjj0*dkk<@*dkk8L3IJr1   c           	      
   [        U R                  5        [        R                  n[        R
                  R                  [        R                  " 5       5      nU R                  [         U5        [        R
                  R                  X R                  5      n[        R                  " U5        [        R                  " [        R                  U5        [        R
                  R                  X!U R                   S   5      n[        R"                  " U5        [        R
                  R                  US5      n[$        R&                  " S5      (       a  SOSnS[        R(                  R*                   [        R(                  R,                   U 3n[        R
                  R                  UUU5      n/ n	[        R
                   GH  n
U
R/                  S5      (       a\  [        R
                  R1                  U
5      (       a6  [        R2                  " U
[        R
                  R                  X!5      5        Mt  Mv  [        R
                  R1                  [        R
                  R                  U
S5      5      (       a  [        R4                  " U
5      n[7        X5      nU H  nX;   a  M
  US:X  a  M  [        R
                  R                  X5      n[        R
                  R1                  U5      (       a  [        R8                  " X5        Mm  [        R
                  R;                  U5      (       d  M  [        R<                  " U[        R
                  R                  XM5      [6        S	9  M     GM  U	R?                  U
5        GM     [        R
                  R                  X R                  U R@                  5      S
SSSU R                  /n[        RB                  R                  U	5      n[$        R&                  " S5      nU(       a  [$        RD                  " 5       (       aJ  [        R
                  RG                  [        R
                  RI                  [        R                  5      5      n[        RJ                  S:X  a  SnOSnSUUU0n[        RL                  RO                  S5      =n(       a  UUS'   [P        RR                  " UUS9  U RU                  5       SSS/n[W        U5      u  nnU RY                  UR[                  5       U;   5        g)zZ
Test that when create venv from non-installed python, the zip path
value is as expected.
r   zos.pyr   tr   r=   z.zipr  )ignorer   r   r   r   LIBDIRr   DYLD_LIBRARY_PATHLD_LIBRARY_PATH
PYTHONPATHASAN_OPTIONS)r   z-Sr   zimport sys; print(sys.path)N).r   rE   rJ   
platlibdirr#   rA   rB   rC   rD   
addCleanupr^   rG   r  rM  copy2rS   r<   makedirsrH   r  version_infomajorminorr   r   copyfiler   r   copyr   copytreeappendrM   r  r  abspathr   rN   r$   getr    ru  r_   r0   r   r>  )rR   r  non_installed_dirrG   libdirlandmark
abi_thread
stdlib_zipzip_landmark'additional_pythonpath_for_non_installedeachpathnamesignored_namesrF   r   r*   
pythonpathld_library_pathld_library_path_env	child_envasan_optionsr-   r.   s                          r/   %test_zippath_from_non_installed_posix/BasicTest.test_zippath_from_non_installed_posix  s    	t|| ^^
GG,,X-=-=-?@ 12/=
S^^V,/TXXa[I
F77<<0%445FGGSR
c..445c6F6F6L6L5Mj\Z
ww||$5$.$.0 35/ H  ((77>>(++OO %6CE , Xw ?@@

8, 6x G!D, . h5Bww~~b))B/r**BGGLL,F/EG " 8>>+ !. ww||-{{DHHE+|| ZZ__35

 $228<)";";"="= ggoobggoocnn.MNO<<8#"5"3j#_
	 ::>>.99<9(4In%cy1 zz|T4)FG$S++-45r1   c                 t   [         R                  " U R                  5      n[        U5        U R                  tu  p#X-  S-  n[
        R                  " U5        [        US5       n[        US5       H+  u  pgSU 3nU R                  UR                  S5      U5        M-     SSS5        g! , (       d  f       g= f)z
Test that the `activate` shell script contains no CR LF.
This is relevant for Cygwin, as the Windows build might have
converted line endings accidentally.
rH  r  r   zCR LF found in line s   
N)r   r   rE   r   r  r   r   rq   	enumerater   r   )	rR   venv_dirscripts_dirrk  script_pathrv  ilineerror_messages	            r/   .test_activate_shell_script_has_no_dos_newlines8BasicTest.test_activate_shell_script_has_no_dos_newlines  s     <<-x"..+,z9H+t$$VQ/"6qc :  w!7G 0 %$$s   $<B))
B7c                     U R                  [        R                  U R                  S1S9  U R	                  S5      R                  5       nU R                  SU5        g)z~
        Test that a .gitignore file is created when "git" is specified.
        The file should contain a `*
` line.
        r   r   
.gitignore*N)rh   r   r   rE   ru   rR  r   )rR   
file_liness     r/   test_scm_ignore_files_git#BasicTest.test_scm_ignore_files_git  sO     	dkk4<<05w 	 	800>IIK
c:&r1   c                 N  ^^ SmSm " UU4S jS[         R                  5      nU" SS1S9nU R                  UR                  U R                  5        U R                  S5      R                  5       nU R                  S	U5        U R                  T5      nU R                  UT5        g
)z=
Test that ``scm_ignore_files`` can work with multiple SCMs.
z
.bzrignorez# For Bazaar.
*
c                   $   > \ rS rSrU U4S jrSrg)FBasicTest.test_create_scm_ignore_files_multiple.<locals>.BzrEnvBuilderi  c                    > [         R                  R                  UR                  T5      n[	        USSS9 nUR                  T5        S S S 5        g ! , (       d  f       g = f)NrI  r   rn   )r#   rA   r^   rE   rq   r  )rR   r   gitignore_pathfilebzrignore_namecontentss       r/   create_bzr_ignore_file]BasicTest.test_create_scm_ignore_files_multiple.<locals>.BzrEnvBuilder.create_bzr_ignore_file  sB    !#goo~!N.#@DJJx( A@@s   A
A r~   N)rw   rx   ry   rz   r  r}   )r  r  s   r/   BzrEnvBuilderr    s    ) )r1   r  r   bzrr  r  r  N)	r   r   rh   r   rE   ru   rR  r   r   )rR   r  r   gitignore_lines	bzrignorer  r  s        @@r/   %test_create_scm_ignore_files_multiple/BasicTest.test_create_scm_ignore_files_multiple  s    
 &'	) 	)DOO 	)  %@gnndll;55lCNNPc?+//?	H-r1   c                    U R                  [        R                  U R                  5        U R	                  [
        5         U R                  S5        SSS5        U R                  SU R                  S5      5        g! , (       d  f       N0= f)zS
Test that no default ignore files are created when ``scm_ignore_files``
is empty.
r  Nr   r   )rh   r   r   rE   r&  FileNotFoundErrorru   r   rX   s    r/   "test_create_scm_ignore_files_empty,BasicTest.test_create_scm_ignore_files_empty'  sg     	dkk4<<801''5 2 	211,?	A 21s    A<<
B
c                     U R                  [        R                  SU R                  /5        U R	                  S5      R                  5       nU R                  SU5        g)zH
Test that default SCM ignore files are created by default via the CLI.
r   r  r  N)rh   r   mainrE   ru   rR  r   )rR   r  s     r/   test_cli_with_scm_ignore_files(BasicTest.test_cli_with_scm_ignore_files5  sH    
 	dii/4<<)HI55lCNNPc?+r1   c                     SSU R                   /nU R                  [        R                  U5        U R	                  [
        5         U R                  S5        SSS5        g! , (       d  f       g= f)zK
Test that ``--without-scm-ignore-files`` doesn't create SCM ignore files.
r   r   r  N)rE   rh   r   r  r&  r  ru   rk   s     r/   !test_cli_without_scm_ignore_files+BasicTest.test_cli_without_scm_ignore_files?  sR    
  !=t||Ldii.01''5 211s   A  
A.c                    [         R                  R                  n[        R                  S:X  a  S[
        [
        4S[
        R                  " 5       [
        R                  " 5       4/nSS Kn[        R                  " S5      nU(       a+  / UQSXD4PSUR                  U5      UR                  U5      4PnO8S[
        [
        4S[
        R                  " 5       [
        R                  " 5       4/nU H[  u  pVnU R                  U SU 35         U(       a  U R                  U" Xg5      5        OU R                  U" Xg5      5        S S S 5        M]     g ! , (       d  f       Mo  = f)Nr@   Tr   ProgramFilesF-)r   r   
_same_pathrJ   rN   r   lowerupper_winapir#   getenvGetShortPathNameGetLongPathNamer   r   r   )rR   	same_pathtestsr  	progfilesrp   path1path2s           r/   test_venv_same_pathBasicTest.test_venv_same_pathJ  s'   OO..	<<7" vv&v||~v||~6E 		.1I90 733I>@W@WXa@bc vv&7E  %OAeq01OOIe$;<$$Yu%<=	 21  %11s   
7E
E	c                    [        U R                  5        [        R                  " U R                  5        U R                  nSU;   a  SU;  a  UR                  SS5      n[        R                  R                  U R                  U R                  U5      n [        R                  " USSU-  /5        g! [        R                   a    U R                  SU-  5         gf = f)z1
Test that the GUI launcher runs the GUI python.
r=   pythonwr   z6import sys; assert sys._base_executable.endswith('%s')z venvwlauncher.exe did not run %sN)r   rE   r   r   rM   replacer#   rA   r^   rG   r    ru  r)   fail)rR   exenameenvpyws      r/   test_venvwlauncherBasicTest.test_venvwlauncheri  s     	t||DLL!((wyG';ooh	:GdllDKKA	D!!64 2=?F2G #H I,, 	DII87BC	Ds   B3 3(CCr~   )7rw   rx   ry   rz   r{   r   r   r   r   r   r   r   requireVenvCreater   r  unittest
skipUnlessr   r
  rJ   rN   r  r  r  r  r"  r)  r-  r4  r9  r?  rB  skipIfr#   rF   rV  r[  r`  rf  rm  rq  rw  rz  r~  r  r  r  r  r  r  r  r  r  r  r}   r~   r1   r/   r   r   s   s   )+//J:CB58!;F = =$ = =@ (89= : =B ||w
 MC$4$4Ra$889MC$4$4Ra$88/J

(1$/N*K (898 :8. 	6 	6 (89
6 :
6 __RWW_&NO9 P92 __RWW_&NO9 P92 D*DE9 F9, D*DE+ F+ D:[].0^0^ 9 9$ 	M 	M __RWW_&?@+ A+$ 13KL8 M8K __RWW_&?@R6  AR6h H H  ' ' . ., A A , , 6 6>> D*DED F Dr1   r   c                       \ rS rSrSrS rS rS rS rS r	\
R                  S 5       r\" 5       \" S	5      S
 5       5       rSrg)EnsurePipTesti}  z%Test venv module installation of pip.c                     [        U R                  SS9SS/5      u  pUR                  S5      nU R                  US5        UR                  S5      nU R                  UR	                  5       S5        g )NTr[   r   z1try:
 import pip
except ImportError:
 print("OK")latin-1r   OK)r0   r_   r(   r   r   rp  s      r/   assert_pip_not_installed&EnsurePipTest.assert_pip_not_installed  sk    !>B!D E jj#b!jj#d+r1   c                     [        U R                  5        U R                  [        R                  U R                  5        U R                  5         g rW   r   rE   rh   r   r   r  rX   s    r/   test_no_pip_by_default$EnsurePipTest.test_no_pip_by_default  s2    t||dkk4<<8%%'r1   c                     [        U R                  5        U R                  [        R                  U R                  SS9  U R                  5         g )NF)r   r  rX   s    r/   test_explicit_no_pip"EnsurePipTest.test_explicit_no_pip  s7    t||dkk4<<%H%%'r1   c                 $   [        [        R                  S5       nU R                  UR	                  5       S5        S S S 5        U R                  [        R                  R                  [        R                  5      5        g ! , (       d  f       NK= f)Nr  r1   )rq   r#   devnullr   rr   r   rA   rP   )rR   rs   s     r/   test_devnullEnsurePipTest.test_devnull  sW    
 "**d#qQVVXs+ $ 	rzz23 $#s   !B
Bc                    [        U R                  5        [        5        nSUS'   SUS'   [        R                  " 5        nX2S'   SnSnSnU4 H  u  px[
        R                  R                  X75      n	[
        R                  " U	5        [
        R                  R                  X5      n
[        U
S	5       nUR                  U5        S S S 5        M     U R                  5          U R                  [        R                  U R                  US
S9  S S S 5        S S S 5        S S S 5        [        U R!                  S
S9SSSSSSSS/	5      u  pUR#                  S5      nU R%                  US5        UR#                  S5      nSR'                  [(        R*                  " 5       5      nU R%                  US [-        U5       U5        [
        R.                  " U R                  5      R#                  S5      nU R1                  X5        [        5        nU R                  5          SUS'   [        U R!                  S
S9SSSSSSS/5      u  pS S S 5        S S S 5        UR#                  S5      n[2        R4                  " SSU[2        R6                  S9n SS KnU R%                  UR=                  5       S5        UR#                  S5      nU R1                  SU5        U(       d  U R?                  5         g g ! , (       d  f       GM  = f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN	= f! , (       d  f       N= f! , (       d  f       GN = f! [:         a(    [2        R4                  " SSU[2        R6                  S9n Nf = f)Nr  PYTHONWARNINGS1PIP_NO_INSTALLHOMEz[global]
no-install=1)r   zpip.ini)z.pipzpip.confrI  T)r   r   r[   z-Wzignore::DeprecationWarningzignore::ImportWarningrt  r   r   z	--versionr  r   zpip {}zensurepip._uninstallzl^(WARNING: )?The directory .* or its parent directory is not owned or is not writable by the current user.*$)flagsr   z<^WARNING: Disabling truststore since ssl support is missing$zSuccessfully uninstalled pip) r   rE   r   rC   r   r#   rA   r^   r  rq   r  nicer_errorrh   r   r   r0   r_   r(   r   format	ensurepipversionlenfsencoder   resub	MULTILINEsslImportErrorrstripr  )rR   r   envvarshome_dir
bad_configwin_locationposix_locationr   fnamedirpathfpathrs   r-   r.   expected_versionrE   r  s                    r/   do_test_with_pipEnsurePipTest.do_test_with_pip  s   t|| "g )1G$% ),G$% ,,.("*5
  2!5'5&7NG ggll8=GHHW%GGLL8EeS)Q
+ *)	 '8 %%'))$++t||?S37 * 9 (# / #H  !>1,dUK!) * jj#b!jj##??9+<+<+>?3c"2346FG++dll+229=g#
 !"g!!# -5()')F6140)2 3	 $ # jj# ff NOQ.	) 	r* jj#4c: $))+ $E *)
 ('# /. #"l $# #"0  	)&&N2<<)C	)s    L A3L3K'	L!+K:LLM(L0 MM '
K71	L:
L	L
L	L
L-0
L>	:M
M/NNc              #     #     Sv   g! [         R                   ag  nUR                  =(       d    SR                  SS9nUR                  =(       d    SR                  SS9nU R                  U SU SU 35         SnAgSnAff = f7f)z
Capture output from a failed subprocess for easier debugging.

The output this handler produces can be a little hard to read,
but at least it has all the details.
Nr1   r  )errorsz

**Subprocess Output**
z

**Subprocess Error**
)r    r)   rf   r(   r   r  )rR   excr-   r.   s       r/   r  EnsurePipTest.nicer_error  s     		,, 	::$,,I,>C::$,,I,>CII% **- /)),/ 	s+   B	 BBAA?:B?BBcpuc                 H    U R                  S5        U R                  S5        g )NFT)r!  rX   s    r/   test_with_pipEnsurePipTest.test_with_pip  s      	e$d#r1   r~   N)rw   rx   ry   rz   r{   r  r  r   r  r!  
contextlibcontextmanagerr  r   r   r)  r}   r~   r1   r/   r  r  }  s^    /,(
(
4^,@  $ u$  $r1   r  __main__rW   )9r{   r+  r  r#   os.pathr   r  rM  r   r    rJ   rH   rC   rP  test.supportr   r   r   r   r   r   r	   r
   r   r   r   r   r   test.support.os_helperr   r   r   r   r   test.support.testcaser   r  r   unittest.mockr   r   ctypesr  r  r   r   rK   rS   r  SkipTestr0   TestCaser3   r   r  rw   r  r~   r1   r/   <module>r6     sM     	   	    
   E E E E6 6 1   % ''JJ#//! .
s~~-@B 
 MW


D
EE $-x  / -^GD GDT X$H X$ X$v zMMO k  Fs   :E EE