
    dafH                         d Z 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                          yy)
zEUnittests for test.support.script_helper.  Who tests the test helper?    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
y)	TestScriptHelperc                 \    t        j                  dd      }| j                  d|d   d       y )N-cimport sys; sys.exit(0)r   zreturn code was not 0)r   assert_python_okassertEqual)selfts     2/root/Python-3.12.4/Lib/test/test_script_helper.pytest_assert_python_okz&TestScriptHelper.test_assert_python_ok   s,    **41JKAaD"9:    c                 ^    t        j                  dd      \  }}}| j                  d|d       y )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   s-    $::4OCAr#@Ar   c                     | j                  t              5 }t        j                  dd       d d d        t	        j
                        }| j                  d|       | j                  d|d       y # 1 sw Y   ExY w)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   sl    ~. 	@-**4?	@//0	oy1mY4MN		@ 	@   A11A:c                     | j                  t              5 }t        j                  dd       d d d        t	        j
                        }| j                  d|       | j                  d|d       y # 1 sw Y   ExY w)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   st    ~. 	Q-//6OP	Q//0	2I>/4 	 	6		Q 	Qr&   zsubprocess.Popenc                 z   t         j                  j                  t        dd      5 }t	        d      |_        	 t        j                  ddd       | j                  d	|j                         | j                  d	|j                         |j                  d   d   }| j                  t        j                  |d          | j                  d|       | j                  d
|       | j                  d|       d d d        y # t        $ r)}| j                  d|j                  d          Y d }~d }~ww xY w# 1 sw Y   y xY w)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   ZZ}A,1  3 	26C%12H%IJ"F,,T4@ Q
 5 56Q 8 89&003A6MS^^]1-=>MM&-0MM$.T=1	2 	2   F  !7!EEF	2 	2s5   D1C<B#D1<	D.D)$D1)D..D11D:c                    t         j                  j                  t        dd      5 }t	        d      |_        	 t        j                  ddd       |j                  d   d   }| j                  d	|       | j                  d
|       ddd       y# t        $ r)}| j                  d|j                  d          Y d}~ld}~ww xY w# 1 sw Y   yxY w)z>Ensure that -I is not passed when the environment is required.r*   Tr+   r-   r	   r.   r   Nr0   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   s     ZZ}A,0  2 
	25B%12H%IJ"F,,T4@ '003A6MT=1T=1
	2 
	2   F  !7!EEF
	2 
	2s4   CB6C	CB<7C<CCCN)__name__
__module____qualname__r   r   r%   r(   r   r2   rA   rC    r   r   r   r      sX    ;B
O6 TZZ"#2 $2" TZZ"#2 $2r   r   c                       e Zd 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y	)
TestScriptHelperEnvironmentz5Code coverage for interpreter_requires_environment().c                 h    | j                  t        t        d             d t        j                  d<   y N$__cached_interp_requires_environment)
assertTruehasattrr   __dict__r   s    r   setUpz!TestScriptHelperEnvironment.setUpL   s/    M#IJ	L JNEFr   c                 *    d t         j                  d<   y rK   )r   rO   rP   s    r   tearDownz$TestScriptHelperEnvironment.tearDownR   s    IMEFr   zsubprocess.check_callc                    t         j                  j                  t        j                        5  t        j                  j                  dd        t        j                  dd      |_        | j                  t        j                                | j                  t        j                                | j                  d|j                         d d d        y # 1 sw Y   y xY w)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    ZZ__RZZ( 	<JJNN<.*4*G*GB*OO'OOMJJLMOOMJJLMQ : :;	< 	< 	<s   BCCc                 n   t         j                  j                  t        j                        5  t        j                  j                  dd        t        j                          | j                  t        j                                | j                  d|j                         d d d        y # 1 sw Y   y xY w)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_   sv    ZZ__RZZ( 	<JJNN<.::<]KKMNQ : :;	< 	< 	<s   A4B++B4c                 B   t         j                  j                  t        j                        5  t        j                  j                  dd        t        j                          | j                  t        j                                | j                  t        j                                | j                  d|j                         |j                  d   d   }| j                  t        j                  |d          | j                  d|       d d d        y # 1 sw Y   y xY w)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    ZZ__RZZ( 	4JJNN<.::<]KKMN]KKMNQ : :;!0!:!:1!=a!@S^^-?-BCMM$ 23	4 	4 	4s   CDDc                 r   t         j                  j                  t        j                        5  dt        j                  d<   | j                  t        j                                | j                  t        j                                | j                  d|j                         d d d        y # 1 sw Y   y xY w)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   sy    ZZ__RZZ( 	<'3BJJ|$OOMJJLMOOMJJLMQ : :;		< 	< 	<s   A6B--B6N)rD   rE   rF   __doc__rQ   rS   r   r2   r_   rb   re   rh   rG   r   r   rI   rI   H   s    ?NN TZZ'(< )< TZZ'(< )< TZZ'(	4 )	4 TZZ'(< )<r   rI   __main__)ri   r[   r:   rX   test.supportr   r   unittestr   TestCaser   rI   rD   mainrG   r   r   <module>ro      sl    K  
 	 ;  :2x(( :2z 1<("3"3 1< 1<h zHMMO r   