Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Converted doctest to unittest. Patch by Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7543eb95e6cb6c6dd4f900e0ecdfa71fa411cdea 1 parent bb00b28
Jannis Leidel authored September 10, 2010
26  tests/modeltests/choices/models.py
@@ -22,29 +22,3 @@ class Person(models.Model):
22 22
 
23 23
     def __unicode__(self):
24 24
         return self.name
25  
-
26  
-__test__ = {'API_TESTS':"""
27  
->>> a = Person(name='Adrian', gender='M')
28  
->>> a.save()
29  
->>> s = Person(name='Sara', gender='F')
30  
->>> s.save()
31  
->>> a.gender
32  
-'M'
33  
->>> s.gender
34  
-'F'
35  
->>> a.get_gender_display()
36  
-u'Male'
37  
->>> s.get_gender_display()
38  
-u'Female'
39  
-
40  
-# If the value for the field doesn't correspond to a valid choice,
41  
-# the value itself is provided as a display value.
42  
->>> a.gender = ''
43  
->>> a.get_gender_display()
44  
-u''
45  
-
46  
->>> a.gender = 'U'
47  
->>> a.get_gender_display()
48  
-u'U'
49  
-
50  
-"""}
23  tests/modeltests/choices/tests.py
... ...
@@ -0,0 +1,23 @@
  1
+from django.test import TestCase
  2
+
  3
+from models import Person
  4
+
  5
+
  6
+class ChoicesTests(TestCase):
  7
+    def test_display(self):
  8
+        a = Person.objects.create(name='Adrian', gender='M')
  9
+        s = Person.objects.create(name='Sara', gender='F')
  10
+        self.assertEqual(a.gender, 'M')
  11
+        self.assertEqual(s.gender, 'F')
  12
+        
  13
+        self.assertEqual(a.get_gender_display(), 'Male')
  14
+        self.assertEqual(s.get_gender_display(), 'Female')
  15
+        
  16
+        # If the value for the field doesn't correspond to a valid choice,
  17
+        # the value itself is provided as a display value.
  18
+        a.gender = ''
  19
+        self.assertEqual(a.get_gender_display(), '')
  20
+
  21
+        a.gender = 'U'
  22
+        self.assertEqual(a.get_gender_display(), 'U')
  23
+

0 notes on commit 7543eb9

Please sign in to comment.
Something went wrong with that request. Please try again.