o
    ^ùh  ã                   @   sx   d Z ddlZddlZddlZddlmZ ddlZddlmZ G dd„ dejƒZ	G dd„ dejƒZ
ed	kr:e ¡  dS dS )
zEUnittests for test.support.script_helper.  Who tests the test helper?é    N)Úscript_helper)Úmockc                   @   sP   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Ze d	¡d
d„ ƒZ	e d	¡dd„ ƒZ
dS )ÚTestScriptHelperc                 C   s"   t  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Út© r   á)  /home/conda/feedstock_root/build_artifacts/python-split_1761171407825/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.10/test/test_script_helper.pyÚtest_assert_python_ok   s   z&TestScriptHelper.test_assert_python_okc                 C   s$   t  dd¡\}}}|  d|d¡ d S )Nr   úsys.exit(0)r   zreturn code should not be 0)r   Úassert_python_failureZassertNotEqual)r	   ZrcÚoutÚerrr   r   r   Útest_assert_python_failure   s   z+TestScriptHelper.test_assert_python_failurec                 C   ó`   |   t¡}t dd¡ W d   ƒ n1 sw   Y  t|jƒ}|  d|¡ | jd|dd d S )Nr   r   zcommand line:zunexpected command line©Úmsg)ÚassertRaisesÚAssertionErrorr   r   ÚstrÚ	exceptionÚassertIn©r	   Zerror_contextZ	error_msgr   r   r   Útest_assert_python_ok_raises   s   ÿ
z-TestScriptHelper.test_assert_python_ok_raisesc                 C   r   )Nr   r   zProcess return code is 0
zunexpected command line.r   )r   r   r   r   r   r   r   r   r   r   r   Ú!test_assert_python_failure_raises   s   ÿ

ÿz2TestScriptHelper.test_assert_python_failure_raiseszsubprocess.Popenc                 C   sì   t jjtdddc}tdƒ|_z	t ddd¡ W n ty3 } z|  d|jd ¡ W Y d }~nd }~ww |  d	|j	¡ |  d	|j	¡ |j
d d }|  tj|d ¡ |  d|¡ |  d
|¡ |  d|¡ W d   ƒ d S 1 sow   Y  d S )NÚ interpreter_requires_environmentF©Z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	   Z
mock_popenZmock_ire_funcr   Zpopen_commandr   r   r   Ú1test_assert_python_isolated_when_env_not_required&   s(   þ
€ÿ"òzBTestScriptHelper.test_assert_python_isolated_when_env_not_requiredc                 C   s²   t jjtdddF}tdƒ|_z	t ddd¡ W n ty3 } z|  d|jd ¡ W Y d}~nd}~ww |j	d d }|  
d	|¡ |  
d
|¡ W d  ƒ dS 1 sRw   Y  dS )z>Ensure that -I is not passed when the environment is required.r   Tr   r    r   r!   r   Nr#   r$   )r   r%   r&   r   r'   r(   r)   r   r*   r,   r/   r0   r   r   r   Ú4test_assert_python_not_isolated_when_env_is_required8   s    þ
€ÿ"özETestScriptHelper.test_assert_python_not_isolated_when_env_is_requiredN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r%   r1   r2   r   r   r   r   r      s    
r   c                   @   sh   e Zd ZdZdd„ Zdd„ Ze d¡dd„ ƒZe d¡d	d
„ ƒZ	e d¡dd„ ƒZ
e d¡dd„ ƒZdS )ÚTestScriptHelperEnvironmentz5Code coverage for interpreter_requires_environment().c                 C   s   |   ttdƒ¡ d tjd< d S ©NZ$__cached_interp_requires_environment)Ú
assertTrueÚhasattrr   Ú__dict__©r	   r   r   r   ÚsetUpK   s   ÿz!TestScriptHelperEnvironment.setUpc                 C   s   d t jd< d S r7   )r   r:   r;   r   r   r   ÚtearDownQ   s   z$TestScriptHelperEnvironment.tearDownzsubprocess.check_callc                 C   sz   t j tj¡, tj dd ¡ t dd¡|_|  	t
 ¡ ¡ |  	t
 ¡ ¡ |  d|j¡ W d   ƒ d S 1 s6w   Y  d S )NÚ
PYTHONHOMEÚ r"   )r   r%   ÚdictÚosÚenvironÚpopÚ
subprocessZCalledProcessErrorr(   r8   r   r   r   r+   ©r	   Úmock_check_callr   r   r   Ú*test_interpreter_requires_environment_trueU   s   "ûzFTestScriptHelperEnvironment.test_interpreter_requires_environment_truec                 C   sf   t j tj¡" tj dd ¡ t ¡  |  t ¡ ¡ |  	d|j
¡ W d   ƒ d S 1 s,w   Y  d S )Nr>   r"   )r   r%   r@   rA   rB   rC   r   r   ÚassertFalser   r+   rE   r   r   r   Ú+test_interpreter_requires_environment_false^   s   "ûzGTestScriptHelperEnvironment.test_interpreter_requires_environment_falsec                 C   s    t j tj¡? tj dd ¡ t ¡  |  t ¡ ¡ |  t ¡ ¡ |  	d|j
¡ |jd d }|  	tj|d ¡ |  d|¡ W d   ƒ d S 1 sIw   Y  d S )Nr>   r"   r   r$   )r   r%   r@   rA   rB   rC   r   r   rH   r   r+   r,   r-   r.   r   )r	   rF   Zcheck_call_commandr   r   r   Ú-test_interpreter_requires_environment_detailsg   s   "øzITestScriptHelperEnvironment.test_interpreter_requires_environment_detailsc                 C   sh   t j tj¡# dtjd< |  t ¡ ¡ |  t ¡ ¡ |  d|j	¡ W d   ƒ d S 1 s-w   Y  d S )NZ
MockedHomer>   r   )
r   r%   r@   rA   rB   r8   r   r   r   r+   rE   r   r   r   Ú5test_interpreter_requires_environment_with_pythonhomes   s   
"üzQTestScriptHelperEnvironment.test_interpreter_requires_environment_with_pythonhomeN)r3   r4   r5   Ú__doc__r<   r=   r   r%   rG   rI   rJ   rK   r   r   r   r   r6   H   s    


r6   Ú__main__)rL   rD   r-   rA   Ztest.supportr   Zunittestr   ZTestCaser   r6   r3   Úmainr   r   r   r   Ú<module>   s    =4ÿ