
    6\h                     J   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlZddlZddl m!Z!m"Z" 	 ddl#Z#n# e$$ r dZ#Y nw xY w ej%        e
j&        e
j'        k    pe
j(        e
j)        k    d          Z*eser ej+        d           e            dd            Z, G d	 d
ej-                  Z. G d de.          Z/e* G d de.                      Z0e1dk    r ej2                     dS dS )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_emscriptenis_wasirequires_venv_with_pipTEST_HOME_DIRrequires_resourcecopy_python_src_ignore)can_symlinkEnvironmentVarGuardrmtree)patchMockz:cannot run venv.create from within a venv on this platformz)venv is not available on Emscripten/WASI.c                 .   t          j        | t           j        t           j        |          }|                                \  }}|j        rHt
          r%|r#t          |                    dd                     t          j        |j        | ||          ||fS )N)stdoutstderrencodingutf-8backslashreplace)	
subprocessPopenPIPEcommunicate
returncoder   printdecodeCalledProcessError)cmdr   pouterrs        8/opt/python-3.11.14/usr/lib/python3.11/test/test_venv.pycheck_outputr&   .   s    	 	 	A }}HC| ) 	;s 	;#**W&899:::+L#sC) ) 	)8O    c                   @    e Zd ZdZdZd Zd Zd Zd Zddd	Z	d
 Z
dS )BaseTestzBase class for venv tests.i  c                 <   t           j                            t          j                              | _        t           j        dk    rd| _        d| _        d| _	        n,d| _        ddt          j        d d         z  f| _        d	| _	        t          j        }t           j                            |          d
         | _        t          j        dk    rGt           j                            |          r(t           j                            |          s	d| _        d S d| _        d S )NntScriptsLibIncludebinlibpython%d.%d   includewin32TF)ospathrealpathtempfilemkdtempenv_dirnamebindirr1   r4   sysversion_info_base_executablesplitexeplatformlexistsexistscannot_link_exe)self
executables     r%   setUpzBaseTest.setUp@   s    w''(8(:(:;;7d??#DKDH$DLLDK}s/?/CCDDH$DL)
7==,,R0LG##
++ $GNN:.. $ $(D   #(D   r'   c                 .    t          | j                   d S N)r   r<   rH   s    r%   tearDownzBaseTest.tearDownS   s    t|r'   c                     t                      5 }t                      5 } ||i | d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                |                                fS rL   )r   r   getvalue)rH   funcargskwargsoutputerrors         r%   run_with_capturezBaseTest.run_with_captureV   s     	&& "" &ed%f%%%& & & & & & & & & & & & & & &	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   %.."2"222s,   A
	3A
7	A
7	A

AAc                 :    t          j        j        | j        g|R  S rL   )r7   r8   joinr<   )rH   rR   s     r%   get_env_filezBaseTest.get_env_file\   s    w|DL040000r'   r   r   c                    t           | j        | d|          5 }|                                }d d d            n# 1 swxY w Y   |S )NrrZ   )openrY   read)rH   r   rR   fresults        r%   get_text_file_contentszBaseTest.get_text_file_contents_   s    #$#T*C(CCC 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   <A A c                 j    |                     |          s|                     d|d|           d S d S )NzString z does not end with )endswithfail)rH   stringtails      r%   assertEndsWithzBaseTest.assertEndsWithd   sL    t$$ 	GIIEEETEEFFFFF	G 	Gr'   N)__name__
__module____qualname____doc__maxDiffrJ   rN   rV   rY   ra   rg    r'   r%   r)   r)   <   s        $$G) ) )&  3 3 31 1 1 6=     
G G G G Gr'   r)   c            	          e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
ed	             Zed
             Ze ej         e            d          d                         Zej        dk    rdZn,dddddej        dd         z  fddej        dd         z  dffZd Zd Zd Zd Zd Zd Z ej         e            d          d             Zed             Z ej         e            d          d             Z ej        e j!        d k    d!          d"             Z" ej        e j!        d k    d!          d#             Z# ej        e j!        d k    d$          d%             Z$ ej        e j!        d k    d$          d&             Z%ed'             Z&ed(             Z' ej        e j!        d k    d)          d*             Z( ej        ej        d+k    d,          d-             Z)d. Z* ej        e j!        d k    d)          ed/                         Z+dS )0	BasicTestzTest venv module functionality.c                 ~     | j         | }|                     t          j                            |                     d S rL   )rY   
assertTruer7   r8   isdir)rH   rR   fns      r%   rr   zBasicTest.isdirk   s7    T%b))*****r'   c                     t          | j                   |                     t          j        | j                   |                                  dS )zQ
        Test the create function with default arguments and a str path.
        N)r   r<   rV   venvcreate_check_output_of_default_createrM   s    r%   test_defaults_with_str_pathz%BasicTest.test_defaults_with_str_patho   sF     	t|dk4<888,,.....r'   c                     t          | j                   |                     t          j        t          j        | j                             |                                  dS )zZ
        Test the create function with default arguments and a pathlib.Path path.
        N)r   r<   rV   ru   rv   pathlibPathrw   rM   s    r%   test_defaults_with_pathlib_pathz)BasicTest.test_defaults_with_pathlib_pathw   sP     	t|dk7<+E+EFFF,,.....r'   c                 8   |                      | j                   |                      | j                    | j         | j          |                     d          }t          j        d          dk    ot          j        dk    ot          j
        dk    }|r3|                     t          j                            |                     n2|                     t          j                            |                     |                     d          }t          j        }t          j                            |          }|                     d|z  |           |                     dt          j                            t          j                  z  |           t          j        d	k    rd
nd}dt          j         d| d| j         }|                     ||           |                     | j        | j                  }t          j                            |          sP|                     | j                  }	t1          d|	z             t1          dt          j        |	          z             |                     t          j                            |          d|z             d S )Nlib64P   posixdarwin
pyvenv.cfgz	home = %szexecutable = %sr+    z	 --copiesz
command = z -m venvz --without-pip Contents of %r:    %rFile %r should exist.)rr   r>   r4   r1   rY   structcalcsizer7   r=   r?   rD   rq   r8   islinkassertFalserF   ra   rA   dirnameassertInr9   rI   r<   rC   r   listdir)
rH   r"   
conditionsdatarI   r8   copiesr!   rs   bds
             r%   rw   z)BasicTest._check_output_of_default_create   s5   

4;

4<   
DHg&&s++q0 1rw'7I 1|x/ 	 	0OOBGNN1--....RW^^A..///**<88)
wz**kD($///'g&&s~6678<	> 	> 	>w}}+X3>XX6XX$,XXc4   t{DH55w~~b!! 	-""4;//B#b()))(RZ^^+,,,r**,Cb,HIIIIIr'   c                    g d}|D ]\  }}t          | j                   |st          j                    }nt          j        d
i ||dv rdndi}t	                      |_        t	                      |_        |                     |j        | j                   | 	                    d          }|sdD ]}| 
                    |d|            t          j        dk    r|d	k    r|                     |d|            d S )N))NN)symlinksz--copies)with_pip--without-pip)system_site_packages--system-site-packages)clear--clear)upgrade	--upgrade)upgrade_deps--upgrade-deps)prompt--prompt)r   r   FTr   )r   r   r   r   r   zcommand = .* r+   r   rm   )r   r<   ru   
EnvBuilderr   upgrade_dependencies
_setup_piprV   rv   ra   assertNotRegexr7   r=   assertRegex)rH   attrsattroptbr   s         r%   test_config_file_command_keyz&BasicTest.test_config_file_command_key   sS   	
 	
 	
  	? 	?ID#4<    SO%%O S Sd.F&F&FUUDQS S%)VVA"66AL!!!(DL999..|<<D ?6 F FC''.Ds.D.DEEEEF $4#3#3  '='='=>>>>%	? 	?r'   c                    t           j                            | j                  d         }t	          | j                   t          j                    }|                     |j        | j                   |	                    | j                  }| 
                    d          }|                     |j        d|z             |                     d|           t	          | j                   t          j        d          }|                     |j        | j                   |	                    | j                  }| 
                    d          }|                     |j        d           |                     d|           t	          | j                   t          j        d	          }t           j                            t          j                              }|                     |j        | j                   |	                    | j                  }| 
                    d          }|                     |j        d|z             |                     d
|z  |           d S )N   r   z(%s) z	prompt = z	My prompt)r   z(My prompt) zprompt = 'My prompt'
.zprompt = '%s'
)r7   r8   rB   r<   r   ru   r   rV   rv   ensure_directoriesra   assertEqualr   assertNotInr   basenamegetcwd)rH   env_namebuildercontextr   cwds         r%   test_promptzBasicTest.test_prompt   s   7==..q1t|/##gndl;;;,,T\::**<888);<<<d+++t|/555gndl;;;,,T\::**<88888.555t|/---gry{{++gndl;;;,,T\::**<883777'#-t44444r'   c                     t          j                    }t          j        dk    rdnd}t          j                            t          j                  d         }t          j	                    5 }t          j        
                    t          j                            |||                    t          j        dk    r<t          j        
                    t          j                                                 fd}|                    |          }t          d|          5  |                    |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr6   r,   r0   r   c           
          t           j                            | d                   | d<                       | ddddddg           d S )Nr   -mpipinstallr   
setuptools)r7   r8   normcaser   )r!   rS   
expect_exerH   s     r%   pip_cmd_checkerz<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checker   s_    ))#a&11A  "!#$    r'   zvenv.subprocess.check_output)ru   r   r?   rD   r7   r8   rB   rI   r:   TemporaryDirectoryr   rX   r9   r   r   r   )rH   r   bin_path
python_exefake_env_dirr   fake_contextr   s   `      @r%   test_upgrade_dependenciesz#BasicTest.test_upgrade_dependencies   s   /## # 7 799UW]]3>2215
(** 	;l))\8Z@@ J |w&&W--bg.>.>z.J.JKK
      #55lCCL5GG ; ;,,\:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;/	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s7   ,B6E"E8EE	EE	EE #E c                 8   t          | j                   |                     t          j        | j                   t
          j                            | j        | j        | j	                  }|ddg}d| j        fd| j        fdt          j        fdt          j        ffD ]~\  }}d|z  |d<   t          |          \  }}|                     t          j        |                                                                          t          j        |          |           dS )	z>
        Test that the prefix values are as expected.
        -cNprefixexec_prefixbase_prefixbase_exec_prefixzimport sys; print(sys.%s)r3   )r   r<   rV   ru   rv   r7   r8   rX   r>   rC   r?   r   r   r&   r   rz   r{   stripr   )rH   envpyr!   r   expectedr#   r$   s          r%   test_prefixeszBasicTest.test_prefixes   s    	t|dk4<888T\4;AAdD!t|$DL)CO,!56	!8 	= 	=FH
 169CF#C((HCW\#))++*<*<*>*>??$\(33V= = = =	= 	=r'   c                    t          | j                   |                     t          j        | j        d           t
          j                            | j        | j        | j	                  }|ddg}dddt          t          j                              fdt          j                    fd	t          j                    ffD ]\  }}|                     |          5  d
|z  |d<   t!          |          \  }}|                     |                                |                                |           ddd           n# 1 swxY w Y   dS )R
        Test that the sysconfig functions work in a virtual environment.
        Fr   r   Nzget_preferred_scheme("prefix")ru   zget_default_scheme()ru   is_python_build()get_makefile_filename()get_config_h_filename()%import sysconfig; print(sysconfig.%s)r3   r   r<   rV   ru   rv   r7   r8   rX   r>   rC   str	sysconfigis_python_buildget_makefile_filenameget_config_h_filenamesubTestr&   r   r   encoderH   r   r!   callr   r#   r$   s          r%   test_sysconfigzBasicTest.test_sysconfig  s   
 	t|dk4<%HHHT\4;AAdD! 7, #i&?&A&A"B"BC&	(G(I(IJ&	(G(I(IJL 	F 	FND( d## F F@4GA',,S  hoo.?.?EEEF F F F F F F F F F F F F F F	F 	F   AD::D>	D>	zNeeds symlinksc                    t          | j                   |                     t          j        | j        d           t
          j                            | j        | j        | j	                  }|ddg}dddt          t          j                              fdt          j                    fd	t          j                    ffD ]\  }}|                     |          5  d
|z  |d<   t!          |          \  }}|                     |                                |                                |           ddd           n# 1 swxY w Y   dS )r   Tr   r   Nr   r   r   r   r   r   r3   r   r   s          r%   test_sysconfig_symlinksz!BasicTest.test_sysconfig_symlinks  s    	t|dk4<$GGGT\4;AAdD! 7, #i&?&A&A"B"BC&	(G(I(IJ&	(G(I(IJL 	F 	FND( d## F F@4GA',,S  hoo.?.?EEEF F F F F F F F F F F F F F F	F 	Fr   r6   ))r,   )r/   r-   )r.   site-packages)r0   )r4   )r1   r1   r2   Nr3   r   c                 *   |D ]}t          j        j        | j        g|R  }t          j        |           t           j                            ||          }t          |d          5 }|                    d           ddd           n# 1 swxY w Y   dS )zn
        Create some files in the environment which are unrelated
        to the virtual environment.
        wb   Still here?N)r7   r8   rX   r<   mkdirr]   write)rH   pathsfilenamesubdirsdrs   r_   s          r%   create_contentszBasicTest.create_contentsE  s    
  	( 	(GT\4G444AHQKKKa**Bb$ (1'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (		( 	(s   %BB	B	c                    |                      | j        d           t          j        | j                   | j        D ]}t          j        j        | j        g|dz   R  }|                     t
          j        	                    |                     t          |d          5 }|                     |                                d           ddd           n# 1 swxY w Y   t          j        d          }|                    | j                   | j        D ]S}t          j        j        | j        g|dz   R  }|                     t
          j        	                    |                     TdS )zE
        Test creating environment in an existing directory.
        foo)r   rbr   NTr   )r   ENV_SUBDIRSru   rv   r<   r7   r8   rX   rq   rF   r]   r   r^   r   r   )rH   r   rs   r_   r   s        r%   test_overwrite_existingz!BasicTest.test_overwrite_existingQ  s    	T-u555DL!!!' 	; 	;GdlBg.@BBBBOOBGNN2..///b$ ;1  >:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; /---t|$$$' 	1 	1GdlBg.@BBBBRW^^B//0000	1 	1s   )CC	C	c                 v   t          j        |          D ]}t           j                            ||          }t           j                            |          st           j                            |          rt          j        |           ut           j                            |          rt          |           d S rL   )	r7   r   r8   rX   r   isfileremoverr   r   )rH   r8   rs   s      r%   clear_directoryzBasicTest.clear_directoryc  s    *T"" 	 	BdB''Bw~~b!! RW^^B%7%7 	"r"" r


	 	r'   c                 t   | j         d d         D ]}t          j        j        | j        g|R  }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   |                     t          t          ft          j        | j                   |                     | j                   d S )N   r   r'   )r   r7   r8   rX   r<   r]   r   assertRaises
ValueErrorOSErrorru   rv   r   )rH   r   rs   r_   s       r%   test_unoverwritable_failsz#BasicTest.test_unoverwritable_failsk  s    %bqb) 	/ 	/Edl3U333Bb$ 1              z73T[$,OOO  ....	/ 	/s   A  A$	'A$	c                    dD ]@}t          j        |          }|                     |j        | j                   |                     | j                   |                     | j                    | j        | j          | 	                    | j        | j
                  }t          j                            |          sP| 	                    | j                  }t          d|z             t          dt          j        |          z             |                     t          j                            |          d|z             BdS )zC
        Test upgrading an existing environment directory.
        FT)r   r   r   r   N)ru   r   rV   rv   r<   rr   r>   r4   r1   rY   rC   r7   r8   rF   r   r   rq   )rH   r   r   rs   r   s        r%   test_upgradezBasicTest.test_upgradet  s$    % 	N 	NGog666G!!'.$,???JJt{###JJt|$$$DJ!!""4;99B7>>"%% 1&&t{33'",---hB/000OOBGNN2..0G"0LMMMM	N 	Nr'   c                     dD ]c\  }}t          j        d|          }|                    | j                   |                     d          }|                     d|z  |           ddS )z:
        Test isolation from system site-packages
        ))Ttrue)FfalseT)r   r   r   z"include-system-site-packages = %s
N)ru   r   rv   r<   ra   r   )rH   sspsr   r   s        r%   test_isolationzBasicTest.test_isolation  s}     9 	K 	KFCoDsKKKGNN4<(((..|<<DMM?!CTJJJJ		K 	Kr'   c                    dD ]}t          j        d|          }|                    | j                   |                     | j        | j                  }|rl| j        r3|                     t          j
                            |                     |                     t          j
                            |                     dS )z3
        Test symlinking works as expected
        r  Tr   r   N)ru   r   rv   r<   rY   r>   rC   rG   r   r7   r8   r   rq   )rH   uslr   rs   s       r%   test_symlinkingzBasicTest.test_symlinking  s    
 ! 	8 	8CoD3???GNN4<(((""4;99B  8' 8 $$RW^^B%7%78888OOBGNN2$6$6777	8 	8r'   c                    t          | j                   |                     t          j        | j                   t
          j                            t
          j                            | j                  | j	        | j
                  }t          |ddg          \  }}|                     |                                |                                           dS )D
        Test that the sys.executable value is as expected.
        r   !import sys; print(sys.executable)N)r   r<   rV   ru   rv   r7   r8   rX   r9   r>   rC   r&   r   r   r   rH   r   r#   r$   s       r%   test_executablezBasicTest.test_executable  s    
 	t|dk4<888RW--dl;;![$(4 4/!1 2 2Sellnn55555r'   c                    t          | j                   t          j        dd          }|                    | j                   t
          j                            t
          j                            | j                  | j	        | j
                  }t          |ddg          \  }}|                     |                                |                                           dS )r  Tr  r   r  Nr   r<   ru   r   rv   r7   r8   rX   r9   r>   rC   r&   r   r   r   rH   r   r   r#   r$   s        r%   test_executable_symlinksz"BasicTest.test_executable_symlinks  s    
 	t|/t<<<t|$$$RW--dl;;![$(4 4/!1 2 2Sellnn55555r'   r+   z&contains invalid characters on Windowsc                    t          | j                   t          j        d          }||                     d           d}t
          j                            t
          j                            | j                  |          }t          j
        d          }|                    |           t
          j                            || j        d          }t
          j                            | j        d          }t          |d	          5 }|                    d
t          j        |           d           ddd           n# 1 swxY w Y   t#          ||g          \  }}	|                                }
|                     |                                |
d         v            |                     |
d         |                                           dS )zK
        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   r<   shutilwhichskipTestr7   r8   rX   r9   ru   r   rv   r>   r]   r   shlexquoter&   
splitlinesrq   r   rg   )rH   r  r   r<   r   r  test_scriptr_   r#   r$   liness              r%   test_special_chars_bashz!BasicTest.test_special_chars_bash  s   
 	t||F##<MM7888!',,rw//==xHH/---w7<<jAAgll4<1HII+s## 	$qGG #ek(33 # # # $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
  { 344S  ))U1X5666E!Hhoo&7&788888s   	,EEEc                    t          | j                   t          j        d          pt          j        d          }||                     d           d}t
          j                            t
          j                            | j                  |          }t          j
        d          }|                    |           t
          j                            || j        d          }t
          j                            | j        d	          }t          |d
          5 }|                    dt          j        |           d           ddd           n# 1 swxY w Y   t#          ||g          \  }}	|                                }
|                     |                                |
d         v            |                     |
d         |                                           dS )zJ
        Test that the template strings are quoted properly (csh)
        tcshcshNzcsh required for this testr  Tr   zactivate.cshztest_special_chars.cshr  r  r   r   r   r!  )rH   r-  r   r<   r   r  r(  r_   r#   r$   r)  s              r%   test_special_chars_cshz BasicTest.test_special_chars_csh  s   
 	t|l6""9fl5&9&9;MM6777!',,rw//==xHH/---w7<<nEEgll4<1IJJ+s## 	$qGG #ek(33 # # # $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
  k 233S  ))U1X5666E!Hhoo&7&788888s   ,EEEzonly relevant on Windowsc           
      J   t          | j                   d}t          j                            t          j                            | j                  |          }t          j        d          }|                    |           t          j                            || j	        d          }t          j                            | j        d          }t          |d          5 }|                    d| d| j         d	| j         d
           ddd           n# 1 swxY w Y   t          |g          \  }}|                                }	|                     |                                |	d         v            |                     |	d         |                                           dS )zO
        Test that the template strings are quoted properly on Windows
        z'&&^$eTr   activate.batztest_special_chars.batr  z@echo off
"z" & z* -c "import sys; print(sys.executable)" & z> -c "import os; print(os.environ['VIRTUAL_ENV'])" & deactivateNr   r   )r   r<   r7   r8   rX   r9   ru   r   rv   r>   r]   r   rC   r&   r'  rq   r   rg   )
rH   r   r<   r   r  
test_batchr_   r#   r$   r)  s
             r%   test_special_chars_windowsz$BasicTest.test_special_chars_windows  s   
 	t|',,rw//==xHH/---w7<<nEEW\\$,0HII
*c"" 	"aGG ! ! !x! ! x! ! ! " " "	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"  --S  ))U1X5666E!Hhoo&7&788888s   *DDDc                 4   t          | j                   t          j                            t          j                            | j                  d          }t          j        d          }|                    |           t          j                            || j	        d          }t          j                            || j	        | j
                  }t          |d| j
        ddgd	          \  }}|                     |                                d
           dS )z0
        Test handling of Unicode paths
        u   ϼўТλФЙTr   r0  &r   zprint(0)oemrZ   0N)r   r<   r7   r8   rX   r9   ru   r   rv   r>   rC   r&   r   r   )rH   r<   r   r  r   r#   r$   s          r%   test_unicode_in_batch_filez$BasicTest.test_unicode_in_batch_file  s    
 	t|',,rw//==~NN/---w7<<nEEWdk48<<sDHdJ7
 
 
S 	c*****r'   c                    t                       t          | j                   |                     t          j        | j                   t          j                            t          j        	                    | j                  | j
        | j                  }t          |ddg          \  }}|                     |                                d                                           dS )zA
        Test that the multiprocessing is able to spawn.
        r   zrfrom multiprocessing import Pool; pool = Pool(1); print(pool.apply_async("Python".lower).get(3)); pool.terminate()pythonN)r   r   r<   rV   ru   rv   r7   r8   rX   r9   r>   rC   r&   r   r   r   r  s       r%   test_multiprocessingzBasicTest.test_multiprocessing#  s     	3444t|dk4<888RW--dl;;![$(4 4!  ! !S
 	hoo&7&788888r'   c                    t                       t          | j                   |                     t          j        | j                   t          j                            t          j        	                    | j                  | j
        | j                  }t          j                            t          d          }t          j        |d|g           dS )zG
        Test that the multiprocessing is able to spawn itself
        z_test_venv_multiprocessing.py-IN)r   r   r<   rV   ru   rv   r7   r8   rX   r9   r>   rC   r   r   
check_call)rH   r   scripts      r%   test_multiprocessing_recursionz(BasicTest.test_multiprocessing_recursion8  s    
 	3444t|dk4<888RW--dl;;![$(4 4m-LMMudF344444r'   znot relevant on Windowsc                    t          j        d          }||                     d           t          | j                   t          j        d          }|                    | j                   t          j	        
                    | j        | j        d          }t          j	        
                    | j        d          }t          |d          5 }|                    d| d	           d d d            n# 1 swxY w Y   t          ||g          \  }}|                     |d
                                           |                     |d
                                           d S )Nr  r  Tr   r  ztest_strict.shr  zset -euo pipefail
source z
deactivate
r   )r"  r#  r$  r   r<   ru   r   rv   r7   r8   rX   r>   r]   r   r&   r   r   )rH   r  r   r  r(  r_   r#   r$   s           r%   %test_deactivate_with_strict_bash_optsz/BasicTest.test_deactivate_with_strict_bash_optsF  s{   |F##<MM7888t|/---t|$$$7<<dk:FFgll4<1ABB+s## 	$qGG #&# # # $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$  { 344Sbiikk***biikk*****s   C55C9<C9r   zonly relevant on macOSc                    t          | j                   t          j                    }|                    | j                   t
          j                            t
          j                            | j                  | j	        | j
                  }t          |ddg          \  }}|                     |                                d                                           d S )Nr   z5import os; print("__PYVENV_LAUNCHER__" in os.environ)Falser  r  s        r%   test_macos_envzBasicTest.test_macos_envY  s    t|/##t|$$$RW--dl;;![$(4 4C!E F FSgnn&6&677777r'   c                    t          | j                   | j        t          j        z   }|                     t
          t          j        |           |                     t
          t          j        t          j	        |                     dS )zn
        Test that venv creation fails when the target directory contains
        the path separator.
        N)
r   r<   r7   pathsepr   r   ru   rv   rz   r{   )rH   bad_itempaths     r%   test_pathsep_errorzBasicTest.test_pathsep_errore  sf    
 	t||bj0*dk<@@@*dk7<3M3MNNNNNr'   c           	         t          | j                   t          j        }t          j                            t          j                              }| 	                    t           |           t          j        
                    || j                  }t	          j        |           t          j        t          j        |           t          j        
                    ||| j        d                   }t	          j        |           t          j        
                    |d          }dt          j        dd         z  }t          j        
                    |||          }g }t          j        D ]}	|	                    d          rSt          j                            |	          r3t          j        |	t          j        
                    ||                     kt          j                            t          j        
                    |	d                    rt	          j        |	          }
t/          |	|
          }|
D ]}||v r|dk    rt          j        
                    |	|          }t          j                            |          rt          j        ||           ct          j                            |          r:t          j        |t          j        
                    ||          t.                     |                    |	           t          j        
                    || j        | j                  d	d
d| j        g}t          j        
                    |          }t=          j        d          }|rt=          j                     rFt          j        !                    t          j        "                    t          j                            }t          j#        dk    rd}nd}tI          j%        |d|||i           t          j        
                    | j        | j        | j                  }|dddg}tM          |          \  }}| '                    |(                                |v            dS )zr
        Test that when create venv from non-installed python, the zip path
        value is as expected.
        r   zos.pyzpython%d%d.zipNr3   z.zipr   )ignorer   ru   r   LIBDIRr   DYLD_LIBRARY_PATHLD_LIBRARY_PATH
PYTHONPATH)envz-Sr   zimport sys; print(sys.path)))r   r<   r?   
platlibdirr7   r8   r9   r:   r;   
addCleanuprX   r>   r   r"  copy2rI   r1   makedirsr@   rc   r   copyfiler   r   copyrr   copytreeappendrC   rF  r   get_config_varr   abspathr   rD   r   r=  r&   rq   r   )rH   rP  non_installed_dirr>   libdirlandmark
stdlib_zipzip_landmark'additional_pythonpath_for_non_installedeachpathnamesignored_namesr=   rs   r!   
pythonpathld_library_pathld_library_path_envr   r#   r$   s                        r%   %test_zippath_from_non_installed_posixz/BasicTest.test_zippath_from_non_installed_posixo  s    	t| ^
G,,X-=-?-?@@ 1222/==
S^V,,,/TXa[II
F7<<00%(8!(<<
w||$5$.$.0 0 35/  	 	H  (( 7>>(++ EO %6
CCE E E Xw ? ?@@ 
8,, 6x G G! 
G 
GD},, .. h55Bw~~b)) GB////r** GBGLL,F,F/EG G G G
G 8>>   w||-t{DHEE|	 Z__35 5

 $28<< 	O)";"="= 	O goobgoocn.M.MNNO<8##"5"3c#/#6#I	J 	J 	J 	J T\4;AA dD"?@$$S++--455555r'   ),rh   ri   rj   rk   rr   rx   r|   rw   r   r   r   requireVenvCreater   r   unittest
skipUnlessr   r   r?   rD   r   r@   r   r   r   r  r  r  r  r  r  skipIfr7   r=   r*  r.  r2  r7  r:  r?  rA  rD  rH  rf  rm   r'   r%   ro   ro   h   s       ))+ + +/ / // / /J J J8? ? ?>5 5 58; ; ;< = = =& F F F* X(899F F :9 F* |w
 MC$4RaR$889MC$4RaR$88/J

( 
( 
(1 1 1$  / / /N N N*K K K X(8998 8 :98. 
6 
6 
6 X(8996 6 :96 X_RW_&NOO9 9 PO92 X_RW_&NOO9 9 PO92 XD*DEE9 9 FE9, XD*DEE+ + FE+  9 9 9( 5 5 5 X_RW_&?@@+ + A@+$ X13KLL	8 	8 ML	8O O O X_RW_&?@@L6 L6  A@L6 L6 L6r'   ro   c                       e Zd ZdZd Zd Zd Zd Zd Ze	j
        d             Z e             ed          d	                         Zd
S )EnsurePipTestz%Test venv module installation of pip.c                    t           j                            t           j                            | j                  | j        | j                  }t          |ddg          \  }}|                    d          }| 	                    |d           |                    d          }| 	                    |
                                d           d S )Nr   z1try:
 import pip
except ImportError:
 print("OK")latin-1r   OK)r7   r8   rX   r9   r<   r>   rC   r&   r   r   r   r  s       r%   assert_pip_not_installedz&EnsurePipTest.assert_pip_not_installed  s    RW--dl;;![$(4 4B!D E ES jj##b!!!jj##d+++++r'   c                     t          | j                   |                     t          j        | j                   |                                  d S rL   r   r<   rV   ru   rv   rp  rM   s    r%   test_no_pip_by_defaultz$EnsurePipTest.test_no_pip_by_default  sD    t|dk4<888%%'''''r'   c                     t          | j                   |                     t          j        | j        d           |                                  d S )NF)r   rr  rM   s    r%   test_explicit_no_pipz"EnsurePipTest.test_explicit_no_pip  sI    t|dk4<%HHH%%'''''r'   c                 2   t          t          j        d          5 }|                     |                                d           d d d            n# 1 swxY w Y   |                     t          j                            t          j                             d S )Nr   r'   )r]   r7   devnullr   r^   rq   r8   rF   )rH   r_   s     r%   test_devnullzEnsurePipTest.test_devnull  s    
 "*d## 	,qQVVXXs+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	rz2233333s   )AAAc                    t          | j                   t                      5 }d|d<   d|d<   t          j                    5 }||d<   d}d}d}|fD ]\  }}t
          j                            ||          }	t          j        |	           t
          j                            |	|          }
t          |
d	          5 }|
                    |           d d d            n# 1 swxY w Y   |                                 5  |                     t          j        | j        |d
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t
          j                            t
          j                            | j                  | j        | j                  }t%          |ddddddddg	          \  }}|                    d          }|                     |d           |                    d          }d                    t-          j                              }|                     |d t1          |                   |           t          j        | j                                      d          }|                     ||           t                      5 }|                                 5  d|d<   t%          |dddddddg          \  }}d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                    d          }t7          j        dd|t6          j                  }|                     |                                d           |                    d          }|                     d|           |                     d|           |s|                                  d S d S )NrJ  PYTHONWARNINGS1PIP_NO_INSTALLHOMEz[global]
no-install=1)r   zpip.ini)z.pipzpip.confr  T)r   r   z-Wzignore::DeprecationWarningzignore::ImportWarningr<  r   r   z	--versionrn  r   zpip {}zensurepip._uninstallzl^(WARNING: )?The directory .* or its parent directory is not owned or is not writable by the current user.*$)flagszSuccessfully uninstalled pipz#Successfully uninstalled setuptools) r   r<   r   r:   r   r7   r8   rX   r   r]   r   nicer_errorrV   ru   rv   r9   r>   rC   r&   r   r   format	ensurepipversionlenfsencoder   resub	MULTILINErstriprp  )rH   r   envvarshome_dir
bad_configwin_locationposix_locationr   fnamedirpathfpathr_   r   r#   r$   expected_versionr<   s                    r%   do_test_with_pipzEnsurePipTest.do_test_with_pip  s7   t| "" !	9g )1G$% ),G$% ,.. 9("*5
  2!5'5&7 , ,NGU gll8W==GHW%%%GLL%88EeS)) ,Q
+++, , , , , , , , , , , , , , ,
 %%'' 9 9))$+t|?S37 * 9 9 99 9 9 9 9 9 9 9 9 9 9 9 9 9 9#9 9 9 9 9 9 9 9 9 9 9 9 9 9 9!	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9 !	9F RW--dl;;T[$(SS.J,dUK!) * *S
 jj##b!!!jj###??9+<+>+>??3c"233346FGGG+dl++229==gs###
 !"" 	3g!!## 3 3 -5()'6140)2 3 3S	3 3 3 3 3 3 3 3 3 3 3 3 3 3 3	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 jj## f NOQ. . . 	r*** jj##4c:::;SAAA $ 	,))+++++	, 	,s   EA8E9C	ECE"C#E;)D0$E0D44E7D48E;EE	EE	EE"%E"2L
 K3'L
3K7	7L
:K7	;L

LLc              #      K   	 dV  dS # t           j        $ rb}|j        pd                    d          }|j        pd                    d          }|                     | d| d|            Y d}~dS d}~ww xY w)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.
        Nr'   replace)errorsz

**Subprocess Output**
z

**Subprocess Error**
)r   r    rT   r   r   rd   )rH   excr#   r$   s       r%   r  zEnsurePipTest.nicer_error<  s      		EEEEE, 	 	 	:$,,I,>>C:$,,I,>>CII / /*-/ /),/ /        	s   
 A;AA66A;cpuc                 Z    |                      d           |                      d           d S )NFT)r  rM   s    r%   test_with_pipzEnsurePipTest.test_with_pipO  s2     	e$$$d#####r'   N)rh   ri   rj   rk   rp  rs  ru  rx  r  
contextlibcontextmanagerr  r
   r   r  rm   r'   r%   rl  rl    s        //
, 
, 
,( ( (
( ( (
4 4 4W, W, W,r   $ u$ $  $ $ $r'   rl  __main__rL   )3rk   r  r  r7   os.pathrz   r  r"  r   r   r?   r   r:   r%  test.supportr   r   r   r   r   r   r	   r
   r   r   r   test.support.os_helperr   r   r   rh  ru   unittest.mockr   r   ctypesImportErrorri  r   r   rA   rI   rg  SkipTestr&   TestCaser)   ro   rl  rh   mainrm   r'   r%   <module>r     s            				   				       



      E E E E E E E E E E E E E E E E E E E E E E E E E E
 N M M M M M M M M M   % % % % % % % %MMMM   FFF
 (H'J#/! .
s~-@B B 
  IG I
(
G
H
HH   *G *G *G *G *Gx  *G *G *GXU	6 U	6 U	6 U	6 U	6 U	6 U	6 U	6n S$ S$ S$ S$ S$H S$ S$ S$l zHMOOOOO s   ,A1 1A;:A;