Skip to content

Commit

Permalink
Add test for monkey-patched decimal in Python 2.7
Browse files Browse the repository at this point in the history
For #6105
  • Loading branch information
kbussell committed Aug 7, 2018
1 parent 6a42128 commit 602eec8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest
import pytz
from _pytest.monkeypatch import MonkeyPatch
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import QueryDict
from django.test import TestCase, override_settings
Expand All @@ -17,6 +18,11 @@
from rest_framework import exceptions, serializers
from rest_framework.fields import DjangoImageField, is_simple_callable

try:
import cdecimal
except ImportError:
cdecimal = False

try:
import typings
except ImportError:
Expand Down Expand Up @@ -1128,6 +1134,16 @@ def test_part_precision_string_quantized_value_for_decimal(self):
expected_digit_tuple = (0, (1, 2, 0, 0), -2)
assert value == expected_digit_tuple

@unittest.skipUnless(cdecimal, 'requires python 2.7')
def test_quantize_on_monkey_patched_cdecimal(self):
# Monkey-patch cdecimal to replace decimal in for DecimalField
monkeypatch = MonkeyPatch()

with monkeypatch.context() as m:
m.setattr('rest_framework.fields.decimal', cdecimal)
f = rest_framework.fields.DecimalField(max_digits=4, decimal_places=2)
f.quantize(cdecimal.Decimal('1.234'))


class TestNoDecimalPlaces(FieldValues):
valid_inputs = {
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ deps =
django20: Django>=2.0,<2.1
django21: Django>=2.1b1,<2.2
djangomaster: https://github.com/django/django/archive/master.tar.gz
py27: m3-cdecimal
-rrequirements/requirements-testing.txt
-rrequirements/requirements-optionals.txt

Expand Down

0 comments on commit 602eec8

Please sign in to comment.