<s> import platform <EOL> import unittest <EOL> import re <EOL> import os <EOL> from metakernel import pexpect , replwrap <EOL> class REPLWrapTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( REPLWrapTestCase , self ) . setUp ( ) <EOL> self . save_ps1 = os . getenv ( '<STR_LIT>' , r'<STR_LIT>' ) <EOL> self . save_ps2 = os . getenv ( '<STR_LIT>' , '<STR_LIT:>>' ) <EOL> os . putenv ( '<STR_LIT>' , r'<STR_LIT>' ) <EOL> os . putenv ( '<STR_LIT>' , '<STR_LIT:>>' ) <EOL> def tearDown ( self ) : <EOL> super ( REPLWrapTestCase , self ) . tearDown ( ) <EOL> os . putenv ( '<STR_LIT>' , self . save_ps1 ) <EOL> os . putenv ( '<STR_LIT>' , self . save_ps2 ) <EOL> def test_bash ( self ) : <EOL> bash = replwrap . bash ( ) <EOL> res = bash . run_command ( "<STR_LIT:time>" ) <EOL> assert '<STR_LIT>' in res , res <EOL> res = bash . run_command ( '<STR_LIT>' , timeout = <NUM_LIT:2> ) <EOL> assert '<STR_LIT>' in res , res <EOL> def test_multiline ( self ) : <EOL> bash = replwrap . bash ( ) <EOL> res = bash . run_command ( "<STR_LIT>" ) <EOL> self . assertEqual ( res . strip ( ) . splitlines ( ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> try : <EOL> bash . run_command ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> res = bash . run_command ( "<STR_LIT>" ) <EOL> self . assertEqual ( res . strip ( ) . splitlines ( ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_existing_spawn ( self ) : <EOL> child = pexpect . spawnu ( "<STR_LIT>" , timeout = <NUM_LIT:5> , echo = False ) <EOL> repl = replwrap . REPLWrapper ( child , re . compile ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> res = repl . run_command ( "<STR_LIT>" ) <EOL> assert res . startswith ( '<STR_LIT:/>' ) , res <EOL> def test_python ( self ) : <EOL> if platform . python_implementation ( ) == '<STR_LIT>' : <EOL> raise unittest . SkipTest ( "<STR_LIT>" ) <EOL> p = replwrap . python ( ) <EOL> res = p . run_command ( '<STR_LIT>' ) <EOL> assert res . strip ( ) == '<STR_LIT>' <EOL> res = p . run_command ( '<STR_LIT>' ) <EOL> assert res . strip ( ) . splitlines ( ) == [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] <EOL> def test_no_change_prompt ( self ) : <EOL> if platform . python_implementation ( ) == '<STR_LIT>' : <EOL> raise unittest . SkipTest ( "<STR_LIT>" ) <EOL> child = pexpect . spawnu ( '<STR_LIT>' , echo = False , timeout = <NUM_LIT:5> ) <EOL> py = replwrap . REPLWrapper ( child , replwrap . u ( "<STR_LIT>" ) , prompt_change_cmd = None , continuation_prompt_regex = replwrap . u ( re . escape ( "<STR_LIT>" ) ) ) <EOL> assert py . prompt_regex == "<STR_LIT>" <EOL> res = py . run_command ( "<STR_LIT>" ) <EOL> assert res . strip ( ) . splitlines ( ) == [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
