diff options
author | Nitish Chandra <nitishchandrachinta@gmail.com> | 2018-01-28 10:56:02 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2018-01-28 10:56:02 (GMT) |
commit | 43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99 (patch) | |
tree | e2a5ab622dbb25f3ec3b6f66099ad1aaaab37acd /Lib | |
parent | 255f7a26da47ca6b7bd1d375b8a04920f68c119c (diff) | |
download | cpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.zip cpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.tar.gz cpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.tar.bz2 |
bpo-32685: Improve suggestion for print statement (GH-5375)
Better account for single-line compound statements and
semi-colon separated statements when suggesting
Py3 replacements for Py2 print statements.
Initial patch by Nitish Chandra.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_print.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py index 7bc23cf..e838112 100644 --- a/Lib/test/test_print.py +++ b/Lib/test/test_print.py @@ -165,6 +165,23 @@ class TestPy2MigrationHint(unittest.TestCase): self.assertIn('print("Hello World")', str(context.exception)) + # bpo-32685: Suggestions for print statement should be proper when + # it is in the same line as the header of a compound statement + # and/or followed by a semicolon + def test_string_with_semicolon(self): + python2_print_str = 'print p;' + with self.assertRaises(SyntaxError) as context: + exec(python2_print_str) + + self.assertIn('print(p)', str(context.exception)) + + def test_string_in_loop_on_same_line(self): + python2_print_str = 'for i in s: print i' + with self.assertRaises(SyntaxError) as context: + exec(python2_print_str) + + self.assertIn('print(i)', 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: |