Skip to content

Commit

Permalink
Converted doctest to unittest. Patch by Alex Gaynor.
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Sep 10, 2010
1 parent bb00b28 commit 7543eb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
26 changes: 0 additions & 26 deletions tests/modeltests/choices/models.py
Expand Up @@ -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'
"""}
23 changes: 23 additions & 0 deletions tests/modeltests/choices/tests.py
@@ -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')

0 comments on commit 7543eb9

Please sign in to comment.