Ticket #4287: 4287_tests.diff

File 4287_tests.diff, 1.4 KB (added by Erin Kelly, 17 years ago)

Test cases for storing inf, -inf, nan in a FloatField

  • tests/regressiontests/datatypes/models.py

     
    1717    class Meta:
    1818        ordering = ('consumed_at',)
    1919
    20     def __str__(self):
     20    def __unicode__(self):
    2121        return self.name
    2222
     23
     24class FloatFieldModel(models.Model):
     25    """#4287: Test model for storing inf, -inf, nan in a FloatField."""
     26    field = models.FloatField()
     27
     28    def __unicode__(self):
     29        return unicode(self.field)
     30
     31
    2332__test__ = {'API_TESTS': """
    2433# No donuts are in the system yet.
    2534>>> Donut.objects.all()
     
    5665datetime.time(5, 30)
    5766>>> d3.consumed_at
    5867datetime.datetime(2007, 4, 20, 16, 19, 59)
     68
     69>>> import math
     70>>> f0 = FloatFieldModel(field=math.pi)
     71>>> f0.save()
     72
     73>>> f1 = FloatFieldModel(field=float('inf'))
     74>>> f1.save()
     75
     76>>> f2 = FloatFieldModel(field=float('-inf'))
     77>>> f2.save()
     78
     79>>> f3 = FloatFieldModel(field=float('nan'))
     80>>> f3.save()
     81
     82>>> FloatFieldModel.objects.all()
     83[<FloatFieldModel: 3.14159265359>, <FloatFieldModel: inf>, <FloatFieldModel: -inf>, <FloatFieldModel: nan>]
     84
     85>>> FloatFieldModel.objects.order_by('field')
     86[<FloatFieldModel: -inf>, <FloatFieldModel: 3.14159265359>, <FloatFieldModel: inf>, <FloatFieldModel: nan>]
     87
    5988"""}
Back to Top