mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Add unit test for JSONEncoder for floats
This commit is contained in:
parent
3f5c1425bc
commit
5777d25030
|
@ -1,3 +1,4 @@
|
||||||
|
import json
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
@ -92,3 +93,11 @@ class JSONEncoderTests(TestCase):
|
||||||
"""
|
"""
|
||||||
foo = MockList()
|
foo = MockList()
|
||||||
assert self.encoder.default(foo) == [1, 2, 3]
|
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"]'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user