From 5777d25030f366559c92014791c6206c70841fc7 Mon Sep 17 00:00:00 2001 From: Andy Neff Date: Wed, 22 Feb 2017 10:31:10 -0500 Subject: [PATCH] Add unit test for JSONEncoder for floats --- tests/test_encoders.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_encoders.py b/tests/test_encoders.py index 8f8694c47..31b8391d6 100644 --- a/tests/test_encoders.py +++ b/tests/test_encoders.py @@ -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"]'