async def test_reroute_stderr(self): """Check reroute_stderr argument is correctly handled""" # reroute_stderr default self.infunc.side_effect = ["import sys", "print('griz', file=sys.stderr)", EOFError('Finished')] self.console.write = mock.AsyncMock(self.console.write) await self.console.interact() write_calls = ''.join( ''.join(call[0]) for call in self.console.write.call_args_list) self.assertIn('griz', write_calls) # reroute_stderr = True self.infunc.side_effect = ["import sys", "print('griz', file=sys.stderr)", EOFError('Finished')] console = asyncode.AsyncInteractiveConsole(reroute_stderr=True) console.write = mock.AsyncMock(console.write) await console.interact() write_calls = ''.join( ''.join(call[0]) for call in console.write.call_args_list) self.assertIn('griz', write_calls) # reroute_stderr = False self.infunc.side_effect = ["import sys", "print('griz', file=sys.stderr)", EOFError('Finished')] console = asyncode.AsyncInteractiveConsole(reroute_stderr=False) console.write = mock.AsyncMock(console.write) with mock.patch('sys.stderr'): await console.interact() write_calls = ''.join( ''.join(call[0]) for call in console.write.call_args_list) self.assertNotIn('griz', write_calls)
def setUp(self): self.console = asyncode.AsyncInteractiveConsole() self.mock_sys()
def setUp(self): self.console = asyncode.AsyncInteractiveConsole() patch = mock.patch('asyncode.input', create=True) self.addCleanup(patch.__exit__, None, None, None) self.infunc = patch.__enter__()