<s> import sys <EOL> from bpython . test import mock , unittest <EOL> from bpython . curtsiesfrontend . coderunner import CodeRunner , FakeOutput <EOL> class TestCodeRunner ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . orig_stdout = sys . stdout <EOL> self . orig_stderr = sys . stderr <EOL> def tearDown ( self ) : <EOL> sys . stdout = self . orig_stdout <EOL> sys . stderr = self . orig_stderr <EOL> def test_simple ( self ) : <EOL> c = CodeRunner ( request_refresh = lambda : self . orig_stdout . flush ( ) or <EOL> self . orig_stderr . flush ( ) ) <EOL> stdout = FakeOutput ( c , lambda * args , ** kwargs : None ) <EOL> stderr = FakeOutput ( c , lambda * args , ** kwargs : None ) <EOL> sys . stdout = stdout <EOL> sys . stdout = stderr <EOL> c . load_code ( '<STR_LIT>' ) <EOL> c . run_code ( ) <EOL> c . run_code ( ) <EOL> c . run_code ( ) <EOL> def test_exception ( self ) : <EOL> c = CodeRunner ( request_refresh = lambda : self . orig_stdout . flush ( ) or <EOL> self . orig_stderr . flush ( ) ) <EOL> def ctrlc ( ) : <EOL> raise KeyboardInterrupt ( ) <EOL> stdout = FakeOutput ( c , lambda x : ctrlc ( ) ) <EOL> stderr = FakeOutput ( c , lambda * args , ** kwargs : None ) <EOL> sys . stdout = stdout <EOL> sys . stderr = stderr <EOL> c . load_code ( '<STR_LIT>' ) <EOL> c . run_code ( ) <EOL> class TestFakeOutput ( unittest . TestCase ) : <EOL> def assert_unicode ( self , s ) : <EOL> self . assertIsInstance ( s , type ( u'<STR_LIT>' ) ) <EOL> def test_bytes ( self ) : <EOL> out = FakeOutput ( mock . Mock ( ) , self . assert_unicode ) <EOL> out . write ( '<STR_LIT>' ) </s>
