Ticket #7920: decimal.diff

File decimal.diff, 3.4 KB (added by Karen Tracey <kmtracey@…>, 16 years ago)
  • tests/regressiontests/model_fields/tests.py

     
    11"""
    22>>> from django.db.models.fields import *
     3>>> from decimal import Decimal
    34
    45# DecimalField
    56
    67>>> f = DecimalField(max_digits=4, decimal_places=2)
    78
    8 >>> f.to_python(3)
    9 Decimal("3")
     9>>> f.to_python(3) == Decimal("3")
     10True
    1011
    11 >>> f.to_python("3.14")
    12 Decimal("3.14")
     12>>> f.to_python("3.14") == Decimal("3.14")
     13True
    1314
    1415>>> f.to_python("abc")
    1516Traceback (most recent call last):
  • tests/regressiontests/forms/fields.py

     
    308308Traceback (most recent call last):
    309309...
    310310ValidationError: [u'This field is required.']
    311 >>> f.clean('1')
    312 Decimal("1")
     311>>> f.clean('1') == Decimal("1")
     312True
    313313>>> isinstance(f.clean('1'), Decimal)
    314314True
    315 >>> f.clean('23')
    316 Decimal("23")
    317 >>> f.clean('3.14')
    318 Decimal("3.14")
    319 >>> f.clean(3.14)
    320 Decimal("3.14")
    321 >>> f.clean(Decimal('3.14'))
    322 Decimal("3.14")
     315>>> f.clean('23') == Decimal("23")
     316True
     317>>> f.clean('3.14') == Decimal("3.14")
     318True
     319>>> f.clean(3.14) == Decimal("3.14")
     320True
     321>>> f.clean(Decimal('3.14')) == Decimal("3.14")
     322True
    323323>>> f.clean('a')
    324324Traceback (most recent call last):
    325325...
     
    328328Traceback (most recent call last):
    329329...
    330330ValidationError: [u'Enter a number.']
    331 >>> f.clean('1.0 ')
    332 Decimal("1.0")
    333 >>> f.clean(' 1.0')
    334 Decimal("1.0")
    335 >>> f.clean(' 1.0 ')
    336 Decimal("1.0")
     331>>> f.clean('1.0 ') == Decimal("1.0")
     332True
     333>>> f.clean(' 1.0') == Decimal("1.0")
     334True
     335>>> f.clean(' 1.0 ') == Decimal("1.0")
     336True
    337337>>> f.clean('1.0a')
    338338Traceback (most recent call last):
    339339...
     
    350350Traceback (most recent call last):
    351351...
    352352ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.']
    353 >>> f.clean('-12.34')
    354 Decimal("-12.34")
     353>>> f.clean('-12.34') == Decimal("-12.34")
     354True
    355355>>> f.clean('-123.45')
    356356Traceback (most recent call last):
    357357...
    358358ValidationError: [u'Ensure that there are no more than 4 digits in total.']
    359 >>> f.clean('-.12')
    360 Decimal("-0.12")
    361 >>> f.clean('-00.12')
    362 Decimal("-0.12")
    363 >>> f.clean('-000.12')
    364 Decimal("-0.12")
     359>>> f.clean('-.12') == Decimal("-0.12")
     360True
     361>>> f.clean('-00.12') == Decimal("-0.12")
     362True
     363>>> f.clean('-000.12') == Decimal("-0.12")
     364True
    365365>>> f.clean('-000.123')
    366366Traceback (most recent call last):
    367367...
     
    380380
    381381>>> f.clean(None)
    382382
    383 >>> f.clean('1')
    384 Decimal("1")
     383>>> f.clean('1') == Decimal("1")
     384True
    385385
    386386DecimalField accepts min_value and max_value just like IntegerField:
    387387>>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
     
    394394Traceback (most recent call last):
    395395...
    396396ValidationError: [u'Ensure this value is greater than or equal to 0.5.']
    397 >>> f.clean('1.5')
    398 Decimal("1.5")
    399 >>> f.clean('0.5')
    400 Decimal("0.5")
    401 >>> f.clean('.5')
    402 Decimal("0.5")
    403 >>> f.clean('00.50')
    404 Decimal("0.50")
     397>>> f.clean('1.5') == Decimal("1.5")
     398True
     399>>> f.clean('0.5') == Decimal("0.5")
     400True
     401>>> f.clean('.5') == Decimal("0.5")
     402True
     403>>> f.clean('00.50') == Decimal("0.50")
     404True
    405405
    406406# DateField ###################################################################
    407407
Back to Top