
    <eH                         	 d dl Z d dlZd dlZd dlmZmZ d dlZd dlmZ  G d dej                  Z	 e             G d dej                              Z
edk    r ej                     dS dS )	    N)script_helperrequires_subprocess)mockc                       e Zd Zd Zd Zd Zd Z ej        d          d             Z	 ej        d          d             Z
dS )	TestScriptHelperc                 j    t          j        dd          }|                     d|d         d           d S )N-cimport sys; sys.exit(0)r   zreturn code was not 0)r   assert_python_okassertEqual)selfts     ./usr/lib/python3.11/test/test_script_helper.pytest_assert_python_okz&TestScriptHelper.test_assert_python_ok   s8    *41JKKAaD"9:::::    c                 f    t          j        dd          \  }}}|                     d|d           d S )Nr	   sys.exit(0)r   zreturn code should not be 0)r   assert_python_failureassertNotEqual)r   rcouterrs       r   test_assert_python_failurez+TestScriptHelper.test_assert_python_failure   s9    $:4OOCAr#@AAAAAr   c                    |                      t                    5 }t          j        dd           d d d            n# 1 swxY w Y   t	          |j                  }|                     d|           |                     d|d           d S )Nr	   r   zcommand line:zunexpected command linemsg)assertRaisesAssertionErrorr   r   str	exceptionassertInr   error_context	error_msgs      r   test_assert_python_ok_raisesz-TestScriptHelper.test_assert_python_ok_raises   s    ~.. 	@-*4???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@/00	oy111mY4MNNNNN   =AAc                    |                      t                    5 }t          j        dd           d d d            n# 1 swxY w Y   t	          |j                  }|                     d|           |                     d|d           d S )Nr	   r
   zProcess return code is 0
zunexpected command line.r   )r   r   r   r   r   r    r!   r"   s      r   !test_assert_python_failure_raisesz2TestScriptHelper.test_assert_python_failure_raises   s    ~.. 	Q-/6OPPP	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q/00	2I>>>/4 	 	6 	6 	6 	6 	6r&   zsubprocess.Popenc                    t           j                            t          dd          5 }t	          d          |_        	 t          j        ddd           n8# t          $ r+}|                     d|j        d                    Y d }~nd }~ww xY w|                     d	|j	                   |                     d	|j	                   |j
        d         d         }|                     t          j        |d                    |                     d|           |                     d
|           |                     d|           d d d            d S # 1 swxY w Y   d S )N interpreter_requires_environmentFreturn_valuebail out of unittestTr	   Noner      -I-E)r   patchobjectr   RuntimeErrorside_effect_assert_pythonr   args
call_count	call_argssys
executabler!   assertNotInr   
mock_popenmock_ire_funcr   popen_commands        r   1test_assert_python_isolated_when_env_not_requiredzBTestScriptHelper.test_assert_python_isolated_when_env_not_required&   s   Z}A,1  3 3 	26C%12H%I%IJ"F,T4@@@@ F F F  !7!EEEEEEEEFQ
 5666Q 8999&03A6MS^]1-=>>>MM&-000MM$...T=111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s;   EAE
B
!B EB

B4EEEc                    	 t           j                            t          dd          5 }t	          d          |_        	 t          j        ddd           n8# t          $ r+}|                     d|j        d                    Y d }~nd }~ww xY w|j	        d         d         }| 
                    d|           | 
                    d	|           d d d            d S # 1 swxY w Y   d S )
Nr*   Tr+   r-   r	   r.   r   r0   r1   )r   r2   r3   r   r4   r5   r6   r   r7   r9   r<   r=   s        r   4test_assert_python_not_isolated_when_env_is_requiredzETestScriptHelper.test_assert_python_not_isolated_when_env_is_required8   sH   LZ}A,0  2 2 
	25B%12H%I%IJ"F,T4@@@@ F F F  !7!EEEEEEEEF&03A6MT=111T=111
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2s;   CAC
B !BCBACC!CN)__name__
__module____qualname__r   r   r%   r(   r   r2   rA   rC    r   r   r   r      s        ; ; ;B B B
O O O6 6 6 TZ"##2 2 $#2" TZ"##2 2 $#2 2 2r   r   c                       e Zd Z	 d Zd Z ej        d          d             Z ej        d          d             Z ej        d          d             Z	 ej        d          d             Z
dS )	TestScriptHelperEnvironmentc                 t    |                      t          t          d                     d t          j        d<   d S N$__cached_interp_requires_environment)
assertTruehasattrr   __dict__r   s    r   setUpz!TestScriptHelperEnvironment.setUpL   sA    M#IJJ	L 	L 	L JNEFFFr   c                 $    d t           j        d<   d S rK   )r   rO   rP   s    r   tearDownz$TestScriptHelperEnvironment.tearDownR   s    IMEFFFr   zsubprocess.check_callc                    t           j                            t          j                  5  t          j                            dd            t          j        dd          |_        | 	                    t          j                               | 	                    t          j                               |                     d|j                   d d d            d S # 1 swxY w Y   d S )N
PYTHONHOME r/   )r   r2   dictosenvironpop
subprocessCalledProcessErrorr5   rM   r   r*   r   r8   r   mock_check_calls     r   *test_interpreter_requires_environment_truezFTestScriptHelperEnvironment.test_interpreter_requires_environment_trueV   s    Z__RZ(( 	< 	<JNN<...*4*GB*O*OO'OOMJLLMMMOOMJLLMMMQ :;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   B"CC Cc                 r   t           j                            t          j                  5  t          j                            dd            t          j                     |                     t          j                               | 	                    d|j
                   d d d            d S # 1 swxY w Y   d S )NrU   r/   )r   r2   rW   rX   rY   rZ   r   r*   assertFalser   r8   r]   s     r   +test_interpreter_requires_environment_falsezGTestScriptHelperEnvironment.test_interpreter_requires_environment_false_   s    Z__RZ(( 	< 	<JNN<...:<<<]KMMNNNQ :;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   A5B,,B03B0c                 \   t           j                            t          j                  5  t          j                            dd            t          j                     |                     t          j                               |                     t          j                               | 	                    d|j
                   |j        d         d         }| 	                    t          j        |d                    |                     d|           d d d            d S # 1 swxY w Y   d S )NrU   r/   r   r1   )r   r2   rW   rX   rY   rZ   r   r*   ra   r   r8   r9   r:   r;   r!   )r   r^   check_call_commands      r   -test_interpreter_requires_environment_detailszITestScriptHelperEnvironment.test_interpreter_requires_environment_detailsh   s:   Z__RZ(( 	4 	4JNN<...:<<<]KMMNNN]KMMNNNQ :;;;!0!:1!=a!@S^-?-BCCCMM$ 2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   C*D!!D%(D%c                 v   t           j                            t          j                  5  dt          j        d<   |                     t          j                               |                     t          j                               |                     d|j	                   d d d            d S # 1 swxY w Y   d S )N
MockedHomerU   r   )
r   r2   rW   rX   rY   rM   r   r*   r   r8   r]   s     r   5test_interpreter_requires_environment_with_pythonhomezQTestScriptHelperEnvironment.test_interpreter_requires_environment_with_pythonhomet   s    Z__RZ(( 	< 	<'3BJ|$OOMJLLMMMOOMJLLMMMQ :;;;		< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   A7B..B25B2N)rD   rE   rF   rQ   rS   r   r2   r_   rb   re   rh   rG   r   r   rI   rI   H   s        ?N N NN N N TZ'((< < )(< TZ'((< < )(< TZ'((	4 	4 )(	4 TZ'((< < )(< < <r   rI   __main__)r[   r:   rX   test.supportr   r   unittestr   TestCaser   rI   rD   mainrG   r   r   <module>rn      s    K     



 				 ; ; ; ; ; ; ; ;       :2 :2 :2 :2 :2x( :2 :2 :2z 1< 1< 1< 1< 1<("3 1< 1< 1<h zHMOOOOO r   