Issue27573 code.interact prints a message when exiting.

This commit is contained in:
Steven D'Aprano 2016-08-15 04:14:33 +10:00
parent a0d3eeff86
commit dd51d16b48
3 changed files with 14 additions and 2 deletions

View File

@ -147,6 +147,9 @@ interpreter objects as well as the following additions.
.. versionchanged:: 3.4
To suppress printing any banner, pass an empty string.
.. versionchanged:: 3.6
Now prints a brief message when exiting.
.. method:: InteractiveConsole.push(line)

View File

@ -230,6 +230,7 @@ class InteractiveConsole(InteractiveInterpreter):
self.write("\nKeyboardInterrupt\n")
self.resetbuffer()
more = 0
self.write('now exiting %s...\n' % self.__class__.__name__)
def push(self, line):
"""Push a line to the interpreter.

View File

@ -69,7 +69,7 @@ class TestInteractiveConsole(unittest.TestCase):
# with banner
self.infunc.side_effect = EOFError('Finished')
self.console.interact(banner='Foo')
self.assertEqual(len(self.stderr.method_calls), 2)
self.assertEqual(len(self.stderr.method_calls), 3)
banner_call = self.stderr.method_calls[0]
self.assertEqual(banner_call, ['write', ('Foo\n',), {}])
@ -77,7 +77,15 @@ class TestInteractiveConsole(unittest.TestCase):
self.stderr.reset_mock()
self.infunc.side_effect = EOFError('Finished')
self.console.interact(banner='')
self.assertEqual(len(self.stderr.method_calls), 1)
self.assertEqual(len(self.stderr.method_calls), 2)
def test_exit_msg(self):
self.infunc.side_effect = EOFError('Finished')
self.console.interact(banner='')
self.assertEqual(len(self.stderr.method_calls), 2)
err_msg = self.stderr.method_calls[1]
expected = 'now exiting InteractiveConsole...\n'
self.assertEqual(err_msg, ['write', (expected,), {}])
def test_cause_tb(self):
self.infunc.side_effect = ["raise ValueError('') from AttributeError",