mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Increase coverage
-Use encoder.encode instead of json.dumps. encoder.default can't be used to test floats
This commit is contained in:
parent
5777d25030
commit
80cf8f4d32
|
@ -1,10 +1,12 @@
|
||||||
import json
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.utils import six
|
||||||
from django.utils.timezone import utc
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
from rest_framework.compat import coreapi
|
from rest_framework.compat import coreapi
|
||||||
|
@ -100,4 +102,21 @@ class JSONEncoderTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
f = [3.141592653, float('inf'), float('-inf'), float('nan')]
|
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"]'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user