diff options
author | Georg Brandl <georg@python.org> | 2013-10-13 19:49:06 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-10-13 19:49:06 (GMT) |
commit | fbc3c3c2bed34350e0dde4771805c51b80f2e410 (patch) | |
tree | 2b24e6b4e81deb42db88bc9d5c204dc059a75c3b /Lib | |
parent | a8fc7f6face4aa05b0bd975a3c7f129c67280a81 (diff) | |
download | cpython-fbc3c3c2bed34350e0dde4771805c51b80f2e410.zip cpython-fbc3c3c2bed34350e0dde4771805c51b80f2e410.tar.gz cpython-fbc3c3c2bed34350e0dde4771805c51b80f2e410.tar.bz2 |
Closes #17730: in code.interact(), when banner="", do not print anything.
Also adds tests for banner printing.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/code.py | 2 | ||||
-rw-r--r-- | Lib/test/test_code_module.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/code.py b/Lib/code.py index 9020aab..f8184b6 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -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: diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py index adef170..5fd21dc 100644 --- a/Lib/test/test_code_module.py +++ b/Lib/test/test_code_module.py @@ -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) |