summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2010-02-26 05:14:36 +0000
committerKaren Tracey <kmtracey@gmail.com>2010-02-26 05:14:36 +0000
commit6ca3154bcd14f377ba38f1199f6053ec94e59651 (patch)
tree7e5a1c384fc71b6afbc13c4ddaa15a63c7b5e02a /tests
parent6c031fbef7635732ebecf502520e31d519ab17b3 (diff)
[1.1.X] Fixed a bunch of Python 2.3 incompatibilities that had crept into the 1.1.X branch.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12595 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/test_client/models.py4
-rw-r--r--tests/regressiontests/datastructures/tests.py20
-rw-r--r--tests/regressiontests/defer_regress/models.py5
-rw-r--r--tests/regressiontests/generic_inline_admin/tests.py2
-rw-r--r--tests/regressiontests/generic_relations_regress/tests.py4
-rw-r--r--tests/regressiontests/localflavor/tests.py8
6 files changed, 32 insertions, 11 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index c51323d843..4291cc057a 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -141,12 +141,12 @@ class ClientTest(TestCase):
def test_redirect_http(self):
"GET a URL that redirects to an http URI"
response = self.client.get('/test_client/http_redirect_view/',follow=True)
- self.assertFalse(response.test_was_secure_request)
+ self.failIf(response.test_was_secure_request)
def test_redirect_https(self):
"GET a URL that redirects to an https URI"
response = self.client.get('/test_client/https_redirect_view/',follow=True)
- self.assertTrue(response.test_was_secure_request)
+ self.failUnless(response.test_was_secure_request)
def test_notfound_response(self):
"GET a URL that responds as '404:Not Found'"
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index a858e2469f..cbba99b611 100644
--- a/tests/regressiontests/datastructures/tests.py
+++ b/tests/regressiontests/datastructures/tests.py
@@ -42,7 +42,7 @@ MergeDict can merge MultiValueDicts
True
>>> sorted(mm.items(), key=lambda k: k[0])
[('key1', 'value1'), ('key2', 'value3'), ('key4', 'value6')]
->>> [(k,mm.getlist(k)) for k in sorted(mm)]
+>>> [(k,mm.getlist(k)) for k in sorted(mm.keys())]
[('key1', ['value1']), ('key2', ['value2', 'value3']), ('key4', ['value5', 'value6'])]
### MultiValueDict ##########################################################
@@ -106,7 +106,17 @@ True
>>> d.pop('one', 'missing')
'missing'
->>> SortedDict((i, i) for i in xrange(3))
+This SortedDict test tests that it works properly when called with a
+a generator expression. But having that syntax anywhere in the test
+when run under Python 2.3 will cause a SyntaxError. Thus the rigamorale
+with eval so that the test will run and test what it is intended to test
+when run on Pythons > 2.3, but not cause a SyntaxError when run on Python 2.3.
+>>> import sys
+>>> if sys.version_info[0] == 2 and sys.version_info[1] == 3:
+... arg = '[(i, i) for i in xrange(3)]'
+... else:
+... arg = '((i, i) for i in xrange(3))'
+>>> SortedDict(eval(arg))
{0: 0, 1: 1, 2: 2}
We don't know which item will be popped in popitem(), so we'll just check that
@@ -171,3 +181,9 @@ AttributeError: Object is immutable!
'Normal: a. Modified: *a'
"""
+
+try:
+ sorted
+except NameError:
+ from django.utils.itercompat import sorted # For Python 2.3
+
diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
index d9e7bc6249..c2745b1265 100644
--- a/tests/regressiontests/defer_regress/models.py
+++ b/tests/regressiontests/defer_regress/models.py
@@ -6,6 +6,11 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db import connection, models
+try:
+ sorted
+except NameError:
+ from django.utils.itercompat import sorted # For Python 2.3
+
class Item(models.Model):
name = models.CharField(max_length=15)
text = models.TextField(default="xyzzy")
diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
index 9b3e12d137..2df4ca0c1d 100644
--- a/tests/regressiontests/generic_inline_admin/tests.py
+++ b/tests/regressiontests/generic_inline_admin/tests.py
@@ -185,4 +185,4 @@ class NoInlineDeletionTest(TestCase):
inline = MediaPermanentInline(EpisodePermanent, fake_site)
fake_request = object()
formset = inline.get_formset(fake_request)
- self.assertFalse(formset.can_delete)
+ self.failIf(formset.can_delete)
diff --git a/tests/regressiontests/generic_relations_regress/tests.py b/tests/regressiontests/generic_relations_regress/tests.py
index 45e86746e5..e61618ae11 100644
--- a/tests/regressiontests/generic_relations_regress/tests.py
+++ b/tests/regressiontests/generic_relations_regress/tests.py
@@ -63,12 +63,12 @@ class GenericRelationTests(TestCase):
# search with a non-matching note and a matching org name
qs = Contact.objects.filter(Q(notes__note__icontains=r'other note') |
Q(organizations__name__icontains=r'org name'))
- self.assertTrue(org_contact in qs)
+ self.failUnless(org_contact in qs)
# search again, with the same query parameters, in reverse order
qs = Contact.objects.filter(
Q(organizations__name__icontains=r'org name') |
Q(notes__note__icontains=r'other note'))
- self.assertTrue(org_contact in qs)
+ self.failUnless(org_contact in qs)
diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py
index 0ea3c52568..7d1080fd8b 100644
--- a/tests/regressiontests/localflavor/tests.py
+++ b/tests/regressiontests/localflavor/tests.py
@@ -5,19 +5,19 @@ from forms import PlaceForm
class USLocalflavorTests(TestCase):
def setUp(self):
self.form = PlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'})
-
+
def test_get_display_methods(self):
"""Test that the get_*_display() methods are added to the model instances."""
place = self.form.save()
self.assertEqual(place.get_state_display(), 'Georgia')
self.assertEqual(place.get_state_req_display(), 'North Carolina')
-
+
def test_required(self):
"""Test that required USStateFields throw appropriate errors."""
form = PlaceForm({'state':'GA', 'name':'Place in GA'})
- self.assertFalse(form.is_valid())
+ self.failIf(form.is_valid())
self.assertEqual(form.errors['state_req'], [u'This field is required.'])
-
+
def test_field_blank_option(self):
"""Test that the empty option is there."""
state_select_html = """\