summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2017-07-03 07:49:50 (GMT)
committerGitHub <noreply@github.com>2017-07-03 07:49:50 (GMT)
commitbfdc6fdc0e76204caf2261f9cfa9d232fc23906a (patch)
tree65e8c431687d26af65833b3321a4d5a514bdbcd8 /Lib
parent03af4282423b1c287a194664f90496cfc9cf20c7 (diff)
downloadcpython-bfdc6fdc0e76204caf2261f9cfa9d232fc23906a.zip
cpython-bfdc6fdc0e76204caf2261f9cfa9d232fc23906a.tar.gz
cpython-bfdc6fdc0e76204caf2261f9cfa9d232fc23906a.tar.bz2
[3.6] bpo-30597: Show expected input in custom 'print' error message. (GH-2531)
(cherry picked from commit 3a7f03584ab75afbf5507970711c87042e423bb4)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_print.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py
index 7eea349..03f13b4 100644
--- a/Lib/test/test_print.py
+++ b/Lib/test/test_print.py
@@ -128,5 +128,33 @@ class TestPrint(unittest.TestCase):
raise RuntimeError
self.assertRaises(RuntimeError, print, 1, file=noflush(), flush=True)
+
+class TestPy2MigrationHint(unittest.TestCase):
+ """Test that correct hint is produced analogous to Python3 syntax,
+ if print statement is executed as in Python 2.
+ """
+
+ def test_normal_string(self):
+ python2_print_str = 'print "Hello World"'
+ with self.assertRaises(SyntaxError) as context:
+ exec(python2_print_str)
+
+ self.assertIn('print("Hello World")', str(context.exception))
+
+ def test_string_with_soft_space(self):
+ python2_print_str = 'print "Hello World",'
+ with self.assertRaises(SyntaxError) as context:
+ exec(python2_print_str)
+
+ self.assertIn('print("Hello World", end=" ")', str(context.exception))
+
+ def test_string_with_excessive_whitespace(self):
+ python2_print_str = 'print "Hello World", '
+ with self.assertRaises(SyntaxError) as context:
+ exec(python2_print_str)
+
+ self.assertIn('print("Hello World", end=" ")', str(context.exception))
+
+
if __name__ == "__main__":
unittest.main()