1. Luke Plant
  2. django

Commits

jez...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed fabac7f

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

Backport from trunk (r13725).

  • Participants
  • Parent commits 6cb8e05
  • Branches releases/1.2.X

Comments (0)

Files changed (2)

File tests/modeltests/choices/models.py

View file
 
     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'
-
-"""}

File tests/modeltests/choices/tests.py

View file
+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')
+