diff options
| author | davfsa <davfsa@gmail.com> | 2021-05-03 07:08:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-03 07:08:20 +0200 |
| commit | 09628248e212ecb08a51d017bc67e4f37452d92a (patch) | |
| tree | 009f7ce149cc1fa9a2c676b9b94f8d901d1ae0e7 /tests/run/test_fstring.pyx | |
| parent | d8f4fed0c295cfa1a719356bc6015695eed65e73 (diff) | |
| download | cython-09628248e212ecb08a51d017bc67e4f37452d92a.tar.gz | |
Self documenting f-strings (GH-3939)
Closes https://github.com/cython/cython/issues/3796
Diffstat (limited to 'tests/run/test_fstring.pyx')
| -rw-r--r-- | tests/run/test_fstring.pyx | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/run/test_fstring.pyx b/tests/run/test_fstring.pyx index a670e2ccb..f5c95d3f6 100644 --- a/tests/run/test_fstring.pyx +++ b/tests/run/test_fstring.pyx @@ -10,6 +10,10 @@ import unittest import sys IS_PY2 = sys.version_info[0] < 3 +if IS_PY2: + # Define `ascii` as `repr` for Python2 as it functions + # the same way in that version. + ascii = repr from Cython.Build.Inline import cython_inline from Cython.TestUtils import CythonTest @@ -1122,8 +1126,7 @@ non-important content self.assertEqual(cy_eval('f"\\\n"'), '') self.assertEqual(cy_eval('f"\\\r"'), '') - """ - def __test_debug_conversion(self): + def test_debug_conversion(self): x = 'A string' self.assertEqual(f'{x=}', 'x=' + repr(x)) self.assertEqual(f'{x =}', 'x =' + repr(x)) @@ -1169,10 +1172,11 @@ non-important content self.assertEqual(f'{0!=1}', 'True') self.assertEqual(f'{0<=1}', 'True') self.assertEqual(f'{0>=1}', 'False') - self.assertEqual(f'{(x:="5")}', '5') - self.assertEqual(x, '5') - self.assertEqual(f'{(x:=5)}', '5') - self.assertEqual(x, 5) + # Walrus not implemented yet, skip + # self.assertEqual(f'{(x:="5")}', '5') + # self.assertEqual(x, '5') + # self.assertEqual(f'{(x:=5)}', '5') + # self.assertEqual(x, 5) self.assertEqual(f'{"="}', '=') x = 20 @@ -1226,7 +1230,7 @@ non-important content # 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 @@ -1234,6 +1238,8 @@ non-important content # spec of '=10'. self.assertEqual(f'{x:=10}', ' 20') + # Note to anyone going to enable these: please have a look to the test + # above this one for more walrus cases to enable. """ # This is an assignment expression, which requires parens. self.assertEqual(f'{(x:=10)}', '10') |
