]> granicus.if.org Git - python/commitdiff
Closes #17730: in code.interact(), when banner="", do not print anything.
authorGeorg Brandl <georg@python.org>
Sun, 13 Oct 2013 19:49:06 +0000 (21:49 +0200)
committerGeorg Brandl <georg@python.org>
Sun, 13 Oct 2013 19:49:06 +0000 (21:49 +0200)
Also adds tests for banner printing.

Doc/library/code.rst
Lib/code.py
Lib/test/test_code_module.py

index 56214b9f7227bb7cadddc4e62ff5e12b5125cde5..d1f94755ee0bcaa1450e1b85ceedfaf3c59153ef 100644 (file)
@@ -132,12 +132,15 @@ interpreter objects as well as the following additions.
 
 .. method:: InteractiveConsole.interact(banner=None)
 
-   Closely emulate the interactive Python console. The optional banner argument
+   Closely emulate the interactive Python console. The optional *banner* argument
    specify the banner to print before the first interaction; by default it prints a
    banner similar to the one printed by the standard Python interpreter, followed
    by the class name of the console object in parentheses (so as not to confuse
    this with the real interpreter -- since it's so close!).
 
+   .. versionchanged:: 3.4
+      To suppress printing any banner, pass an empty string.
+
 
 .. method:: InteractiveConsole.push(line)
 
index 9020aab70163a8d684f08aeffeb56d44df79d2c2..f8184b6c22e5632d9e372553f90d289a827dafc2 100644 (file)
@@ -216,7 +216,7 @@ class InteractiveConsole(InteractiveInterpreter):
             self.write("Python %s on %s\n%s\n(%s)\n" %
                        (sys.version, sys.platform, cprt,
                         self.__class__.__name__))
-        else:
+        elif banner:
             self.write("%s\n" % str(banner))
         more = 0
         while 1:
index adef1701d46a469b41335a2579bf8ff753bbb3e4..5fd21dc32c61872d13e4b820945d207ba27bc465 100644 (file)
@@ -64,6 +64,20 @@ class TestInteractiveConsole(unittest.TestCase):
         self.console.interact()
         self.assertTrue(hook.called)
 
+    def test_banner(self):
+        # with banner
+        self.infunc.side_effect = EOFError('Finished')
+        self.console.interact(banner='Foo')
+        self.assertEqual(len(self.stderr.method_calls), 2)
+        banner_call = self.stderr.method_calls[0]
+        self.assertEqual(banner_call, ['write', ('Foo\n',), {}])
+
+        # no banner
+        self.stderr.reset_mock()
+        self.infunc.side_effect = EOFError('Finished')
+        self.console.interact(banner='')
+        self.assertEqual(len(self.stderr.method_calls), 1)
+
 
 def test_main():
     support.run_unittest(TestInteractiveConsole)