[Python-checkins] cpython: Issue27573 code.interact prints a message when exiting.
steven.daprano
python-checkins at python.org
Sun Aug 14 14:17:45 EDT 2016
https://hg.python.org/cpython/rev/9410dc027505
changeset: 102653:9410dc027505
user: Steven D'Aprano <steve at pearwood.info>
date: Mon Aug 15 04:14:33 2016 +1000
summary:
Issue27573 code.interact prints a message when exiting.
files:
Doc/library/code.rst | 3 +++
Lib/code.py | 1 +
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
--- a/Doc/library/code.rst
+++ b/Doc/library/code.rst
@@ -147,6 +147,9 @@
.. 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
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -230,6 +230,7 @@
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
--- a/Lib/test/test_code_module.py
+++ b/Lib/test/test_code_module.py
@@ -69,7 +69,7 @@
# 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 @@
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",
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list