Ticket #7777: code_and_tests.diff

File code_and_tests.diff, 1.3 KB (added by Farhan Ahmad, 14 years ago)

Code for checking these cases and the accompanying tests.

  • django/forms/fields.py

     
    249249        except DecimalException:
    250250            raise ValidationError(self.error_messages['invalid'])
    251251
     252        # value != value => NaN is never equal to itself, all other decimals are.
     253        if value != value or value == Decimal("Inf") or value == Decimal("-Inf"):
     254            raise ValidationError(self.error_messages['invalid'])
     255       
    252256        sign, digittuple, exponent = value.as_tuple()
    253257        decimals = abs(exponent)
    254258        # digittuple doesn't include any leading zeros.
  • tests/regressiontests/forms/fields.py

     
    320320True
    321321>>> f.clean(Decimal('3.14')) == Decimal("3.14")
    322322True
     323>>> f.clean('NaN')
     324Traceback (most recent call last):
     325...
     326ValidationError: [u'Enter a number.']
     327>>> f.clean('Inf')
     328Traceback (most recent call last):
     329...
     330ValidationError: [u'Enter a number.']
     331>>> f.clean('-Inf')
     332Traceback (most recent call last):
     333...
     334ValidationError: [u'Enter a number.']
    323335>>> f.clean('a')
    324336Traceback (most recent call last):
    325337...
Back to Top