Django

Code

Changeset 5211

Show
Ignore:
Timestamp:
05/12/07 11:53:27 (2 years ago)
Author:
mtredinnick
Message:

Fixed the test harness to work with Python 2.3 again (tested that it still
works with 2.4 and 2.5 as well).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/test/testcases.py

    r5182 r5211  
    11import re, doctest, unittest 
     2import sys 
    23from urlparse import urlparse 
    34from django.db import transaction 
     
    4647            management.load_data(self.fixtures, verbosity=0) 
    4748        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(). 
    5455        """ 
    5556        self.client = Client() 
    5657        self._pre_setup() 
    57         super(TestCase, self).run(result) 
     58        super(TestCase, self).__call__(result) 
    5859 
    5960    def assertRedirects(self, response, expected_path, status_code=302, target_status_code=200): 
     
    109110                    if field: 
    110111                        if field in context[form].errors: 
    111                             self.assertTrue(err in context[form].errors[field],  
     112                            self.failUnless(err in context[form].errors[field],  
    112113                            "The field '%s' on form '%s' in context %d does not contain the error '%s' (actual errors: %s)" %  
    113114                                (field, form, i, err, list(context[form].errors[field]))) 
     
    118119                            self.fail("The form '%s' in context %d does not contain the field '%s'" % (form, i, field)) 
    119120                    else: 
    120                         self.assertTrue(err in context[form].non_field_errors(),  
     121                        self.failUnless(err in context[form].non_field_errors(),  
    121122                            "The form '%s' in context %d does not contain the non-field error '%s' (actual errors: %s)" %  
    122123                                (form, i, err, list(context[form].non_field_errors()))) 
     
    128129        if isinstance(response.template, list): 
    129130            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, 
    131132                "Template '%s' was not one of the templates used to render the response. Templates used: %s" % 
    132133                    (template_name, template_names)) 
     
    141142        "Assert that the template with the provided name was NOT used in rendering the response" 
    142143        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], 
    144145                "Template '%s' was used unexpectedly in rendering the response" % template_name) 
    145146        elif response.template: