]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-109546: Add more tests for formatting floats (GH-109548) (#109685)
authorVictor Stinner <vstinner@python.org>
Thu, 21 Sep 2023 19:45:18 +0000 (21:45 +0200)
committerGitHub <noreply@github.com>
Thu, 21 Sep 2023 19:45:18 +0000 (21:45 +0200)
gh-109546: Add more tests for formatting floats (GH-109548)

(cherry picked from commit beb5ec5817b645562ebbdd59f25683a93061c32c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_float.py

index 304388e1f78c9751771b534febbd54ef943c9aa8..c6af0b92a73ad8b0af825d9b5cc25d72b0f39ef1 100644 (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')