a ze@stdZddlZddlZddlZddlmZddlZddlmZGdddejZ GdddejZ e d krpe dS) zEUnittests for test.support.script_helper. Who tests the test helper?N) script_helper)mockc@sPeZdZddZddZddZddZed d d Z ed d d Z dS)TestScriptHelpercCs"tdd}|d|dddS)N-cimport sys; sys.exit(0)rzreturn code was not 0)rassert_python_ok assertEqual)selftr K/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_script_helper.pytest_assert_python_ok s z&TestScriptHelper.test_assert_python_okcCs$tdd\}}}|d|ddS)Nr sys.exit(0)rzreturn code should not be 0)rassert_python_failureZassertNotEqual)r rcouterrr r r test_assert_python_failuresz+TestScriptHelper.test_assert_python_failurecCs`|t}tddWdn1s,0Yt|j}|d||jd|dddS)Nrrz command line:zunexpected command linemsg) assertRaisesAssertionErrorrrstr exceptionassertInr Z error_contextZ error_msgr r r test_assert_python_ok_raisess  *  z-TestScriptHelper.test_assert_python_ok_raisescCs`|t}tddWdn1s,0Yt|j}|d||jd|dddS)NrrzProcess return code is 0 zunexpected command line.r)rrrrrrrrr r r !test_assert_python_failure_raisess *  z2TestScriptHelper.test_assert_python_failure_raiseszsubprocess.Popenc Cstjjtddd}td|_ztdddWn6tyf}z|d|jdWYd}~n d}~00|d |j |d |j |j dd}|t j |d| d|| d ||d |Wdn1s0YdS) N interpreter_requires_environmentFZ return_valuebail out of unittestTrNoner-I-E)rpatchobjectr RuntimeError side_effect_assert_pythonrargs call_count call_argssys executabler assertNotInr Z mock_popenZ mock_ire_funcrZ popen_commandr r r 1test_assert_python_isolated_when_env_not_required&s" (  zBTestScriptHelper.test_assert_python_isolated_when_env_not_requiredc Cstjjtddd}td|_ztdddWn6tyf}z|d|jdWYd}~n d}~00|j dd}| d || d |Wdn1s0YdS) z>Ensure that -I is not passed when the environment is required.rTrr rr!rNr#r$) rr%r&rr'r(r)rr*r,r/r0r r r 4test_assert_python_not_isolated_when_env_is_required8s ( zETestScriptHelper.test_assert_python_not_isolated_when_env_is_requiredN) __name__ __module__ __qualname__r rrrrr%r1r2r r r r r s rc@sheZdZdZddZddZedddZedd d Z edd d Z edd dZ dS)TestScriptHelperEnvironmentz5Code coverage for interpreter_requires_environment().cCs|ttddtjd<dSNZ$__cached_interp_requires_environment) assertTruehasattrr__dict__r r r r setUpKsz!TestScriptHelperEnvironment.setUpcCsdtjd<dSr7)rr:r;r r r tearDownQsz$TestScriptHelperEnvironment.tearDownzsubprocess.check_callcCsxtjtjVtjddtdd|_| t | t | d|j Wdn1sj0YdS)N PYTHONHOMEr")rr%dictosenvironpop subprocessCalledProcessErrorr(r8rrrr+r mock_check_callr r r *test_interpreter_requires_environment_trueUs zFTestScriptHelperEnvironment.test_interpreter_requires_environment_truecCsdtjtjBtjddt|t| d|j Wdn1sV0YdS)Nr>r") rr%r@rArBrCrr assertFalserr+rFr r r +test_interpreter_requires_environment_false^s zGTestScriptHelperEnvironment.test_interpreter_requires_environment_falsecCstjtj|tjddt|t|t| d|j |j dd}| t j |d|d|Wdn1s0YdS)Nr>r"rr$)rr%r@rArBrCrrrIrr+r,r-r.r)r rGZcheck_call_commandr r r -test_interpreter_requires_environment_detailsgszITestScriptHelperEnvironment.test_interpreter_requires_environment_detailscCsftjtjDdtjd<|t|t|d|j Wdn1sX0YdS)NZ MockedHomer>r) rr%r@rArBr8rrrr+rFr r r 5test_interpreter_requires_environment_with_pythonhomess  zQTestScriptHelperEnvironment.test_interpreter_requires_environment_with_pythonhomeN) r3r4r5__doc__r<r=rr%rHrJrKrLr r r r r6Hs   r6__main__) rMrDr-rAZ test.supportrZunittestrZTestCaserr6r3mainr r r r s  =4