Fixed #16196 - Redundant or incorrect code in tests

Thanks to intelliyole and melinath for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16354 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2011-06-10 10:18:06 +00:00
parent 9e952be26f
commit 430b819967
11 changed files with 24 additions and 29 deletions

View File

@ -131,7 +131,7 @@ class DummyCacheTests(unittest.TestCase):
u'ascii': u'ascii_value', u'ascii': u'ascii_value',
u'unicode_ascii': u'Iñtërnâtiônàlizætiøn1', u'unicode_ascii': u'Iñtërnâtiônàlizætiøn1',
u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2', u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2',
u'ascii': {u'x' : 1 } u'ascii2': {u'x' : 1 }
} }
for (key, value) in stuff.items(): for (key, value) in stuff.items():
self.cache.set(key, value) self.cache.set(key, value)
@ -317,7 +317,7 @@ class BaseCacheTests(object):
u'ascii': u'ascii_value', u'ascii': u'ascii_value',
u'unicode_ascii': u'Iñtërnâtiônàlizætiøn1', u'unicode_ascii': u'Iñtërnâtiônàlizætiøn1',
u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2', u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2',
u'ascii': {u'x' : 1 } u'ascii2': {u'x' : 1 }
} }
# Test `set` # Test `set`
for (key, value) in stuff.items(): for (key, value) in stuff.items():

View File

@ -54,7 +54,7 @@ class DeleteLockingTest(TransactionTestCase):
# Delete something using connection 2. # Delete something using connection 2.
cursor2 = self.conn2.cursor() cursor2 = self.conn2.cursor()
cursor2.execute('DELETE from delete_regress_book WHERE id=1') cursor2.execute('DELETE from delete_regress_book WHERE id=1')
self.conn2._commit(); self.conn2._commit()
# Now perform a queryset delete that covers the object # Now perform a queryset delete that covers the object
# deleted in connection 2. This causes an infinite loop # deleted in connection 2. This causes an infinite loop

View File

@ -92,7 +92,6 @@ class ARLocalFlavorTests(LocalFlavorTestCase):
'20-10123456': error_format, '20-10123456': error_format,
'20-10123456-': error_format, '20-10123456-': error_format,
'20-10123456-5': error_invalid, '20-10123456-5': error_invalid,
'2-10123456-9': error_format,
'27-10345678-1': error_invalid, '27-10345678-1': error_invalid,
u'27-10345678-1': error_invalid, u'27-10345678-1': error_invalid,
} }

View File

@ -133,7 +133,6 @@ class IDLocalFlavorTests(LocalFlavorTestCase):
invalid = { invalid = {
'0123456789': error_invalid, '0123456789': error_invalid,
'+62-021-3456789': error_invalid, '+62-021-3456789': error_invalid,
'+62-021-3456789': error_invalid,
'+62-0812-3456789': error_invalid, '+62-0812-3456789': error_invalid,
'0812345678901': error_invalid, '0812345678901': error_invalid,
'foo': error_invalid, 'foo': error_invalid,

View File

@ -19,7 +19,6 @@ class PTLocalFlavorTests(LocalFlavorTestCase):
def test_PTPhoneNumberField(self): def test_PTPhoneNumberField(self):
error_format = [u'Phone numbers must have 9 digits, or start by + or 00.'] error_format = [u'Phone numbers must have 9 digits, or start by + or 00.']
valid = { valid = {
'917845189': '917845189',
'917845189': '917845189', '917845189': '917845189',
'91 784 5189': '917845189', '91 784 5189': '917845189',
'+351 91 111': '+35191111', '+351 91 111': '+35191111',

View File

@ -42,7 +42,7 @@ class DictList(generic.ListView):
"""A ListView that doesn't use a model.""" """A ListView that doesn't use a model."""
queryset = [ queryset = [
{'first': 'John', 'last': 'Lennon'}, {'first': 'John', 'last': 'Lennon'},
{'last': 'Yoko', 'last': 'Ono'} {'first': 'Yoko', 'last': 'Ono'}
] ]
template_name = 'generic_views/list.html' template_name = 'generic_views/list.html'
@ -65,7 +65,7 @@ class CustomPaginator(Paginator):
allow_empty_first_page=allow_empty_first_page) allow_empty_first_page=allow_empty_first_page)
class AuthorListCustomPaginator(AuthorList): class AuthorListCustomPaginator(AuthorList):
paginate_by = 5; paginate_by = 5
def get_paginator(self, queryset, page_size, orphans=0, allow_empty_first_page=True): def get_paginator(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
return super(AuthorListCustomPaginator, self).get_paginator( return super(AuthorListCustomPaginator, self).get_paginator(

View File

@ -45,7 +45,7 @@ class IntrospectionTests(TestCase):
def test_django_table_names(self): def test_django_table_names(self):
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute('CREATE TABLE django_ixn_test_table (id INTEGER);'); cursor.execute('CREATE TABLE django_ixn_test_table (id INTEGER);')
tl = connection.introspection.django_table_names() tl = connection.introspection.django_table_names()
cursor.execute("DROP TABLE django_ixn_test_table;") cursor.execute("DROP TABLE django_ixn_test_table;")
self.assertTrue('django_ixn_testcase_table' not in tl, self.assertTrue('django_ixn_testcase_table' not in tl,

View File

@ -48,8 +48,7 @@ class ModelTests(TestCase):
article_text = "ABCDE" * 1000 article_text = "ABCDE" * 1000
) )
a = Article.objects.get(pk=a.pk) a = Article.objects.get(pk=a.pk)
self.assertEqual self.assertEqual(len(a.article_text), 5000)
(len(a.article_text), 5000)
def test_date_lookup(self): def test_date_lookup(self):
# Regression test for #659 # Regression test for #659

View File

@ -1612,7 +1612,6 @@ class AntiPetRouter(object):
return model._meta.object_name == 'Pet' return model._meta.object_name == 'Pet'
else: else:
return model._meta.object_name != 'Pet' return model._meta.object_name != 'Pet'
return None
class FixtureTestCase(TestCase): class FixtureTestCase(TestCase):
multi_db = True multi_db = True

View File

@ -25,7 +25,7 @@ class FeedTestCase(TestCase):
elem.getElementsByTagName(k)[0].firstChild.wholeText, v) elem.getElementsByTagName(k)[0].firstChild.wholeText, v)
def assertCategories(self, elem, expected): def assertCategories(self, elem, expected):
self.assertEqual(set(i.firstChild.wholeText for i in elem.childNodes if i.nodeName == 'category'), set(expected)); self.assertEqual(set(i.firstChild.wholeText for i in elem.childNodes if i.nodeName == 'category'), set(expected))
###################################### ######################################
# Feed view # Feed view
@ -73,7 +73,7 @@ class SyndicationFeedTest(FeedTestCase):
'ttl': '600', 'ttl': '600',
'copyright': 'Copyright (c) 2007, Sally Smith', 'copyright': 'Copyright (c) 2007, Sally Smith',
}) })
self.assertCategories(chan, ['python', 'django']); self.assertCategories(chan, ['python', 'django'])
# Ensure the content of the channel is correct # Ensure the content of the channel is correct
self.assertChildNodeContent(chan, { self.assertChildNodeContent(chan, {
@ -102,7 +102,7 @@ class SyndicationFeedTest(FeedTestCase):
'pubDate': pub_date, 'pubDate': pub_date,
'author': 'test@example.com (Sally Smith)', 'author': 'test@example.com (Sally Smith)',
}) })
self.assertCategories(items[0], ['python', 'testing']); self.assertCategories(items[0], ['python', 'testing'])
for item in items: for item in items:
self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'category', 'pubDate', 'author']) self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'category', 'pubDate', 'author'])

View File

@ -1282,7 +1282,7 @@ class Templates(unittest.TestCase):
'legacyi18n28': ('{% load i18n %}{% blocktrans with anton as a and berta as b %}{{ a }} + {{ b }}{% endblocktrans %}', {'anton': 'α', 'berta': 'β'}, u'α + β'), 'legacyi18n28': ('{% load i18n %}{% blocktrans with anton as a and berta as b %}{{ a }} + {{ b }}{% endblocktrans %}', {'anton': 'α', 'berta': 'β'}, u'α + β'),
# retrieving language information # retrieving language information
'i18n28': ('{% load i18n %}{% get_language_info for "de" as l %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {}, 'de: German/Deutsch bidi=False'), 'i18n28_2': ('{% load i18n %}{% get_language_info for "de" as l %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {}, 'de: German/Deutsch bidi=False'),
'i18n29': ('{% load i18n %}{% get_language_info for LANGUAGE_CODE as l %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {'LANGUAGE_CODE': 'fi'}, 'fi: Finnish/suomi bidi=False'), 'i18n29': ('{% load i18n %}{% get_language_info for LANGUAGE_CODE as l %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}', {'LANGUAGE_CODE': 'fi'}, 'fi: Finnish/suomi bidi=False'),
'i18n30': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': ['it', 'no']}, u'it: Italian/italiano bidi=False; no: Norwegian/Norsk bidi=False; '), 'i18n30': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': ['it', 'no']}, u'it: Italian/italiano bidi=False; no: Norwegian/Norsk bidi=False; '),
'i18n31': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': (('sl', 'Slovenian'), ('fa', 'Persian'))}, u'sl: Slovenian/Sloven\u0161\u010dina bidi=False; fa: Persian/\u0641\u0627\u0631\u0633\u06cc bidi=True; '), 'i18n31': ('{% load i18n %}{% get_language_info_list for langcodes as langs %}{% for l in langs %}{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}; {% endfor %}', {'langcodes': (('sl', 'Slovenian'), ('fa', 'Persian'))}, u'sl: Slovenian/Sloven\u0161\u010dina bidi=False; fa: Persian/\u0641\u0627\u0631\u0633\u06cc bidi=True; '),
@ -1298,7 +1298,7 @@ class Templates(unittest.TestCase):
'invalidstr02': ('{{ var|default_if_none:"Foo" }}', {}, ('','INVALID')), 'invalidstr02': ('{{ var|default_if_none:"Foo" }}', {}, ('','INVALID')),
'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''), 'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''),
'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'), 'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'),
'invalidstr04': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'), 'invalidstr04_2': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'),
'invalidstr05': ('{{ var }}', {}, ('', ('INVALID %s', 'var'))), 'invalidstr05': ('{{ var }}', {}, ('', ('INVALID %s', 'var'))),
'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', ('INVALID %s', 'var.prop'))), 'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', ('INVALID %s', 'var.prop'))),
@ -1323,12 +1323,12 @@ class Templates(unittest.TestCase):
"""), """),
### REGROUP TAG ########################################################### ### REGROUP TAG ###########################################################
'regroup01': ('{% regroup data by bar as grouped %}' + \ 'regroup01': ('{% regroup data by bar as grouped %}'
'{% for group in grouped %}' + \ '{% for group in grouped %}'
'{{ group.grouper }}:' + \ '{{ group.grouper }}:'
'{% for item in group.list %}' + \ '{% for item in group.list %}'
'{{ item.foo }}' + \ '{{ item.foo }}'
'{% endfor %},' + \ '{% endfor %},'
'{% endfor %}', '{% endfor %}',
{'data': [ {'foo':'c', 'bar':1}, {'data': [ {'foo':'c', 'bar':1},
{'foo':'d', 'bar':1}, {'foo':'d', 'bar':1},
@ -1338,12 +1338,12 @@ class Templates(unittest.TestCase):
'1:cd,2:ab,3:x,'), '1:cd,2:ab,3:x,'),
# Test for silent failure when target variable isn't found # Test for silent failure when target variable isn't found
'regroup02': ('{% regroup data by bar as grouped %}' + \ 'regroup02': ('{% regroup data by bar as grouped %}'
'{% for group in grouped %}' + \ '{% for group in grouped %}'
'{{ group.grouper }}:' + \ '{{ group.grouper }}:'
'{% for item in group.list %}' + \ '{% for item in group.list %}'
'{{ item.foo }}' + \ '{{ item.foo }}'
'{% endfor %},' + \ '{% endfor %},'
'{% endfor %}', '{% endfor %}',
{}, ''), {}, ''),
### SSI TAG ######################################################## ### SSI TAG ########################################################