Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6ebf81da
Commit
6ebf81da
authored
Oct 13, 2013
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #17730: in code.interact(), when banner="", do not print anything.
Also adds tests for banner printing.
parent
7c601918
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
Doc/library/code.rst
Doc/library/code.rst
+4
-1
Lib/code.py
Lib/code.py
+1
-1
Lib/test/test_code_module.py
Lib/test/test_code_module.py
+14
-0
No files found.
Doc/library/code.rst
View file @
6ebf81da
...
...
@@ -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)
...
...
Lib/code.py
View file @
6ebf81da
...
...
@@ -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__
))
el
se
:
el
if
banner
:
self
.
write
(
"%s
\
n
"
%
str
(
banner
))
more
=
0
while
1
:
...
...
Lib/test/test_code_module.py
View file @
6ebf81da
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment