Skip to content

Update test_fstring.py from Cpython v3.11.2 #4828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2023
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
48 changes: 33 additions & 15 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,33 +663,51 @@ def test_missing_expression(self):
["f'{}'",
"f'{ }'"
"f' {} '",
"f'{!r}'",
"f'{ !r}'",
"f'{10:{ }}'",
"f' { } '",

# The Python parser ignores also the following
# whitespace characters in additional to a space.
"f'''{\t\f\r\n}'''",
])

# Different error messeges are raised when a specfier ('!', ':' or '=') is used after an empty expression
self.assertAllRaise(SyntaxError, "f-string: expression required before '!'",
["f'{!r}'",
"f'{ !r}'",
"f'{!}'",
"f'''{\t\f\r\n!a}'''",

# Catch empty expression before the
# missing closing brace.
"f'{!'",
"f'{!s:'",

# Catch the empty expression before the
# Catch empty expression before the
# invalid conversion.
"f'{!x}'",
"f'{ !xr}'",
"f'{!x:}'",
"f'{!x:a}'",
"f'{ !xr:}'",
"f'{ !xr:a}'",
])

"f'{!}'",
"f'{:}'",

# We find the empty expression before the
# missing closing brace.
"f'{!'",
"f'{!s:'",
self.assertAllRaise(SyntaxError, "f-string: expression required before ':'",
["f'{:}'",
"f'{ :!}'",
"f'{:2}'",
"f'''{\t\f\r\n:a}'''",
"f'{:'",
"f'{:x'",
])

self.assertAllRaise(SyntaxError, "f-string: expression required before '='",
["f'{=}'",
"f'{ =}'",
"f'{ =:}'",
"f'{ =!}'",
"f'''{\t\f\r\n=}'''",
"f'{='",
])

# Different error message is raised for other whitespace characters.
Expand Down Expand Up @@ -820,10 +838,10 @@ def test_no_escapes_for_braces(self):
Only literal curly braces begin an expression.
"""
# \x7b is '{'.
# TODO: RUSTPYTHON self.assertEqual(f'\x7b1+1}}', '{1+1}')
# TODO: RUSTPYTHON self.assertEqual(f'\x7b1+1', '{1+1')
# TODO: RUSTPYTHON self.assertEqual(f'\u007b1+1', '{1+1')
# TODO: RUSTPYTHON self.assertEqual(f'\N{LEFT CURLY BRACKET}1+1\N{RIGHT CURLY BRACKET}', '{1+1}')
self.assertEqual(f'\x7b1+1}}', '{1+1}')
self.assertEqual(f'\x7b1+1', '{1+1')
self.assertEqual(f'\u007b1+1', '{1+1')
self.assertEqual(f'\N{LEFT CURLY BRACKET}1+1\N{RIGHT CURLY BRACKET}', '{1+1}')

def test_newlines_in_expressions(self):
self.assertEqual(f'{0}', '0')
Expand Down