Skip to content

Commit 84d8fdb

Browse files
[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 beb5ec5) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent ca8da71 commit 84d8fdb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/test_float.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,13 @@ def test_format_testfile(self):
734734

735735
lhs, rhs = map(str.strip, line.split('->'))
736736
fmt, arg = lhs.split()
737-
self.assertEqual(fmt % float(arg), rhs)
738-
self.assertEqual(fmt % -float(arg), '-' + rhs)
737+
f = float(arg)
738+
self.assertEqual(fmt % f, rhs)
739+
self.assertEqual(fmt % -f, '-' + rhs)
740+
if fmt != '%r':
741+
fmt2 = fmt[1:]
742+
self.assertEqual(format(f, fmt2), rhs)
743+
self.assertEqual(format(-f, fmt2), '-' + rhs)
739744

740745
def test_issue5864(self):
741746
self.assertEqual(format(123.456, '.4'), '123.5')

0 commit comments

Comments
 (0)