Increase coverage

-Use encoder.encode instead of json.dumps. encoder.default can't be used to
test floats
This commit is contained in:
Andy Neff 2017-02-22 11:28:34 -05:00
parent 5777d25030
commit 80cf8f4d32

View File

@ -1,10 +1,12 @@
import json
# -*- coding: utf-8 -*-
from datetime import date, datetime, timedelta
from decimal import Decimal
from uuid import uuid4
import pytest
from django.test import TestCase
from django.utils import six
from django.utils.timezone import utc
from rest_framework.compat import coreapi
@ -100,4 +102,21 @@ class JSONEncoderTests(TestCase):
"""
f = [3.141592653, float('inf'), float('-inf'), float('nan')]
assert json.dumps(f, cls=JSONEncoder) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'
assert self.encoder.encode(f) == '[3.141592653, "Infinity", "-Infinity", "NaN"]'
encoder = JSONEncoder(allow_nan=False)
try:
encoder.encode(f)
except ValueError:
pass
else:
assert False
def test_encode_string(self):
"""
Tests encoding string
"""
if six.PY2:
encoder2 = JSONEncoder(encoding='latin_1', check_circular=False)
assert encoder2.encode(['foo☺']) == '["foo\\u00e2\\u0098\\u00ba"]'