Add unit test for JSONEncoder for floats

This commit is contained in:
Andy Neff 2017-02-22 10:31:10 -05:00
parent 3f5c1425bc
commit 5777d25030

View File

@ -1,3 +1,4 @@
import json
from datetime import date, datetime, timedelta
from decimal import Decimal
from uuid import uuid4
@ -92,3 +93,11 @@ class JSONEncoderTests(TestCase):
"""
foo = MockList()
assert self.encoder.default(foo) == [1, 2, 3]
def test_encode_float(self):
"""
Tests encoding floats with special values
"""
f = [3.141592653, float('inf'), float('-inf'), float('nan')]
assert json.dumps(f, cls=JSONEncoder) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'