summaryrefslogtreecommitdiff
path: root/Lib/test/test_fstring.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-05-25 13:33:55 +0300
committerGitHub <noreply@github.com>2017-05-25 13:33:55 +0300
commit0cd7a3f196cf34d9bb0a52e61327f7fe289d9750 (patch)
tree8e1758a3b7a031a3c52545f8b5d462ddb08ad18e /Lib/test/test_fstring.py
parentd1c3c13fedaf62b71445ccd048e395aa4a7d510f (diff)
downloadcpython-git-0cd7a3f196cf34d9bb0a52e61327f7fe289d9750.tar.gz
bpo-29104: Fixed parsing backslashes in f-strings. (#490)
Diffstat (limited to 'Lib/test/test_fstring.py')
-rw-r--r--Lib/test/test_fstring.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 708ed25b52..25730029ae 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -361,6 +361,20 @@ f'{a * x()}'"""
self.assertEqual(f'2\x203', '2 3')
self.assertEqual(f'\x203', ' 3')
+ with self.assertWarns(DeprecationWarning): # invalid escape sequence
+ value = eval(r"f'\{6*7}'")
+ self.assertEqual(value, '\\42')
+ self.assertEqual(f'\\{6*7}', '\\42')
+ self.assertEqual(fr'\{6*7}', '\\42')
+
+ AMPERSAND = 'spam'
+ # Get the right unicode character (&), or pick up local variable
+ # depending on the number of backslashes.
+ self.assertEqual(f'\N{AMPERSAND}', '&')
+ self.assertEqual(f'\\N{AMPERSAND}', '\\Nspam')
+ self.assertEqual(fr'\N{AMPERSAND}', '\\Nspam')
+ self.assertEqual(f'\\\N{AMPERSAND}', '\\&')
+
def test_misformed_unicode_character_name(self):
# These test are needed because unicode names are parsed
# differently inside f-strings.