Converted doctest to unittest. Patch by Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-09-10 20:54:01 +00:00
parent bb00b28399
commit 7543eb95e6
2 changed files with 23 additions and 26 deletions

View File

@ -22,29 +22,3 @@ class Person(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
__test__ = {'API_TESTS':"""
>>> a = Person(name='Adrian', gender='M')
>>> a.save()
>>> s = Person(name='Sara', gender='F')
>>> s.save()
>>> a.gender
'M'
>>> s.gender
'F'
>>> a.get_gender_display()
u'Male'
>>> s.get_gender_display()
u'Female'
# If the value for the field doesn't correspond to a valid choice,
# the value itself is provided as a display value.
>>> a.gender = ''
>>> a.get_gender_display()
u''
>>> a.gender = 'U'
>>> a.get_gender_display()
u'U'
"""}

View File

@ -0,0 +1,23 @@
from django.test import TestCase
from models import Person
class ChoicesTests(TestCase):
def test_display(self):
a = Person.objects.create(name='Adrian', gender='M')
s = Person.objects.create(name='Sara', gender='F')
self.assertEqual(a.gender, 'M')
self.assertEqual(s.gender, 'F')
self.assertEqual(a.get_gender_display(), 'Male')
self.assertEqual(s.get_gender_display(), 'Female')
# If the value for the field doesn't correspond to a valid choice,
# the value itself is provided as a display value.
a.gender = ''
self.assertEqual(a.get_gender_display(), '')
a.gender = 'U'
self.assertEqual(a.get_gender_display(), 'U')