Skip to content

Commit 2237f29

Browse files
committed
Increase coverage
-Use encoder.encode instead of json.dumps. encoder.default can't be used to test floats
1 parent 5777d25 commit 2237f29

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/test_encoders.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import json
1+
# -*- coding: utf-8 -*-
2+
23
from datetime import date, datetime, timedelta
34
from decimal import Decimal
45
from uuid import uuid4
@@ -100,4 +101,12 @@ def test_encode_float(self):
100101
"""
101102

102103
f = [3.141592653, float('inf'), float('-inf'), float('nan')]
103-
assert json.dumps(f, cls=JSONEncoder) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'
104+
assert self.encoder.encode(f) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'
105+
106+
encoder = JSONEncoder(allow_nan=False)
107+
try:
108+
encoder.encode(f)
109+
except ValueError:
110+
pass
111+
else:
112+
assert False

0 commit comments

Comments
 (0)