a ze@spddlZddlZddlmZddlmZddlmZddlmZe dZ Gdddej Z e d krledS) N)dedent) ExitStack)mock)supportcodec@sdeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dS)TestInteractiveConsolecCst|_|dS)N)rZInteractiveConsoleconsolemock_sysselfr I/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_code_module.pysetUps zTestInteractiveConsole.setUpcCst}||j|tjddd|_|td|_|td|_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)wrapsspec)rZ addCleanupclose enter_contextrZpatchinfuncstdoutstderrrsyssysmod excepthook__excepthook__ps1ps2)r stackZprepatchr r r r s      zTestInteractiveConsole.mock_syscCsLtd|j_|j||jjdd|j_|j||jjddS)NFinishedz>>> z custom1> )EOFErrorr side_effectrinteract assertEqualrrr r r r test_ps1"s    zTestInteractiveConsole.test_ps1cCsLtd|j_|j||jjdd|j_|j||jjddS)Nrz... z custom2> ) rrrrr r!rrrr r r r test_ps2*s    zTestInteractiveConsole.test_ps2cCsPddtdg|j_|jt|jjD]}dd|dvr(qLq(t ddS)Nz 'antioch'rZantiochzno console stdout) rrrrr listr method_callsjoinAssertionErrorr callr r r test_console_stderr2s  z*TestInteractiveConsole.test_console_stderrcCsJdtdg|j_|j|jjD]}dd|dvr"qFq"tddS)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:dtdg|j_t}||j_|j| |j dS)Nzraise ValueError('')r) rrrrZMockrrrr Z assertTrueZcalled)r hookr r r test_sysexcepthookDs z)TestInteractiveConsole.test_sysexcepthookcCstd|j_|jjdd|t|jjd|jjd}||ddig|j td|j_|jjdd|t|jjd dS) NrZFoobannerrwrite)zFoo r$ rrrrr r!lenrr'Z reset_mock)r Z banner_callr r r test_bannerLs    z"TestInteractiveConsole.test_bannercCstd|j_|jjdd|t|jjd|jjd}d}||d|fig|j td|j_|jjddd|t|jjd|j d }td|j_|jjd|d|t|jjd|jjd}|d }||d|figdS) Nrr$r1r5r%z"now exiting InteractiveConsole... r4)r2Zexitmsgu bye! ζж r6)r err_msgexpectedmessager r r test_exit_msgZs&       z$TestInteractiveConsole.test_exit_msgcCsJdtdg|j_|jddd|jjD}td}| ||dS)Nz(raise ValueError('') from AttributeErrorrr$css|]}d|dVqdSr$r%Nr(.0r+r r r zz7TestInteractiveConsole.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'rZassertInr outputr;r r r test_cause_tbvs  z$TestInteractiveConsole.test_cause_tbcCsJdtdg|j_|jddd|jjD}td}| ||dS)Nztry: ham except: eggs rr$css|]}d|dVqdSr>r?r@r r r rBrCz9TestInteractiveConsole.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_tbs  z&TestInteractiveConsole.test_context_tbN)__name__ __module__ __qualname__rr r"r#r,r.r0r8r=rGrHr r r r r s  r__main__)rZunittesttextwrapr contextlibrrtestr import_modulerZTestCaserrImainr r r r s