
    <e}                     >   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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,                      Z.e/dk    r ej0                     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requires_zlib*skip_if_broken_multiprocessing_synchronizeverboserequires_subprocessis_emscriptenis_wasirequires_venv_with_pipTEST_HOME_DIR)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        %/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
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bindirr0   r3   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;   rG   s    r$   tearDownzBaseTest.tearDownQ   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 rK   )r   r   getvalue)rG   funcargskwargsoutputerrors         r$   run_with_capturezBaseTest.run_with_captureT   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 rK   )r6   r7   joinr;   )rG   rQ   s     r$   get_env_filezBaseTest.get_env_fileZ   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rrY   )openrX   read)rG   r   rQ   fresults        r$   get_text_file_contentszBaseTest.get_text_file_contents]   s    #$#T*C(CCC 	qVVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   <A A N)
__name__
__module____qualname____doc__maxDiffrI   rM   rU   rX   r`    r&   r$   r(   r(   :   sy        $$G) ) )&  3 3 31 1 1 6=       r&   r(   c            	       L   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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 ),	BasicTestzTest venv module functionality.c                 ~     | j         | }|                     t          j                            |                     d S rK   )rX   
assertTruer6   r7   isdir)rG   rQ   fns      r$   rk   zBasicTest.isdire   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;   rU   venvcreate_check_output_of_default_createrL   s    r$   test_defaults_with_str_pathz%BasicTest.test_defaults_with_str_pathi   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;   rU   rn   ro   pathlibPathrp   rL   s    r$   test_defaults_with_pathlib_pathz)BasicTest.test_defaults_with_pathlib_pathq   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.)rk   r=   r3   r0   rX   structcalcsizer6   r<   r>   rC   rj   r7   islinkassertFalserE   r`   r@   dirnameassertInr8   rH   r;   rB   r   listdir)
rG   r!   
conditionsdatarH   r7   copiesr    rl   bds
             r$   rp   z)BasicTest._check_output_of_default_createy   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   rf   )r   r;   rn   
EnvBuilderr   upgrade_dependencies
_setup_piprU   ro   r`   assertNotRegexr6   r<   assertRegex)rG   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'
)r6   r7   rA   r;   r   rn   r   rU   ro   ensure_directoriesr`   assertEqualr   assertNotInr   basenamegetcwd)rG   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 )Nr5   r+   r/   r   c           
          t           j                            | d                   | d<                       | ddddddg           d S )Nr   -mpipinstallr   
setuptools)r6   r7   normcaser   )r    rR   
expect_exerG   s     r$   pip_cmd_checkerz<BasicTest.test_upgrade_dependencies.<locals>.pip_cmd_checker   s_    ))#a&11A  "!#$    r&   zvenv.subprocess.check_output)rn   r   r>   rC   r6   r7   rA   rH   r9   TemporaryDirectoryr   rW   r8   r   r   r   )rG   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                    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 ]Z\  }}d|z  |d<   t          |          \  }}|                     |                                |                                |           [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)r2   )r   r;   rU   rn   ro   r6   r7   rW   r=   rB   r>   r   r   r%   r   stripencode)rG   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 	E 	EFH
 169CF#C((HCSYY[[(//*;*;VDDDD	E 	E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")rn   zget_default_scheme()rn   is_python_build()get_makefile_filename()get_config_h_filename()%import sysconfig; print(sysconfig.%s)r2   r   r;   rU   rn   ro   r6   r7   rW   r=   rB   str	sysconfigis_python_buildget_makefile_filenameget_config_h_filenamesubTestr%   r   r   r   rG   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   r2   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   r5   ))r+   )r.   r,   )r-   site-packages)r/   )r3   )r0   r0   r1   Nr2   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)r6   r7   rW   r;   mkdirr\   write)rG   pathsfilenamesubdirsdrl   r^   s          r$   create_contentszBasicTest.create_contents>  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_SUBDIRSrn   ro   r;   r6   r7   rW   rj   rE   r\   r   r]   r   r   )rG   r   rl   r^   r   s        r$   test_overwrite_existingz!BasicTest.test_overwrite_existingJ  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 rK   )	r6   r   r7   rW   r   isfileremoverk   r   )rG   r7   rl   s      r$   clear_directoryzBasicTest.clear_directory\  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   r6   r7   rW   r;   r\   r   assertRaises
ValueErrorOSErrorrn   ro   r   )rG   r   rl   r^   s       r$   test_unoverwritable_failsz#BasicTest.test_unoverwritable_failsd  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)rn   r   rU   ro   r;   rk   r=   r3   r0   rX   rB   r6   r7   rE   r   r   rj   )rG   r   r   rl   r   s        r$   test_upgradezBasicTest.test_upgradem  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)rn   r   ro   r;   r`   r   )rG   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)rn   r   ro   r;   rX   r=   rB   rF   r   r6   r7   r   rj   )rG   uslr   rl   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;   rU   rn   ro   r6   r7   rW   r8   r=   rB   r%   r   r   r   rG   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;   rn   r   ro   r6   r7   rW   r8   r=   rB   r%   r   r   r   rG   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only relevant on Windowsc                 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   zactivate.bat&r   zprint(0)oemrY   0N)r   r;   r6   r7   rW   r8   rn   r   ro   r=   rB   r%   r   r   )rG   r;   r   activater   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;   rU   rn   ro   r6   r7   rW   r8   r=   rB   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        ||g           dS )zG
        Test that the multiprocessing is able to spawn itself
        z_test_venv_multiprocessing.pyN)r   r   r;   rU   rn   ro   r6   r7   rW   r8   r=   rB   r   r   
check_call)rG   r   scripts      r$   test_multiprocessing_recursionz(BasicTest.test_multiprocessing_recursion  s    
 	3444t|dk4<888RW--dl;;![$(4 4m-LMMufo.....r&   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 )Nbashzbash required for this testTr   r  ztest_strict.shwzset -euo pipefail
source z
deactivate
r}   )shutilwhichskipTestr   r;   rn   r   ro   r6   r7   rW   r=   r\   r   r%   r   r   )rG   r   r   r  test_scriptr^   r"   r#   s           r$   %test_deactivate_with_strict_bash_optsz/BasicTest.test_deactivate_with_strict_bash_opts  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_env  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;   r6   pathsepr   r   rn   ro   rs   rt   )rG   bad_itempaths     r$   test_pathsep_errorzBasicTest.test_pathsep_error  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        |	          D ]}
|
dk    r	t          j        
                    |	|
          }t          j                            |          rt          j        ||           ^t          j                            |          r3t          j        |t          j        
                    ||
                     o|                    |	           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}tG          j$        |d|||i           t          j        
                    | j        | j        | j                  }|dddg}tK          |          \  }}| &                    |'                                |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.zipNr2   z.zipr   r   rn   r   LIBDIRr{   DYLD_LIBRARY_PATHLD_LIBRARY_PATH
PYTHONPATH)envz-Sr   zimport sys; print(sys.path))(r   r;   r>   
platlibdirr6   r7   r8   r9   r:   
addCleanuprW   r=   r   r"  copy2rH   r0   makedirsr?   endswithr   copyfiler   copyrk   copytreeappendrB   r+  r   get_config_varr   abspathr   rC   r   r  r%   rj   r   )rG   r4  non_installed_dirr=   libdirlandmark
stdlib_zipzip_landmark'additional_pythonpath_for_non_installedeachpathr<   rl   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_posix  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 ? ?@@ Jx00 H HD.. h55Bw~~b)) HB////r** HBGLL,F,FGGGH 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&   ))ra   rb   rc   rd   rk   rq   ru   rp   r   r   r   requireVenvCreater   r   unittest
skipUnlessr   r   r>   rC   r   r?   r   r   r   r   r   r  r  r  r  r6   r<   r  r  r  skipIfr&  r)  r-  rI  rf   r&   r$   rh   rh   b   sg       ))+ + +/ / // / /J J J8? ? ?>5 5 58; ; ;< E E E$ 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D*DEE+ + FE+  9 9 9( / / / X_RW_&?@@+ + A@+$ X13KLL	8 	8 ML	8O O O X_RW_&?@@F6 F6  A@F6 F6 F6r&   rh   c                   v    e Zd ZdZd Zd Zd Zd Zd Ze	j
        d             Z e            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)r6   r7   rW   r8   r;   r=   rB   r%   r   r   r   r  s       r$   assert_pip_not_installedz&EnsurePipTest.assert_pip_not_installedi  s    RW--dl;;![$(4 4B!D E ES jj##b!!!jj##d+++++r&   c                     t          | j                   |                     t          j        | j                   |                                  d S rK   r   r;   rU   rn   ro   rS  rL   s    r$   test_no_pip_by_defaultz$EnsurePipTest.test_no_pip_by_defaultv  sD    t|dk4<888%%'''''r&   c                     t          | j                   |                     t          j        | j        d           |                                  d S )NF)r   rU  rL   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\   r6   devnullr   r]   rj   r7   rE   )rG   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 )Nignore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::ImportWarningz-Ir   r   z	--versionrQ  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   r9   r   r6   r7   rW   r   r\   r   nicer_errorrU   rn   ro   r8   r=   rB   r%   r   r   format	ensurepipversionlenfsencoder   resub	MULTILINErstriprS  )rG   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   rS   r   r   fail)rG   excr"   r#   s       r$   rc  zEnsurePipTest.nicer_error  s      		EEEEE, 	 	 	:$,,I,>>C:$,,I,>>CII / /*-/ /),/ /        	s   
 A;AA66A;c                 Z    |                      d           |                      d           d S )NFT)rv  rL   s    r$   test_with_pipzEnsurePipTest.test_with_pip  s0    e$$$d#####r&   N)ra   rb   rc   rd   rS  rV  rX  r[  rv  
contextlibcontextmanagerrc  r   r}  rf   r&   r$   rO  rO  f  s        //
, 
, 
,( ( (
( ( (
4 4 4W, W, W,r   $ $ $ $ $ $r&   rO  __main__rK   )1rd   r~  re  r6   os.pathrs   ri  r"  r   r   r>   r   r9   test.supportr   r   r   r   r   r   r	   r
   r   r   test.support.os_helperr   r   r   rK  rn   unittest.mockr   r   ctypesImportErrorrL  r   r   r@   rH   rJ  SkipTestr%   TestCaser(   rh   rO  ra   mainrf   r&   r$   <module>r     s            				   				       



     A A A A A A A A A A A A A A A A A A A A A A A A N M M M M M M M M M   % % % % % % % %MMMM   FFF
 (H'J#/! .
s~-@B B 
  IG I
(
G
H
HH   & & & & &x  & & &PB6 B6 B6 B6 B6 B6 B6 B6H R$ R$ R$ R$ R$H R$ R$ R$j zHMOOOOO s   &A+ +A54A5