Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Converted doctest to unittest. Patch by Alex Gaynor.

Backport from trunk (r13725).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13726 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ebda0e014a49bd26d08436ba222e2047e6b071c3 1 parent 19cce79
@jezdez jezdez authored
View
26 tests/modeltests/choices/models.py
@@ -22,29 +22,3 @@ class Person(models.Model):
def __unicode__(self):
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
23 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')
+
Please sign in to comment.
Something went wrong with that request. Please try again.