diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2020-05-29 13:23:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 13:23:57 (GMT) |
commit | 895c9c1d438367722f74f437fda96767d770662b (patch) | |
tree | 8b4a46c98dda92716458b5d2f24ea907b736e577 /Lib/test/test_format.py | |
parent | 28316422124206f63ddd4b91f2e19c54b6e9cd9d (diff) | |
download | cpython-895c9c1d438367722f74f437fda96767d770662b.zip cpython-895c9c1d438367722f74f437fda96767d770662b.tar.gz cpython-895c9c1d438367722f74f437fda96767d770662b.tar.bz2 |
bpo-40780: Fix failure of _Py_dg_dtoa to remove trailing zeros (GH-20435)
* Fix failure of _Py_dg_dtoa to remove trailing zeros
* Add regression test and news entry
* Add explanation about why it's safe to strip trailing zeros
* Make code safer, clean up comments, add change note at top of file
* Nitpick: avoid implicit int-to-float conversion in tests
Diffstat (limited to 'Lib/test/test_format.py')
-rw-r--r-- | Lib/test/test_format.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 4559cd5..e9e5bb9 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -484,6 +484,17 @@ class FormatTest(unittest.TestCase): with self.assertRaises(ValueError) as cm: format(c, ".%sf" % (INT_MAX + 1)) + def test_g_format_has_no_trailing_zeros(self): + # regression test for bugs.python.org/issue40780 + self.assertEqual("%.3g" % 1505.0, "1.5e+03") + self.assertEqual("%#.3g" % 1505.0, "1.50e+03") + + self.assertEqual(format(1505.0, ".3g"), "1.5e+03") + self.assertEqual(format(1505.0, "#.3g"), "1.50e+03") + + self.assertEqual(format(12300050.0, ".6g"), "1.23e+07") + self.assertEqual(format(12300050.0, "#.6g"), "1.23000e+07") + if __name__ == "__main__": unittest.main() |