Skip to content

Commit 8a38261

Browse files
committed
Add test to json.dump for newly added encode_float argument
1 parent ddb3786 commit 8a38261

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/test/test_json/test_dump.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ def __lt__(self, o):
5757
d[1337] = "true.dat"
5858
self.assertEqual(self.dumps(d, sort_keys=True), '{"1337": "true.dat"}')
5959

60+
# Issue 36841
61+
def test_encode_float(self):
62+
data = {0.88: 0.9, 0: 0.1}
63+
expected = '{"0.88": 0.9, "0": 0.1}'
64+
self.assertEqual(
65+
self.dumps(data, encode_float=None),
66+
expected
67+
)
68+
69+
data = {0.88: 0.9, 0: 0.1}
70+
expected = '{"1": 1, "0": 0}'
71+
self.assertEqual(
72+
self.dumps(data, encode_float=lambda x: str(round(x))),
73+
expected
74+
)
6075

6176
class TestPyDump(TestDump, PyTest): pass
6277

0 commit comments

Comments
 (0)