Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions Lib/test/test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,24 @@ def flush(self):
raise RuntimeError
self.assertRaises(RuntimeError, print, 1, file=noflush(), flush=True)

def test_gh130163(self):
class X:
def __str__(self):
sys.stdout = StringIO()
support.gc_collect()
return 'foo'

with support.swap_attr(sys, 'stdout', None):
sys.stdout = StringIO() # the only reference
print(X()) # should not crash


class TestPy2MigrationHint(unittest.TestCase):
"""Test that correct hint is produced analogous to Python3 syntax,
if print statement is executed as in Python 2.
"""

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_normal_string(self):
python2_print_str = 'print "Hello World"'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -145,8 +155,7 @@ def test_normal_string(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_soft_space(self):
python2_print_str = 'print "Hello World",'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -155,8 +164,7 @@ def test_string_with_soft_space(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_excessive_whitespace(self):
python2_print_str = 'print "Hello World", '
with self.assertRaises(SyntaxError) as context:
Expand All @@ -165,8 +173,7 @@ def test_string_with_excessive_whitespace(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_leading_whitespace(self):
python2_print_str = '''if 1:
print "Hello World"
Expand All @@ -180,9 +187,7 @@ def test_string_with_leading_whitespace(self):
# 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

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_semicolon(self):
python2_print_str = 'print p;'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -191,8 +196,7 @@ def test_string_with_semicolon(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_in_loop_on_same_line(self):
python2_print_str = 'for i in s: print i'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -201,8 +205,7 @@ def test_string_in_loop_on_same_line(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_stream_redirection_hint_for_py2_migration(self):
# Test correct hint produced for Py2 redirection syntax
with self.assertRaises(TypeError) as context:
Expand Down
Loading