summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2019-05-27 19:31:52 (GMT)
committerGitHub <noreply@github.com>2019-05-27 19:31:52 (GMT)
commit6f6ff8a56518a80da406aad6ac8364c046cc7f18 (patch)
tree645d87649541f53b0ea4180a5f886c84320453fa /Lib/test
parent695b1dd8cbf3a48fdb30ab96918a49b20b7ec3e7 (diff)
downloadcpython-6f6ff8a56518a80da406aad6ac8364c046cc7f18.zip
cpython-6f6ff8a56518a80da406aad6ac8364c046cc7f18.tar.gz
cpython-6f6ff8a56518a80da406aad6ac8364c046cc7f18.tar.bz2
bpo-37050: Remove expr_text from FormattedValue ast node, use Constant node instead (GH-13597)
When using the "=" debug functionality of f-strings, use another Constant node (or a merged constant node) instead of adding expr_text to the FormattedValue node.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_fstring.py18
-rw-r--r--Lib/test/test_future.py15
2 files changed, 27 insertions, 6 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 3484fce..c9e6e7d 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1150,6 +1150,24 @@ non-important content
self.assertRaises(SyntaxError, eval, "f'{C=]'")
+ # Make sure leading and following text works.
+ x = 'foo'
+ self.assertEqual(f'X{x=}Y', 'Xx='+repr(x)+'Y')
+
+ # Make sure whitespace around the = works.
+ self.assertEqual(f'X{x =}Y', 'Xx ='+repr(x)+'Y')
+ self.assertEqual(f'X{x= }Y', 'Xx= '+repr(x)+'Y')
+ self.assertEqual(f'X{x = }Y', 'Xx = '+repr(x)+'Y')
+
+ # These next lines contains tabs. Backslash escapes don't
+ # work in f-strings.
+ # patchcheck doens't like these tabs. So the only way to test
+ # this will be to dynamically created and exec the f-strings. But
+ # that's such a hassle I'll save it for another day. For now, convert
+ # the tabs to spaces just to shut up patchcheck.
+ #self.assertEqual(f'X{x =}Y', 'Xx\t='+repr(x)+'Y')
+ #self.assertEqual(f'X{x = }Y', 'Xx\t=\t'+repr(x)+'Y')
+
def test_walrus(self):
x = 20
# This isn't an assignment expression, it's 'x', with a format
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index dd148b6..303c5f7 100644
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -270,12 +270,6 @@ class AnnotationsFutureTestCase(unittest.TestCase):
eq("f'{x}'")
eq("f'{x!r}'")
eq("f'{x!a}'")
- eq("f'{x=!r}'")
- eq("f'{x=:}'")
- eq("f'{x=:.2f}'")
- eq("f'{x=!r}'")
- eq("f'{x=!a}'")
- eq("f'{x=!s:*^20}'")
eq('(yield from outside_of_generator)')
eq('(yield)')
eq('(yield a + b)')
@@ -290,6 +284,15 @@ class AnnotationsFutureTestCase(unittest.TestCase):
eq("(x:=10)")
eq("f'{(x:=10):=10}'")
+ # f-strings with '=' don't round trip very well, so set the expected
+ # result explicitely.
+ self.assertAnnotationEqual("f'{x=!r}'", expected="f'x={x!r}'")
+ self.assertAnnotationEqual("f'{x=:}'", expected="f'x={x:}'")
+ self.assertAnnotationEqual("f'{x=:.2f}'", expected="f'x={x:.2f}'")
+ self.assertAnnotationEqual("f'{x=!r}'", expected="f'x={x!r}'")
+ self.assertAnnotationEqual("f'{x=!a}'", expected="f'x={x!a}'")
+ self.assertAnnotationEqual("f'{x=!s:*^20}'", expected="f'x={x!s:*^20}'")
+
if __name__ == "__main__":
unittest.main()