From c7d7b6da3cf388320ff1c817d80cce3b76ea5e08 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 12 May 2007 16:53:27 +0000 Subject: [PATCH] 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 --- django/test/testcases.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 788e215ca15..7df1784d642 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1,4 +1,5 @@ import re, doctest, unittest +import sys from urlparse import urlparse from django.db import transaction from django.core import management, mail @@ -45,16 +46,16 @@ class TestCase(unittest.TestCase): if hasattr(self, 'fixtures'): management.load_data(self.fixtures, verbosity=0) mail.outbox = [] - - def run(self, result=None): - """Wrapper around default run method to perform common Django test set up. - This means that user-defined Test Cases aren't required to include a call - to super().setUp(). - + + def __call__(self, result=None): + """ + Wrapper around default __call__ method to perform common Django test + set up. This means that user-defined Test Cases aren't required to + include a call to super().setUp(). """ self.client = Client() self._pre_setup() - super(TestCase, self).run(result) + super(TestCase, self).__call__(result) def assertRedirects(self, response, expected_path, status_code=302, target_status_code=200): """Assert that a response redirected to a specific URL, and that the @@ -108,7 +109,7 @@ class TestCase(unittest.TestCase): for err in errors: if field: if field in context[form].errors: - self.assertTrue(err in context[form].errors[field], + self.failUnless(err in context[form].errors[field], "The field '%s' on form '%s' in context %d does not contain the error '%s' (actual errors: %s)" % (field, form, i, err, list(context[form].errors[field]))) elif field in context[form].fields: @@ -117,7 +118,7 @@ class TestCase(unittest.TestCase): else: self.fail("The form '%s' in context %d does not contain the field '%s'" % (form, i, field)) else: - self.assertTrue(err in context[form].non_field_errors(), + self.failUnless(err in context[form].non_field_errors(), "The form '%s' in context %d does not contain the non-field error '%s' (actual errors: %s)" % (form, i, err, list(context[form].non_field_errors()))) if not found_form: @@ -127,7 +128,7 @@ class TestCase(unittest.TestCase): "Assert that the template with the provided name was used in rendering the response" if isinstance(response.template, list): template_names = [t.name for t in response.template] - self.assertTrue(template_name in template_names, + self.failUnless(template_name in template_names, "Template '%s' was not one of the templates used to render the response. Templates used: %s" % (template_name, template_names)) elif response.template: @@ -140,9 +141,9 @@ class TestCase(unittest.TestCase): def assertTemplateNotUsed(self, response, template_name): "Assert that the template with the provided name was NOT used in rendering the response" if isinstance(response.template, list): - self.assertFalse(template_name in [t.name for t in response.template], + self.failIf(template_name in [t.name for t in response.template], "Template '%s' was used unexpectedly in rendering the response" % template_name) elif response.template: self.assertNotEqual(template_name, response.template.name, "Template '%s' was used unexpectedly in rendering the response" % template_name) - \ No newline at end of file +