Skip to content

Commit 5777d25

Browse files
committed
Add unit test for JSONEncoder for floats
1 parent 3f5c142 commit 5777d25

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_encoders.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from datetime import date, datetime, timedelta
23
from decimal import Decimal
34
from uuid import uuid4
@@ -92,3 +93,11 @@ def test_encode_object_with_tolist(self):
9293
"""
9394
foo = MockList()
9495
assert self.encoder.default(foo) == [1, 2, 3]
96+
97+
def test_encode_float(self):
98+
"""
99+
Tests encoding floats with special values
100+
"""
101+
102+
f = [3.141592653, float('inf'), float('-inf'), float('nan')]
103+
assert json.dumps(f, cls=JSONEncoder) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'

0 commit comments

Comments
 (0)