From: Victor Stinner Date: Thu, 21 Sep 2023 19:45:18 +0000 (+0200) Subject: [3.11] gh-109546: Add more tests for formatting floats (GH-109548) (#109685) X-Git-Tag: v3.11.6~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=84d8fdb2661220ee6af8f23637363bed38a90ba7;p=thirdparty%2FPython%2Fcpython.git [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 beb5ec5817b645562ebbdd59f25683a93061c32c) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 304388e1f78c..c6af0b92a73a 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -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')