summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_print.py
diff options
context:
space:
mode:
authorSanyam Khurana <CuriousLearner@users.noreply.github.com>2017-06-20 13:31:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-06-20 13:31:32 (GMT)
commit3a7f03584ab75afbf5507970711c87042e423bb4 (patch)
treeab193606a8d7371fdf1650a7be10b541979b61a9 /Lib/test/test_print.py
parent90e01e50ef8a9e6c91f30d965563c378a4ad26de (diff)
downloadcpython-3a7f03584ab75afbf5507970711c87042e423bb4.zip
cpython-3a7f03584ab75afbf5507970711c87042e423bb4.tar.gz
cpython-3a7f03584ab75afbf5507970711c87042e423bb4.tar.bz2
bpo-30597: Show expected input in custom 'print' error message. (#2009)
Diffstat (limited to 'Lib/test/test_print.py')
-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()