From 6f0c59948101aff81917f3b84c77c071b0392f30 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 19 Sep 2023 08:09:11 +0300 Subject: [PATCH] gh-109546: Add more tests for formatting floats (GH-109548) (cherry picked from commit beb5ec5817b645562ebbdd59f25683a93061c32c) --- Lib/test/test_float.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 304388e1f78c97..c6af0b92a73ad8 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -734,8 +734,13 @@ def test_format_testfile(self): 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')