Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Migrated properties doctests. Thanks to George Sakkis for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14165 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c830dbe39fe078e910291c855c97baabc74953d2 1 parent cdfbe79
Russell Keith-Magee authored October 12, 2010
19  tests/modeltests/properties/models.py
@@ -19,22 +19,3 @@ def _set_full_name(self, combined_name):
19 19
     full_name = property(_get_full_name)
20 20
 
21 21
     full_name_2 = property(_get_full_name, _set_full_name)
22  
-
23  
-__test__ = {'API_TESTS':"""
24  
->>> a = Person(first_name='John', last_name='Lennon')
25  
->>> a.save()
26  
->>> a.full_name
27  
-'John Lennon'
28  
-
29  
-# The "full_name" property hasn't provided a "set" method.
30  
->>> a.full_name = 'Paul McCartney'
31  
-Traceback (most recent call last):
32  
-    ...
33  
-AttributeError: can't set attribute
34  
-
35  
-# But "full_name_2" has, and it can be used to initialise the class.
36  
->>> a2 = Person(full_name_2 = 'Paul McCartney')
37  
->>> a2.save()
38  
->>> a2.first_name
39  
-'Paul'
40  
-"""}
20  tests/modeltests/properties/tests.py
... ...
@@ -0,0 +1,20 @@
  1
+from django.test import TestCase
  2
+from models import Person
  3
+
  4
+class PropertyTests(TestCase):
  5
+
  6
+    def setUp(self):
  7
+        self.a = Person(first_name='John', last_name='Lennon')
  8
+        self.a.save()
  9
+
  10
+    def test_getter(self):
  11
+        self.assertEqual(self.a.full_name, 'John Lennon')
  12
+
  13
+    def test_setter(self):
  14
+        # The "full_name" property hasn't provided a "set" method.
  15
+        self.assertRaises(AttributeError, setattr, self.a, 'full_name', 'Paul McCartney')
  16
+
  17
+        # But "full_name_2" has, and it can be used to initialise the class.
  18
+        a2 = Person(full_name_2 = 'Paul McCartney')
  19
+        a2.save()
  20
+        self.assertEqual(a2.first_name, 'Paul')

0 notes on commit c830dbe

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