diff options
-rw-r--r-- | Doc/library/code.rst | 3 | ||||
-rw-r--r-- | Lib/code.py | 1 | ||||
-rw-r--r-- | Lib/test/test_code_module.py | 12 |
3 files changed, 14 insertions, 2 deletions
diff --git a/Doc/library/code.rst b/Doc/library/code.rst index 443af69..c573087 100644 --- a/Doc/library/code.rst +++ b/Doc/library/code.rst @@ -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) diff --git a/Lib/code.py b/Lib/code.py index 53244e3..c8b7204 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -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. diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py index 3394b39..08ba3f3 100644 --- a/Lib/test/test_code_module.py +++ b/Lib/test/test_code_module.py @@ -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", |