summaryrefslogtreecommitdiff
path: root/Lib/test/test_print.py
diff options
context:
space:
mode:
authorSanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>2018-01-20 08:42:22 +0530
committerNick Coghlan <ncoghlan@gmail.com>2018-01-20 13:12:22 +1000
commitd57f26c753dce61f72b52b96db3a3253d9f2fc3e (patch)
tree45edd2bbbd2a8abdfefacf29a52ad45e8a1dfbb4 /Lib/test/test_print.py
parent6690bb9f17d34eb3dec0aca8919d8d27d6c3c452 (diff)
downloadcpython-git-d57f26c753dce61f72b52b96db3a3253d9f2fc3e.tar.gz
bpo-32028: Fix suggestions for indented print statements (GH-4688)
The suggested replacement for print statements previously failed to account for leading whitespace and hence could end up including unwanted text in the proposed call to the print builtin. Patch by Sanyam Khurana.
Diffstat (limited to 'Lib/test/test_print.py')
-rw-r--r--Lib/test/test_print.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py
index e6434feaf5..7bc23cf9fc 100644
--- a/Lib/test/test_print.py
+++ b/Lib/test/test_print.py
@@ -156,6 +156,15 @@ class TestPy2MigrationHint(unittest.TestCase):
self.assertIn('print("Hello World", end=" ")', str(context.exception))
+ def test_string_with_leading_whitespace(self):
+ python2_print_str = '''if 1:
+ print "Hello World"
+ '''
+ with self.assertRaises(SyntaxError) as context:
+ exec(python2_print_str)
+
+ self.assertIn('print("Hello World")', str(context.exception))
+
def test_stream_redirection_hint_for_py2_migration(self):
# Test correct hint produced for Py2 redirection syntax
with self.assertRaises(TypeError) as context: