[3.11] gh-109546: Add more tests for formatting floats (GH-109548) (#109685)

gh-109546: Add more tests for formatting floats (GH-109548)

(cherry picked from commit beb5ec5817)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Victor Stinner 2023-09-21 21:45:18 +02:00 committed by GitHub
parent ca8da713d5
commit 84d8fdb266
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -734,8 +734,13 @@ class FormatTestCase(unittest.TestCase):
lhs, rhs = map(str.strip, line.split('->'))
fmt, arg = lhs.split()
self.assertEqual(fmt % float(arg), rhs)
self.assertEqual(fmt % -float(arg), '-' + rhs)
f = float(arg)
self.assertEqual(fmt % f, rhs)
self.assertEqual(fmt % -f, '-' + rhs)
if fmt != '%r':
fmt2 = fmt[1:]
self.assertEqual(format(f, fmt2), rhs)
self.assertEqual(format(-f, fmt2), '-' + rhs)
def test_issue5864(self):
self.assertEqual(format(123.456, '.4'), '123.5')