Skip to content

Commit

Permalink
Restore accidentally-deleted test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Oct 25, 2023
1 parent deb20d0 commit 18e5c55
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Lib/test/test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,30 @@ def test_invalid_formats(self):
with self.assertRaises(ValueError):
format(fraction, spec)

@requires_IEEE_754
def test_float_format_testfile(self):
with open(format_testfile, encoding="utf-8") as testfile:
for line in testfile:
if line.startswith('--'):
continue
line = line.strip()
if not line:
continue

lhs, rhs = map(str.strip, line.split('->'))
fmt, arg = lhs.split()
if fmt == '%r':
continue
fmt2 = fmt[1:]
with self.subTest(fmt=fmt, arg=arg):
f = F(float(arg))
self.assertEqual(format(f, fmt2), rhs)
if f: # skip negative zero
self.assertEqual(format(-f, fmt2), '-' + rhs)
f = F(arg)
self.assertEqual(float(format(f, fmt2)), float(rhs))
self.assertEqual(float(format(-f, fmt2)), float('-' + rhs))


if __name__ == '__main__':
unittest.main()

0 comments on commit 18e5c55

Please sign in to comment.