Fixed #7920 -- Made tests compatible with Python 2.6's Decimal repr change, patch from Karen Tracey.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8190 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-08-02 04:48:14 +00:00
parent a500ade891
commit cbbd54d5cd
2 changed files with 42 additions and 38 deletions

View File

@ -308,18 +308,18 @@ ValidationError: [u'This field is required.']
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValidationError: [u'This field is required.'] ValidationError: [u'This field is required.']
>>> f.clean('1') >>> f.clean('1') == Decimal("1")
Decimal("1") True
>>> isinstance(f.clean('1'), Decimal) >>> isinstance(f.clean('1'), Decimal)
True True
>>> f.clean('23') >>> f.clean('23') == Decimal("23")
Decimal("23") True
>>> f.clean('3.14') >>> f.clean('3.14') == Decimal("3.14")
Decimal("3.14") True
>>> f.clean(3.14) >>> f.clean(3.14) == Decimal("3.14")
Decimal("3.14") True
>>> f.clean(Decimal('3.14')) >>> f.clean(Decimal('3.14')) == Decimal("3.14")
Decimal("3.14") True
>>> f.clean('a') >>> f.clean('a')
Traceback (most recent call last): Traceback (most recent call last):
... ...
@ -328,12 +328,12 @@ ValidationError: [u'Enter a number.']
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValidationError: [u'Enter a number.'] ValidationError: [u'Enter a number.']
>>> f.clean('1.0 ') >>> f.clean('1.0 ') == Decimal("1.0")
Decimal("1.0") True
>>> f.clean(' 1.0') >>> f.clean(' 1.0') == Decimal("1.0")
Decimal("1.0") True
>>> f.clean(' 1.0 ') >>> f.clean(' 1.0 ') == Decimal("1.0")
Decimal("1.0") True
>>> f.clean('1.0a') >>> f.clean('1.0a')
Traceback (most recent call last): Traceback (most recent call last):
... ...
@ -350,18 +350,18 @@ ValidationError: [u'Ensure that there are no more than 2 decimal places.']
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.']
>>> f.clean('-12.34') >>> f.clean('-12.34') == Decimal("-12.34")
Decimal("-12.34") True
>>> f.clean('-123.45') >>> f.clean('-123.45')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValidationError: [u'Ensure that there are no more than 4 digits in total.'] ValidationError: [u'Ensure that there are no more than 4 digits in total.']
>>> f.clean('-.12') >>> f.clean('-.12') == Decimal("-0.12")
Decimal("-0.12") True
>>> f.clean('-00.12') >>> f.clean('-00.12') == Decimal("-0.12")
Decimal("-0.12") True
>>> f.clean('-000.12') >>> f.clean('-000.12') == Decimal("-0.12")
Decimal("-0.12") True
>>> f.clean('-000.123') >>> f.clean('-000.123')
Traceback (most recent call last): Traceback (most recent call last):
... ...
@ -380,8 +380,8 @@ ValidationError: [u'Enter a number.']
>>> f.clean(None) >>> f.clean(None)
>>> f.clean('1') >>> f.clean('1') == Decimal("1")
Decimal("1") True
DecimalField accepts min_value and max_value just like IntegerField: DecimalField accepts min_value and max_value just like IntegerField:
>>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) >>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
@ -394,14 +394,14 @@ ValidationError: [u'Ensure this value is less than or equal to 1.5.']
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] ValidationError: [u'Ensure this value is greater than or equal to 0.5.']
>>> f.clean('1.5') >>> f.clean('1.5') == Decimal("1.5")
Decimal("1.5") True
>>> f.clean('0.5') >>> f.clean('0.5') == Decimal("0.5")
Decimal("0.5") True
>>> f.clean('.5') >>> f.clean('.5') == Decimal("0.5")
Decimal("0.5") True
>>> f.clean('00.50') >>> f.clean('00.50') == Decimal("0.50")
Decimal("0.50") True
# DateField ################################################################### # DateField ###################################################################

View File

@ -1,15 +1,19 @@
""" """
>>> from django.db.models.fields import * >>> from django.db.models.fields import *
>>> try:
... from decimal import Decimal
... except ImportError:
... from django.utils._decimal import Decimal
# DecimalField # DecimalField
>>> f = DecimalField(max_digits=4, decimal_places=2) >>> f = DecimalField(max_digits=4, decimal_places=2)
>>> f.to_python(3) >>> f.to_python(3) == Decimal("3")
Decimal("3") True
>>> f.to_python("3.14") >>> f.to_python("3.14") == Decimal("3.14")
Decimal("3.14") True
>>> f.to_python("abc") >>> f.to_python("abc")
Traceback (most recent call last): Traceback (most recent call last):