a 4êdgã@spddlZddlZddlmZddlmZddlmZddlmZe  d¡Z Gdd„dej ƒZ e d krle ¡dS) éN)Údedent)Ú ExitStack)Úmock)ÚsupportÚcodec@sdeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dS)ÚTestInteractiveConsolecCst ¡|_| ¡dS)N)rZInteractiveConsoleÚconsoleÚmock_sys©Úself©r ú1/usr/local/lib/python3.9/test/test_code_module.pyÚsetUps zTestInteractiveConsole.setUpcCs”tƒ}| |j¡| tjddd¡|_| t d¡¡|_| t d¡¡|_tjdt j t j d}| |¡|_ t j t j ur„|j j |j _ |j `|j `dS)Nz code.inputT)Zcreatezcode.sys.stdoutzcode.sys.stderrzcode.sys)ÚwrapsÚspec)rZ addCleanupÚcloseÚ enter_contextrZpatchÚinfuncÚstdoutÚstderrrÚsysÚsysmodÚ excepthookÚ__excepthook__Úps1Úps2)r ÚstackZprepatchr r r r s  ÿ    zTestInteractiveConsole.mock_syscCsLtdƒ|j_|j ¡| |jjd¡d|j_|j ¡| |jjd¡dS)NÚFinishedz>>> z custom1> )ÚEOFErrorrÚ side_effectrÚinteractÚ assertEqualrrr r r r Útest_ps1"s    zTestInteractiveConsole.test_ps1cCsLtdƒ|j_|j ¡| |jjd¡d|j_|j ¡| |jjd¡dS)Nrz... z custom2> ) rrrrr r!rrrr r r r Útest_ps2*s    zTestInteractiveConsole.test_ps2cCsPddtdƒg|j_|j ¡t|jjƒD]}dd |d¡vr(qLq(t dƒ‚dS)Nz 'antioch'ÚrZantiochézno console stdout) rrrrr ÚlistrÚ method_callsÚjoinÚAssertionError©r Úcallr r r Útest_console_stderr2s  z*TestInteractiveConsole.test_console_stderrcCsJdtdƒg|j_|j ¡|jjD]}dd |d¡vr"qFq"tdƒ‚dS)NZ undefinedrÚ NameErrorr$r%zNo syntax error from console) rrrrr rr'r(r)r*r r r Útest_syntax_error;s   z(TestInteractiveConsole.test_syntax_errorcCs:dtdƒg|j_t ¡}||j_|j ¡|  |j ¡dS)Nzraise ValueError('')r) rrrrZMockrrrr Z assertTrueZcalled)r Úhookr r r Útest_sysexcepthookDsÿ z)TestInteractiveConsole.test_sysexcepthookcCsˆtdƒ|j_|jjdd| t|jjƒd¡|jjd}| |ddig¡|j  ¡tdƒ|j_|jjdd| t|jjƒd ¡dS) NrZFoo©ÚbannerérÚwrite)zFoo r$é© rrrrr r!Úlenrr'Z reset_mock)r Z banner_callr r r Ú test_bannerLs    z"TestInteractiveConsole.test_bannercCsötdƒ|j_|jjdd| t|jjƒd¡|jjd}d}| |d|fig¡|j  ¡tdƒ|j_|jjddd| t|jjƒd¡|j  ¡d }tdƒ|j_|jjd|d| t|jjƒd¡|jjd}|d }| |d|fig¡dS) Nrr$r1r5r%z"now exiting InteractiveConsole... r4)r2Zexitmsgu bye! ζжÚ r6)r Úerr_msgÚexpectedÚmessager r r Ú test_exit_msgZs&     ÿ  z$TestInteractiveConsole.test_exit_msgcCsJdtdƒg|j_|j ¡d dd„|jjDƒ¡}tdƒ}|  ||¡dS)Nz(raise ValueError('') from AttributeErrorrr$css|]}d |d¡VqdS©r$r%N©r(©Ú.0r+r r r Ú zóz7TestInteractiveConsole.test_cause_tb..zÝ AttributeError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in ValueError © rrrrr r(rr'rZassertIn©r Úoutputr;r r r Ú test_cause_tbvsÿ  z$TestInteractiveConsole.test_cause_tbcCsJdtdƒg|j_|j ¡d dd„|jjDƒ¡}tdƒ}|  ||¡dS)Nztry: ham except: eggs rr$css|]}d |d¡VqdSr>r?r@r r r rBŠrCz9TestInteractiveConsole.test_context_tb..ah Traceback (most recent call last): File "", line 1, in NameError: name 'ham' is not defined During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 2, in NameError: name 'eggs' is not defined rDrEr r r Útest_context_tb†sÿ  z&TestInteractiveConsole.test_context_tbN)Ú__name__Ú __module__Ú __qualname__rr r"r#r,r.r0r8r=rGrHr r r r r s  rÚ__main__)rZunittestÚtextwraprÚ contextlibrrÚtestrÚ import_modulerZTestCaserrIÚmainr r r r Ús