diff options
author | Sanyam Khurana <8039608+CuriousLearner@users.noreply.github.com> | 2018-01-20 03:12:22 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2018-01-20 03:12:22 (GMT) |
commit | d57f26c753dce61f72b52b96db3a3253d9f2fc3e (patch) | |
tree | 45edd2bbbd2a8abdfefacf29a52ad45e8a1dfbb4 /Lib | |
parent | 6690bb9f17d34eb3dec0aca8919d8d27d6c3c452 (diff) | |
download | cpython-d57f26c753dce61f72b52b96db3a3253d9f2fc3e.zip cpython-d57f26c753dce61f72b52b96db3a3253d9f2fc3e.tar.gz cpython-d57f26c753dce61f72b52b96db3a3253d9f2fc3e.tar.bz2 |
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')
-rw-r--r-- | Lib/test/test_print.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py index e6434fe..7bc23cf 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: |