Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed the test harness to work with Python 2.3 again (tested that it …

…still

works with 2.4 and 2.5 as well).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5211 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c7d7b6da3cf388320ff1c817d80cce3b76ea5e08 1 parent 3780a45
Malcolm Tredinnick authored May 12, 2007

Showing 1 changed file with 13 additions and 12 deletions. Show diff stats Hide diff stats

  1. 25  django/test/testcases.py
25  django/test/testcases.py
... ...
@@ -1,4 +1,5 @@
1 1
 import re, doctest, unittest
  2
+import sys
2 3
 from urlparse import urlparse
3 4
 from django.db import transaction
4 5
 from django.core import management, mail
@@ -45,16 +46,16 @@ def _pre_setup(self):
45 46
         if hasattr(self, 'fixtures'):
46 47
             management.load_data(self.fixtures, verbosity=0)
47 48
         mail.outbox = []
48  
-        
49  
-    def run(self, result=None):
50  
-        """Wrapper around default run method to perform common Django test set up.
51  
-        This means that user-defined Test Cases aren't required to include a call 
52  
-        to super().setUp().
53  
-        
  49
+
  50
+    def __call__(self, result=None):
  51
+        """
  52
+        Wrapper around default __call__ method to perform common Django test
  53
+        set up. This means that user-defined Test Cases aren't required to
  54
+        include a call to super().setUp().
54 55
         """
55 56
         self.client = Client()
56 57
         self._pre_setup()
57  
-        super(TestCase, self).run(result)
  58
+        super(TestCase, self).__call__(result)
58 59
 
59 60
     def assertRedirects(self, response, expected_path, status_code=302, target_status_code=200):
60 61
         """Assert that a response redirected to a specific URL, and that the
@@ -108,7 +109,7 @@ def assertFormError(self, response, form, field, errors):
108 109
                 for err in errors:
109 110
                     if field:
110 111
                         if field in context[form].errors:
111  
-                            self.assertTrue(err in context[form].errors[field], 
  112
+                            self.failUnless(err in context[form].errors[field], 
112 113
                             "The field '%s' on form '%s' in context %d does not contain the error '%s' (actual errors: %s)" % 
113 114
                                 (field, form, i, err, list(context[form].errors[field])))
114 115
                         elif field in context[form].fields:
@@ -117,7 +118,7 @@ def assertFormError(self, response, form, field, errors):
117 118
                         else:
118 119
                             self.fail("The form '%s' in context %d does not contain the field '%s'" % (form, i, field))
119 120
                     else:
120  
-                        self.assertTrue(err in context[form].non_field_errors(), 
  121
+                        self.failUnless(err in context[form].non_field_errors(), 
121 122
                             "The form '%s' in context %d does not contain the non-field error '%s' (actual errors: %s)" % 
122 123
                                 (form, i, err, list(context[form].non_field_errors())))
123 124
         if not found_form:
@@ -127,7 +128,7 @@ def assertTemplateUsed(self, response, template_name):
127 128
         "Assert that the template with the provided name was used in rendering the response"
128 129
         if isinstance(response.template, list):
129 130
             template_names = [t.name for t in response.template]
130  
-            self.assertTrue(template_name in template_names,
  131
+            self.failUnless(template_name in template_names,
131 132
                 "Template '%s' was not one of the templates used to render the response. Templates used: %s" %
132 133
                     (template_name, template_names))
133 134
         elif response.template:
@@ -140,9 +141,9 @@ def assertTemplateUsed(self, response, template_name):
140 141
     def assertTemplateNotUsed(self, response, template_name):
141 142
         "Assert that the template with the provided name was NOT used in rendering the response"
142 143
         if isinstance(response.template, list):            
143  
-            self.assertFalse(template_name in [t.name for t in response.template],
  144
+            self.failIf(template_name in [t.name for t in response.template],
144 145
                 "Template '%s' was used unexpectedly in rendering the response" % template_name)
145 146
         elif response.template:
146 147
             self.assertNotEqual(template_name, response.template.name,
147 148
                 "Template '%s' was used unexpectedly in rendering the response" % template_name)
148  
-        
  149
+        

0 notes on commit c7d7b6d

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