Removed some more unused local vars

This commit is contained in:
Alex Gaynor 2013-09-08 12:20:01 -07:00
parent c687bf0620
commit 9d11522599
14 changed files with 56 additions and 56 deletions

View File

@ -696,7 +696,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Assigning polygon's exterior ring w/the new shell # Assigning polygon's exterior ring w/the new shell
poly.exterior_ring = new_shell poly.exterior_ring = new_shell
s = str(new_shell) # new shell is still accessible str(new_shell) # new shell is still accessible
self.assertEqual(poly.exterior_ring, new_shell) self.assertEqual(poly.exterior_ring, new_shell)
self.assertEqual(poly[0], new_shell) self.assertEqual(poly[0], new_shell)

View File

@ -2435,7 +2435,7 @@ class AdminActionsTest(TestCase):
'action': 'external_mail', 'action': 'external_mail',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
self.assertEqual(len(mail.outbox), 1) self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action') self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action')
@ -3679,10 +3679,10 @@ class RawIdFieldsTest(TestCase):
def test_limit_choices_to(self): def test_limit_choices_to(self):
"""Regression test for 14880""" """Regression test for 14880"""
actor = Actor.objects.create(name="Palin", age=27) actor = Actor.objects.create(name="Palin", age=27)
inquisition1 = Inquisition.objects.create(expected=True, Inquisition.objects.create(expected=True,
leader=actor, leader=actor,
country="England") country="England")
inquisition2 = Inquisition.objects.create(expected=False, Inquisition.objects.create(expected=False,
leader=actor, leader=actor,
country="Spain") country="Spain")
response = self.client.get('/test_admin/admin/admin_views/sketch/add/') response = self.client.get('/test_admin/admin/admin_views/sketch/add/')
@ -3872,7 +3872,7 @@ class GroupAdminTest(TestCase):
'name': 'newgroup', 'name': 'newgroup',
}) })
new_group = Group.objects.order_by('-id')[0] Group.objects.order_by('-id')[0]
self.assertRedirects(response, '/test_admin/admin/auth/group/') self.assertRedirects(response, '/test_admin/admin/auth/group/')
self.assertEqual(Group.objects.count(), group_count + 1) self.assertEqual(Group.objects.count(), group_count + 1)
@ -4229,7 +4229,7 @@ class AdminCustomSaveRelatedTests(TestCase):
'child_set-0-name': 'Paul', 'child_set-0-name': 'Paul',
'child_set-1-name': 'Catherine', 'child_set-1-name': 'Catherine',
} }
response = self.client.post('/test_admin/admin/admin_views/parent/add/', post) self.client.post('/test_admin/admin/admin_views/parent/add/', post)
self.assertEqual(1, Parent.objects.count()) self.assertEqual(1, Parent.objects.count())
self.assertEqual(2, Child.objects.count()) self.assertEqual(2, Child.objects.count())
@ -4251,7 +4251,7 @@ class AdminCustomSaveRelatedTests(TestCase):
'child_set-1-name': 'Catherine', 'child_set-1-name': 'Catherine',
'child_set-1-id': catherine.id, 'child_set-1-id': catherine.id,
} }
response = self.client.post('/test_admin/admin/admin_views/parent/%s/' % parent.id, post) self.client.post('/test_admin/admin/admin_views/parent/%s/' % parent.id, post)
children_names = list(Child.objects.order_by('name').values_list('name', flat=True)) children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
@ -4260,8 +4260,8 @@ class AdminCustomSaveRelatedTests(TestCase):
def test_should_be_able_to_edit_related_objects_on_changelist_view(self): def test_should_be_able_to_edit_related_objects_on_changelist_view(self):
parent = Parent.objects.create(name='Josh Rock') parent = Parent.objects.create(name='Josh Rock')
paul = Child.objects.create(parent=parent, name='Paul') Child.objects.create(parent=parent, name='Paul')
catherine = Child.objects.create(parent=parent, name='Catherine') Child.objects.create(parent=parent, name='Catherine')
post = { post = {
'form-TOTAL_FORMS': '1', 'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '1', 'form-INITIAL_FORMS': '1',
@ -4271,7 +4271,7 @@ class AdminCustomSaveRelatedTests(TestCase):
'_save': 'Save' '_save': 'Save'
} }
response = self.client.post('/test_admin/admin/admin_views/parent/', post) self.client.post('/test_admin/admin/admin_views/parent/', post)
children_names = list(Child.objects.order_by('name').values_list('name', flat=True)) children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
self.assertEqual('Josh Stone', Parent.objects.latest('id').name) self.assertEqual('Josh Stone', Parent.objects.latest('id').name)

View File

@ -531,11 +531,11 @@ class ModelTest(TestCase):
def test_year_lookup_edge_case(self): def test_year_lookup_edge_case(self):
# Edge-case test: A year lookup should retrieve all objects in # Edge-case test: A year lookup should retrieve all objects in
# the given year, including Jan. 1 and Dec. 31. # the given year, including Jan. 1 and Dec. 31.
a11 = Article.objects.create( Article.objects.create(
headline='Article 11', headline='Article 11',
pub_date=datetime(2008, 1, 1), pub_date=datetime(2008, 1, 1),
) )
a12 = Article.objects.create( Article.objects.create(
headline='Article 12', headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999), pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
) )
@ -591,15 +591,15 @@ class ModelTest(TestCase):
def test_extra_method_select_argument_with_dashes_and_values(self): def test_extra_method_select_argument_with_dashes_and_values(self):
# The 'select' argument to extra() supports names with dashes in # The 'select' argument to extra() supports names with dashes in
# them, as long as you use values(). # them, as long as you use values().
a10 = Article.objects.create( Article.objects.create(
headline="Article 10", headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45), pub_date=datetime(2005, 7, 31, 12, 30, 45),
) )
a11 = Article.objects.create( Article.objects.create(
headline='Article 11', headline='Article 11',
pub_date=datetime(2008, 1, 1), pub_date=datetime(2008, 1, 1),
) )
a12 = Article.objects.create( Article.objects.create(
headline='Article 12', headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999), pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
) )
@ -615,15 +615,15 @@ class ModelTest(TestCase):
# If you use 'select' with extra() and names containing dashes on a # If you use 'select' with extra() and names containing dashes on a
# query that's *not* a values() query, those extra 'select' values # query that's *not* a values() query, those extra 'select' values
# will silently be ignored. # will silently be ignored.
a10 = Article.objects.create( Article.objects.create(
headline="Article 10", headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45), pub_date=datetime(2005, 7, 31, 12, 30, 45),
) )
a11 = Article.objects.create( Article.objects.create(
headline='Article 11', headline='Article 11',
pub_date=datetime(2008, 1, 1), pub_date=datetime(2008, 1, 1),
) )
a12 = Article.objects.create( Article.objects.create(
headline='Article 12', headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999), pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
) )
@ -640,7 +640,7 @@ class ModelTest(TestCase):
""" """
notlazy = 'test' notlazy = 'test'
lazy = ugettext_lazy(notlazy) lazy = ugettext_lazy(notlazy)
reporter = Article.objects.create(headline=lazy, pub_date=datetime.now()) Article.objects.create(headline=lazy, pub_date=datetime.now())
article = Article.objects.get() article = Article.objects.get()
self.assertEqual(article.headline, notlazy) self.assertEqual(article.headline, notlazy)
# test that assign + save works with Promise objecs # test that assign + save works with Promise objecs

View File

@ -310,7 +310,7 @@ class BaseCacheTests(object):
# Don't want fields with callable as default to be called on cache write # Don't want fields with callable as default to be called on cache write
expensive_calculation.num_runs = 0 expensive_calculation.num_runs = 0
Poll.objects.all().delete() Poll.objects.all().delete()
my_poll = Poll.objects.create(question="What?") Poll.objects.create(question="What?")
self.assertEqual(expensive_calculation.num_runs, 1) self.assertEqual(expensive_calculation.num_runs, 1)
defer_qs = Poll.objects.all().defer('question') defer_qs = Poll.objects.all().defer('question')
self.assertEqual(defer_qs.count(), 1) self.assertEqual(defer_qs.count(), 1)
@ -323,14 +323,14 @@ class BaseCacheTests(object):
# Don't want fields with callable as default to be called on cache read # Don't want fields with callable as default to be called on cache read
expensive_calculation.num_runs = 0 expensive_calculation.num_runs = 0
Poll.objects.all().delete() Poll.objects.all().delete()
my_poll = Poll.objects.create(question="What?") Poll.objects.create(question="What?")
self.assertEqual(expensive_calculation.num_runs, 1) self.assertEqual(expensive_calculation.num_runs, 1)
defer_qs = Poll.objects.all().defer('question') defer_qs = Poll.objects.all().defer('question')
self.assertEqual(defer_qs.count(), 1) self.assertEqual(defer_qs.count(), 1)
self.cache.set('deferred_queryset', defer_qs) self.cache.set('deferred_queryset', defer_qs)
self.assertEqual(expensive_calculation.num_runs, 1) self.assertEqual(expensive_calculation.num_runs, 1)
runs_before_cache_read = expensive_calculation.num_runs runs_before_cache_read = expensive_calculation.num_runs
cached_polls = self.cache.get('deferred_queryset') self.cache.get('deferred_queryset')
# We only want the default expensive calculation run on creation and set # We only want the default expensive calculation run on creation and set
self.assertEqual(expensive_calculation.num_runs, runs_before_cache_read) self.assertEqual(expensive_calculation.num_runs, runs_before_cache_read)
@ -1776,7 +1776,7 @@ class CacheMiddlewareTest(IgnoreDeprecationWarningsMixin, TestCase):
time.sleep(2) time.sleep(2)
# ... the default cache will still hit # ... the default cache will still hit
cache = get_cache('default') get_cache('default')
response = default_view(request, '11') response = default_view(request, '11')
self.assertEqual(response.content, b'Hello World 1') self.assertEqual(response.content, b'Hello World 1')

View File

@ -21,7 +21,7 @@ class CommentAppAPITests(CommentTestCase):
) )
def testGetMissingCommentApp(self): def testGetMissingCommentApp(self):
with six.assertRaisesRegex(self, ImproperlyConfigured, 'missing_app'): with six.assertRaisesRegex(self, ImproperlyConfigured, 'missing_app'):
_ = comments.get_comment_app() comments.get_comment_app()
def testGetForm(self): def testGetForm(self):
self.assertEqual(comments.get_form(), CommentForm) self.assertEqual(comments.get_form(), CommentForm)

View File

@ -17,7 +17,7 @@ class CommentFeedTests(CommentTestCase):
site_2 = Site.objects.create(id=settings.SITE_ID+1, site_2 = Site.objects.create(id=settings.SITE_ID+1,
domain="example2.com", name="example2.com") domain="example2.com", name="example2.com")
# A comment for another site # A comment for another site
c5 = Comment.objects.create( Comment.objects.create(
content_type = ContentType.objects.get_for_model(Article), content_type = ContentType.objects.get_for_model(Article),
object_pk = "1", object_pk = "1",
user_name = "Joe Somebody", user_name = "Joe Somebody",

View File

@ -269,13 +269,13 @@ class AdminActionsTests(CommentTestCase):
u.save() u.save()
def testActionsNonModerator(self): def testActionsNonModerator(self):
comments = self.createSomeComments() self.createSomeComments()
self.client.login(username="normaluser", password="normaluser") self.client.login(username="normaluser", password="normaluser")
response = self.client.get("/admin/comments/comment/") response = self.client.get("/admin/comments/comment/")
self.assertNotContains(response, "approve_comments") self.assertNotContains(response, "approve_comments")
def testActionsModerator(self): def testActionsModerator(self):
comments = self.createSomeComments() self.createSomeComments()
makeModerator("normaluser") makeModerator("normaluser")
self.client.login(username="normaluser", password="normaluser") self.client.login(username="normaluser", password="normaluser")
response = self.client.get("/admin/comments/comment/") response = self.client.get("/admin/comments/comment/")
@ -283,7 +283,7 @@ class AdminActionsTests(CommentTestCase):
def testActionsDisabledDelete(self): def testActionsDisabledDelete(self):
"Tests a CommentAdmin where 'delete_selected' has been disabled." "Tests a CommentAdmin where 'delete_selected' has been disabled."
comments = self.createSomeComments() self.createSomeComments()
self.client.login(username="normaluser", password="normaluser") self.client.login(username="normaluser", password="normaluser")
response = self.client.get('/admin2/comments/comment/') response = self.client.get('/admin2/comments/comment/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)

View File

@ -376,7 +376,7 @@ class CsrfViewMiddlewareTest(TestCase):
logger.setLevel(logging.WARNING) logger.setLevel(logging.WARNING)
req = self._get_GET_no_csrf_cookie_request() req = self._get_GET_no_csrf_cookie_request()
resp = view(req) view(req)
finally: finally:
logger.removeHandler(test_handler) logger.removeHandler(test_handler)
logger.setLevel(old_log_level) logger.setLevel(old_log_level)

View File

@ -8,7 +8,7 @@ from .models import Person, Book, Car, PersonManager, PublishedBookManager
class CustomManagerTests(TestCase): class CustomManagerTests(TestCase):
def test_manager(self): def test_manager(self):
p1 = Person.objects.create(first_name="Bugs", last_name="Bunny", fun=True) Person.objects.create(first_name="Bugs", last_name="Bunny", fun=True)
p2 = Person.objects.create(first_name="Droopy", last_name="Dog", fun=False) p2 = Person.objects.create(first_name="Droopy", last_name="Dog", fun=False)
# Test a custom `Manager` method. # Test a custom `Manager` method.
@ -63,7 +63,7 @@ class CustomManagerTests(TestCase):
# manager # manager
self.assertIsInstance(p2.books, PublishedBookManager) self.assertIsInstance(p2.books, PublishedBookManager)
b1 = Book.published_objects.create( Book.published_objects.create(
title="How to program", author="Rodney Dangerfield", is_published=True title="How to program", author="Rodney Dangerfield", is_published=True
) )
b2 = Book.published_objects.create( b2 = Book.published_objects.create(
@ -85,8 +85,8 @@ class CustomManagerTests(TestCase):
lambda b: b.title lambda b: b.title
) )
c1 = Car.cars.create(name="Corvette", mileage=21, top_speed=180) Car.cars.create(name="Corvette", mileage=21, top_speed=180)
c2 = Car.cars.create(name="Neon", mileage=31, top_speed=100) Car.cars.create(name="Neon", mileage=31, top_speed=100)
self.assertQuerysetEqual( self.assertQuerysetEqual(
Car.cars.order_by("name"), [ Car.cars.order_by("name"), [

View File

@ -141,12 +141,12 @@ class CustomPKTests(TestCase):
def test_unicode_pk(self): def test_unicode_pk(self):
# Primary key may be unicode string # Primary key may be unicode string
bus = Business.objects.create(name='jaźń') Business.objects.create(name='jaźń')
def test_unique_pk(self): def test_unique_pk(self):
# The primary key must also obviously be unique, so trying to create a # The primary key must also obviously be unique, so trying to create a
# new object with the same primary key will fail. # new object with the same primary key will fail.
e = Employee.objects.create( Employee.objects.create(
employee_code=123, first_name="Frank", last_name="Jones" employee_code=123, first_name="Frank", last_name="Jones"
) )
sid = transaction.savepoint() sid = transaction.savepoint()

View File

@ -47,10 +47,10 @@ class DataTypesTestCase(TestCase):
def test_year_boundaries(self): def test_year_boundaries(self):
"""Year boundary tests (ticket #3689)""" """Year boundary tests (ticket #3689)"""
d = Donut.objects.create(name='Date Test 2007', Donut.objects.create(name='Date Test 2007',
baked_date=datetime.datetime(year=2007, month=12, day=31), baked_date=datetime.datetime(year=2007, month=12, day=31),
consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59)) consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
d1 = Donut.objects.create(name='Date Test 2006', Donut.objects.create(name='Date Test 2006',
baked_date=datetime.datetime(year=2006, month=1, day=1), baked_date=datetime.datetime(year=2006, month=1, day=1),
consumed_at=datetime.datetime(year=2006, month=1, day=1)) consumed_at=datetime.datetime(year=2006, month=1, day=1))
@ -60,7 +60,7 @@ class DataTypesTestCase(TestCase):
self.assertEqual("Date Test 2006", self.assertEqual("Date Test 2006",
Donut.objects.filter(baked_date__year=2006)[0].name) Donut.objects.filter(baked_date__year=2006)[0].name)
d2 = Donut.objects.create(name='Apple Fritter', Donut.objects.create(name='Apple Fritter',
consumed_at = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)) consumed_at = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59))
self.assertEqual(['Apple Fritter', 'Date Test 2007'], self.assertEqual(['Apple Fritter', 'Date Test 2007'],

View File

@ -216,8 +216,8 @@ class DeletionTests(TestCase):
r = R.objects.create(pk=1) r = R.objects.create(pk=1)
s1 = S.objects.create(pk=1, r=r) s1 = S.objects.create(pk=1, r=r)
s2 = S.objects.create(pk=2, r=r) s2 = S.objects.create(pk=2, r=r)
t1 = T.objects.create(pk=1, s=s1) T.objects.create(pk=1, s=s1)
t2 = T.objects.create(pk=2, s=s2) T.objects.create(pk=2, s=s2)
r.delete() r.delete()
self.assertEqual( self.assertEqual(
pre_delete_order, [(T, 2), (T, 1), (S, 2), (S, 1), (R, 1)] pre_delete_order, [(T, 2), (T, 1), (S, 2), (S, 1), (R, 1)]
@ -302,7 +302,7 @@ class DeletionTests(TestCase):
def test_hidden_related(self): def test_hidden_related(self):
r = R.objects.create() r = R.objects.create()
h = HiddenUser.objects.create(r=r) h = HiddenUser.objects.create(r=r)
p = HiddenUserProfile.objects.create(user=h) HiddenUserProfile.objects.create(user=h)
r.delete() r.delete()
self.assertEqual(HiddenUserProfile.objects.count(), 0) self.assertEqual(HiddenUserProfile.objects.count(), 0)

View File

@ -73,7 +73,7 @@ class DeleteCascadeTests(TestCase):
""" """
person = Person.objects.create(name='Nelson Mandela') person = Person.objects.create(name='Nelson Mandela')
award = Award.objects.create(name='Nobel', content_object=person) award = Award.objects.create(name='Nobel', content_object=person)
note = AwardNote.objects.create(note='a peace prize', AwardNote.objects.create(note='a peace prize',
award=award) award=award)
self.assertEqual(AwardNote.objects.count(), 1) self.assertEqual(AwardNote.objects.count(), 1)
person.delete() person.delete()
@ -93,7 +93,7 @@ class DeleteCascadeTests(TestCase):
paints = Toy.objects.create(name='Paints') paints = Toy.objects.create(name='Paints')
played = PlayedWith.objects.create(child=juan, toy=paints, played = PlayedWith.objects.create(child=juan, toy=paints,
date=datetime.date.today()) date=datetime.date.today())
note = PlayedWithNote.objects.create(played=played, PlayedWithNote.objects.create(played=played,
note='the next Jackson Pollock') note='the next Jackson Pollock')
self.assertEqual(PlayedWithNote.objects.count(), 1) self.assertEqual(PlayedWithNote.objects.count(), 1)
paints.delete() paints.delete()
@ -105,7 +105,7 @@ class DeleteCascadeTests(TestCase):
policy = Policy.objects.create(pk=1, policy_number="1234") policy = Policy.objects.create(pk=1, policy_number="1234")
version = Version.objects.create(policy=policy) version = Version.objects.create(policy=policy)
location = Location.objects.create(version=version) location = Location.objects.create(version=version)
item = Item.objects.create(version=version, location=location) Item.objects.create(version=version, location=location)
policy.delete() policy.delete()
@ -135,7 +135,7 @@ class DeleteCascadeTransactionTests(TransactionTestCase):
""" """
apple = Food.objects.create(name="apple") apple = Food.objects.create(name="apple")
eaten = Eaten.objects.create(food=apple, meal="lunch") Eaten.objects.create(food=apple, meal="lunch")
apple.delete() apple.delete()
self.assertFalse(Food.objects.exists()) self.assertFalse(Food.objects.exists())
@ -146,7 +146,7 @@ class LargeDeleteTests(TestCase):
def test_large_deletes(self): def test_large_deletes(self):
"Regression for #13309 -- if the number of objects > chunk size, deletion still occurs" "Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
for x in range(300): for x in range(300):
track = Book.objects.create(pagecount=x+100) Book.objects.create(pagecount=x+100)
# attach a signal to make sure we will not fast-delete # attach a signal to make sure we will not fast-delete
def noop(*args, **kwargs): def noop(*args, **kwargs):
pass pass

View File

@ -9,15 +9,15 @@ from .models import Tag, Celebrity, Fan, Staff, StaffTag
class DistinctOnTests(TestCase): class DistinctOnTests(TestCase):
def setUp(self): def setUp(self):
t1 = Tag.objects.create(name='t1') t1 = Tag.objects.create(name='t1')
t2 = Tag.objects.create(name='t2', parent=t1) Tag.objects.create(name='t2', parent=t1)
t3 = Tag.objects.create(name='t3', parent=t1) t3 = Tag.objects.create(name='t3', parent=t1)
t4 = Tag.objects.create(name='t4', parent=t3) Tag.objects.create(name='t4', parent=t3)
t5 = Tag.objects.create(name='t5', parent=t3) Tag.objects.create(name='t5', parent=t3)
p1_o1 = Staff.objects.create(id=1, name="p1", organisation="o1") p1_o1 = Staff.objects.create(id=1, name="p1", organisation="o1")
p2_o1 = Staff.objects.create(id=2, name="p2", organisation="o1") p2_o1 = Staff.objects.create(id=2, name="p2", organisation="o1")
p3_o1 = Staff.objects.create(id=3, name="p3", organisation="o1") p3_o1 = Staff.objects.create(id=3, name="p3", organisation="o1")
p1_o2 = Staff.objects.create(id=4, name="p1", organisation="o2") Staff.objects.create(id=4, name="p1", organisation="o2")
p1_o1.coworkers.add(p2_o1, p3_o1) p1_o1.coworkers.add(p2_o1, p3_o1)
StaffTag.objects.create(staff=p1_o1, tag=t1) StaffTag.objects.create(staff=p1_o1, tag=t1)
StaffTag.objects.create(staff=p1_o1, tag=t1) StaffTag.objects.create(staff=p1_o1, tag=t1)