diff --git a/tests/test_encoders.py b/tests/test_encoders.py index 31b8391d6..61e049ae1 100644 --- a/tests/test_encoders.py +++ b/tests/test_encoders.py @@ -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"]'