Permalink
Browse files

Removed unused local variables in tests.

  • Loading branch information...
1 parent 5f52590 commit 96d1d4e29275f4f5900f0725975d2ad0a4d05816 @timgraham timgraham committed Oct 19, 2013
Showing with 309 additions and 339 deletions.
  1. +1 −1 setup.cfg
  2. +1 −1 tests/deprecation/tests.py
  3. +5 −5 tests/expressions_regress/tests.py
  4. +1 −1 tests/extra_regress/tests.py
  5. +1 −1 tests/field_deconstruction/tests.py
  6. +3 −3 tests/file_storage/tests.py
  7. +3 −3 tests/file_uploads/tests.py
  8. +1 −1 tests/files/tests.py
  9. +4 −4 tests/forms_tests/tests/test_error_messages.py
  10. +2 −2 tests/forms_tests/tests/test_extra.py
  11. +0 −14 tests/forms_tests/tests/test_formsets.py
  12. +4 −4 tests/forms_tests/tests/tests.py
  13. +2 −3 tests/generic_inline_admin/tests.py
  14. +2 −2 tests/generic_relations/tests.py
  15. +2 −2 tests/generic_views/test_base.py
  16. +2 −2 tests/generic_views/test_dates.py
  17. +19 −21 tests/generic_views/test_edit.py
  18. +4 −4 tests/get_earliest_or_latest/tests.py
  19. +3 −3 tests/get_or_create/tests.py
  20. +3 −3 tests/i18n/tests.py
  21. +2 −2 tests/logging_tests/tests.py
  22. +3 −3 tests/lookup/tests.py
  23. +13 −13 tests/m2m_through/tests.py
  24. +2 −2 tests/many_to_many/tests.py
  25. +13 −13 tests/many_to_one/tests.py
  26. +5 −6 tests/many_to_one_regress/tests.py
  27. +1 −1 tests/middleware_exceptions/tests.py
  28. +1 −1 tests/model_fields/test_imagefield.py
  29. +1 −1 tests/model_fields/tests.py
  30. +7 −7 tests/model_forms/tests.py
  31. +2 −3 tests/model_forms_regress/tests.py
  32. +10 −10 tests/model_formsets/tests.py
  33. +2 −2 tests/model_formsets_regress/tests.py
  34. +2 −2 tests/model_inheritance_regress/tests.py
  35. +2 −2 tests/model_inheritance_select_related/tests.py
  36. +1 −1 tests/model_regress/tests.py
  37. +1 −1 tests/modeladmin/tests.py
  38. +22 −27 tests/multiple_database/tests.py
  39. +1 −1 tests/mutually_referential/tests.py
  40. +14 −14 tests/nested_foreign_keys/tests.py
  41. +7 −7 tests/null_fk_ordering/tests.py
  42. +2 −2 tests/null_queries/tests.py
  43. +1 −1 tests/order_with_respect_to/tests.py
  44. +7 −7 tests/ordering/tests.py
  45. +20 −22 tests/prefetch_related/tests.py
  46. +5 −5 tests/proxy_models/tests.py
  47. +33 −33 tests/queries/tests.py
  48. +3 −3 tests/requests/tests.py
  49. +2 −2 tests/reserved_names/tests.py
  50. +1 −1 tests/reverse_lookup/tests.py
  51. +1 −1 tests/schema/tests.py
  52. +1 −1 tests/select_for_update/tests.py
  53. +2 −3 tests/select_related_onetoone/tests.py
  54. +7 −7 tests/select_related_regress/tests.py
  55. +1 −1 tests/serializers/tests.py
  56. +3 −3 tests/serializers_regress/tests.py
  57. +1 −1 tests/signals/tests.py
  58. +2 −2 tests/sites_framework/tests.py
  59. +1 −1 tests/staticfiles_tests/tests.py
  60. +2 −2 tests/template_tests/test_response.py
  61. +3 −3 tests/template_tests/test_unicode.py
  62. +3 −4 tests/template_tests/tests.py
  63. +1 −1 tests/test_client/tests.py
  64. +2 −2 tests/test_client_regress/tests.py
  65. +1 −1 tests/test_client_regress/views.py
  66. +2 −2 tests/timezones/tests.py
  67. +2 −2 tests/urlpatterns_reverse/tests.py
  68. +0 −2 tests/utils_tests/test_datastructures.py
  69. +1 −1 tests/utils_tests/test_decorators.py
  70. +7 −7 tests/utils_tests/test_simplelazyobject.py
  71. +3 −3 tests/validation/test_unique.py
  72. +14 −14 tests/view_tests/views.py
View
@@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
[flake8]
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py
-ignore=E124,E125,E126,E127,E128,E225,E226,E241,E251,E302,E501,E203,E221,E227,E231,E261,E301,F401,F403,F841,W601
+ignore=E124,E125,E126,E127,E128,E225,E226,E241,E251,E302,E501,E203,E221,E227,E231,E261,E301,F401,F403,W601
[metadata]
license-file = LICENSE
@@ -168,7 +168,7 @@ def test_deprecated_request(self):
with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter('always')
request = RequestFactory().get('/')
- _ = request.REQUEST
+ request.REQUEST # evaluate
msgs = [str(warning.message) for warning in recorded]
self.assertEqual(msgs, [
@@ -351,39 +351,39 @@ def test_delta_update(self):
def test_delta_invalid_op_mult(self):
raised = False
try:
- r = repr(Experiment.objects.filter(end__lt=F('start')*self.deltas[0]))
+ repr(Experiment.objects.filter(end__lt=F('start')*self.deltas[0]))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to multiply datetime by timedelta.")
def test_delta_invalid_op_div(self):
raised = False
try:
- r = repr(Experiment.objects.filter(end__lt=F('start')/self.deltas[0]))
+ repr(Experiment.objects.filter(end__lt=F('start')/self.deltas[0]))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to divide datetime by timedelta.")
def test_delta_invalid_op_mod(self):
raised = False
try:
- r = repr(Experiment.objects.filter(end__lt=F('start') % self.deltas[0]))
+ repr(Experiment.objects.filter(end__lt=F('start') % self.deltas[0]))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to modulo divide datetime by timedelta.")
def test_delta_invalid_op_and(self):
raised = False
try:
- r = repr(Experiment.objects.filter(end__lt=F('start').bitand(self.deltas[0])))
+ repr(Experiment.objects.filter(end__lt=F('start').bitand(self.deltas[0])))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to binary and a datetime with a timedelta.")
def test_delta_invalid_op_or(self):
raised = False
try:
- r = repr(Experiment.objects.filter(end__lt=F('start').bitor(self.deltas[0])))
+ repr(Experiment.objects.filter(end__lt=F('start').bitor(self.deltas[0])))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to binary or a datetime with a timedelta.")
@@ -160,7 +160,7 @@ def test_dates_query(self):
columns, we can (and should) ignore those columns. They don't change
the result and cause incorrect SQL to be produced otherwise.
"""
- rm = RevisionableModel.objects.create(
+ RevisionableModel.objects.create(
title='First Revision',
when=datetime.datetime(2008, 9, 28, 10, 30, 0)
)
@@ -174,7 +174,7 @@ def test_integer_field(self):
self.assertEqual(kwargs, {})
def test_ip_address_field(self):
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
field = models.IPAddressField()
name, path, args, kwargs = field.deconstruct()
@@ -241,8 +241,8 @@ def test_listdir(self):
self.assertFalse(self.storage.exists('storage_test_2'))
self.assertFalse(self.storage.exists('storage_dir_1'))
- f = self.storage.save('storage_test_1', ContentFile('custom content'))
- f = self.storage.save('storage_test_2', ContentFile('custom content'))
+ self.storage.save('storage_test_1', ContentFile('custom content'))
+ self.storage.save('storage_test_2', ContentFile('custom content'))
os.mkdir(os.path.join(self.temp_dir, 'storage_dir_1'))
dirs, files = self.storage.listdir('')
@@ -428,7 +428,7 @@ def save_file(self, name):
def test_race_condition(self):
self.thread.start()
- name = self.save_file('conflict')
+ self.save_file('conflict')
self.thread.join()
self.assertTrue(self.storage.exists('conflict'))
self.assertTrue(self.storage.exists('conflict_1'))
@@ -335,7 +335,7 @@ class POSTAccessingHandler(client.ClientHandler):
"""A handler that'll access POST during an exception."""
def handle_uncaught_exception(self, request, resolver, exc_info):
ret = super(POSTAccessingHandler, self).handle_uncaught_exception(request, resolver, exc_info)
- p = request.POST
+ request.POST # evaluate
return ret
# Maybe this is a little more complicated that it needs to be; but if
@@ -356,7 +356,7 @@ def handle_uncaught_exception(self, request, resolver, exc_info):
'file_field': fp,
}
try:
- response = self.client.post('/file_uploads/upload_errors/', post_data)
+ self.client.post('/file_uploads/upload_errors/', post_data)
except reference_error.__class__ as err:
self.assertFalse(
str(err) == str(reference_error),
@@ -444,7 +444,7 @@ class MultiParserTests(unittest.TestCase):
def test_empty_upload_handlers(self):
# We're not actually parsing here; just checking if the parser properly
# instantiates with empty upload handlers.
- parser = MultiPartParser({
+ MultiPartParser({
'CONTENT_TYPE': 'multipart/form-data; boundary=_foo',
'CONTENT_LENGTH': '1'
}, StringIO('x'), [], 'utf-8')
View
@@ -170,7 +170,7 @@ def test_file_mode(self):
# See #14681, stdlib gzip module crashes if mode is set to None
file = SimpleUploadedFile("mode_test.txt", b"content")
self.assertFalse(hasattr(file, 'mode'))
- g = gzip.GzipFile(fileobj=file)
+ gzip.GzipFile(fileobj=file)
class FileMoveSafeTests(unittest.TestCase):
@@ -194,7 +194,7 @@ def test_ipaddressfield(self):
'required': 'REQUIRED',
'invalid': 'INVALID IP ADDRESS',
}
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
f = IPAddressField(error_messages=e)
self.assertFormErrors(['REQUIRED'], f.clean, '')
@@ -243,9 +243,9 @@ class ModelChoiceFieldErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
def test_modelchoicefield(self):
# Create choices for the model choice field tests below.
from forms_tests.models import ChoiceModel
- c1 = ChoiceModel.objects.create(pk=1, name='a')
- c2 = ChoiceModel.objects.create(pk=2, name='b')
- c3 = ChoiceModel.objects.create(pk=3, name='c')
+ ChoiceModel.objects.create(pk=1, name='a')
+ ChoiceModel.objects.create(pk=2, name='b')
+ ChoiceModel.objects.create(pk=3, name='c')
# ModelChoiceField
e = {
@@ -535,7 +535,7 @@ class ComplexFieldForm(Form):
self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00')
def test_ipaddress(self):
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
f = IPAddressField()
self.assertFormErrors(['This field is required.'], f.clean, '')
@@ -546,7 +546,7 @@ def test_ipaddress(self):
self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
f = IPAddressField(required=False)
self.assertEqual(f.clean(''), '')
@@ -336,20 +336,6 @@ def test_second_form_partially_filled_2(self):
def test_more_initial_data(self):
# The extra argument also works when the formset is pre-filled with initial
# data.
-
- data = {
- 'choices-TOTAL_FORMS': '3', # the number of forms rendered
- 'choices-INITIAL_FORMS': '0', # the number of forms with initial data
- 'choices-MIN_NUM_FORMS': '0', # min number of forms
- 'choices-MAX_NUM_FORMS': '0', # max number of forms
- 'choices-0-choice': 'Calexico',
- 'choices-0-votes': '100',
- 'choices-1-choice': '',
- 'choices-1-votes': '', # missing value
- 'choices-2-choice': '',
- 'choices-2-votes': '',
- }
-
initial = [{'choice': 'Calexico', 'votes': 100}]
ChoiceFormSet = formset_factory(Choice, extra=3)
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix='choices')
@@ -94,9 +94,9 @@ def test_no_empty_option(self):
def test_callable_initial_value(self):
"The initial value for a callable default returning a queryset is the pk (refs #13769)"
- obj1 = ChoiceOptionModel.objects.create(id=1, name='default')
- obj2 = ChoiceOptionModel.objects.create(id=2, name='option 2')
- obj3 = ChoiceOptionModel.objects.create(id=3, name='option 3')
+ ChoiceOptionModel.objects.create(id=1, name='default')
+ ChoiceOptionModel.objects.create(id=2, name='option 2')
+ ChoiceOptionModel.objects.create(id=3, name='option 3')
self.assertHTMLEqual(ChoiceFieldForm().as_p(), """<p><label for="id_choice">Choice:</label> <select name="choice" id="id_choice">
<option value="1" selected="selected">ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
@@ -120,7 +120,7 @@ def test_callable_initial_value(self):
def test_initial_instance_value(self):
"Initial instances for model fields may also be instances (refs #7287)"
- obj1 = ChoiceOptionModel.objects.create(id=1, name='default')
+ ChoiceOptionModel.objects.create(id=1, name='default')
obj2 = ChoiceOptionModel.objects.create(id=2, name='option 2')
obj3 = ChoiceOptionModel.objects.create(id=3, name='option 3')
self.assertHTMLEqual(ChoiceFieldForm(initial={
@@ -178,7 +178,6 @@ def testMaxNumParam(self):
With extra=5 and max_num=2, there should be only 2 forms.
"""
e = self._create_object(EpisodeMaxNum)
- inline_form_data = '<input type="hidden" name="generic_inline_admin-media-content_type-object_id-TOTAL_FORMS" value="2" id="id_generic_inline_admin-media-content_type-object_id-TOTAL_FORMS" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-INITIAL_FORMS" value="1" id="id_generic_inline_admin-media-content_type-object_id-INITIAL_FORMS" />'
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodemaxnum/%s/' % e.pk)
formset = response.context['inline_admin_formsets'][0].formset
self.assertEqual(formset.total_form_count(), 2)
@@ -422,13 +421,13 @@ class EpisodeAdmin(admin.ModelAdmin):
def get_formsets(self, request, obj=None):
# Catch the deprecation warning to force the usage of get_formsets
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
return super(EpisodeAdmin, self).get_formsets(request, obj)
ma = EpisodeAdmin(Episode, self.site)
inlines = ma.get_inline_instances(request)
- with warnings.catch_warnings(record=True) as w:
+ with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
for (formset, inline), other_inline in zip(ma.get_formsets_with_inlines(request), inlines):
self.assertIsInstance(formset, other_inline.get_formset(request).__class__)
@@ -19,7 +19,7 @@ def test_generic_relations(self):
platypus = Animal.objects.create(
common_name="Platypus", latin_name="Ornithorhynchus anatinus"
)
- eggplant = Vegetable.objects.create(name="Eggplant", is_yucky=True)
+ Vegetable.objects.create(name="Eggplant", is_yucky=True)
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
quartz = Mineral.objects.create(name="Quartz", hardness=7)
@@ -46,7 +46,7 @@ def test_generic_relations(self):
# Recall that the Mineral class doesn't have an explicit GenericRelation
# defined. That's OK, because you can create TaggedItems explicitly.
tag1 = TaggedItem.objects.create(content_object=quartz, tag="shiny")
- tag2 = TaggedItem.objects.create(content_object=quartz, tag="clearish")
+ TaggedItem.objects.create(content_object=quartz, tag="clearish")
# However, excluding GenericRelations means your lookups have to be a
# bit more explicit.
@@ -76,7 +76,7 @@ def test_no_init_kwargs(self):
Test that a view can't be accidentally instantiated before deployment
"""
try:
- view = SimpleView(key='value').as_view()
+ SimpleView(key='value').as_view()
self.fail('Should not be able to instantiate a view')
except AttributeError:
pass
@@ -86,7 +86,7 @@ def test_no_init_args(self):
Test that a view can't be accidentally instantiated before deployment
"""
try:
- view = SimpleView.as_view('value')
+ SimpleView.as_view('value')
self.fail('Should not be able to use non-keyword arguments instantiating a view')
except TypeError:
pass
@@ -12,7 +12,7 @@
def _make_books(n, base_date):
for i in range(n):
- b = Book.objects.create(
+ Book.objects.create(
name='Book %d' % i,
slug='book-%d' % i,
pages=100+i,
@@ -158,7 +158,7 @@ def test_year_view_empty(self):
def test_year_view_allow_future(self):
# Create a new book in the future
year = datetime.date.today().year + 1
- b = Book.objects.create(name="The New New Testement", pages=600, pubdate=datetime.date(year, 1, 1))
+ Book.objects.create(name="The New New Testement", pages=600, pubdate=datetime.date(year, 1, 1))
res = self.client.get('/dates/books/%s/' % year)
self.assertEqual(res.status_code, 404)
@@ -122,15 +122,15 @@ def test_create_with_special_properties(self):
def test_create_without_redirect(self):
try:
- res = self.client.post('/edit/authors/create/naive/',
- {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
+ self.client.post('/edit/authors/create/naive/',
+ {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
except ImproperlyConfigured:
pass
def test_create_restricted(self):
res = self.client.post('/edit/authors/create/restricted/',
- {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
+ {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, 'http://testserver/accounts/login/?next=/edit/authors/create/restricted/')
@@ -278,16 +278,15 @@ def test_update_with_special_properties(self):
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
def test_update_without_redirect(self):
- try:
- a = Author.objects.create(
- name='Randall Munroe',
- slug='randall-munroe',
- )
- res = self.client.post('/edit/author/%d/update/naive/' % a.pk,
+ a = Author.objects.create(
+ name='Randall Munroe',
+ slug='randall-munroe',
+ )
+ # Should raise exception -- No redirect URL provided, and no
+ # get_absolute_url provided
+ with self.assertRaises(ImproperlyConfigured):
+ self.client.post('/edit/author/%d/update/naive/' % a.pk,
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
- self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
- except ImproperlyConfigured:
- pass
def test_update_get_object(self):
a = Author.objects.create(
@@ -365,12 +364,11 @@ def test_delete_with_special_properties(self):
self.assertQuerysetEqual(Author.objects.all(), [])
def test_delete_without_redirect(self):
- try:
- a = Author.objects.create(
- name='Randall Munroe',
- slug='randall-munroe',
- )
- res = self.client.post('/edit/author/%d/delete/naive/' % a.pk)
- self.fail('Should raise exception -- No redirect URL provided, and no get_absolute_url provided')
- except ImproperlyConfigured:
- pass
+ a = Author.objects.create(
+ name='Randall Munroe',
+ slug='randall-munroe',
+ )
+ # Should raise exception -- No redirect URL provided, and no
+ # get_absolute_url provided
+ with self.assertRaises(ImproperlyConfigured):
+ self.client.post('/edit/author/%d/delete/naive/' % a.pk)
@@ -27,11 +27,11 @@ def test_earliest(self):
headline="Article 2", pub_date=datetime(2005, 7, 27),
expire_date=datetime(2005, 7, 28)
)
- a3 = Article.objects.create(
+ Article.objects.create(
headline="Article 3", pub_date=datetime(2005, 7, 28),
expire_date=datetime(2005, 8, 27)
)
- a4 = Article.objects.create(
+ Article.objects.create(
headline="Article 4", pub_date=datetime(2005, 7, 28),
expire_date=datetime(2005, 7, 30)
)
@@ -72,7 +72,7 @@ def test_latest(self):
headline="Article 1", pub_date=datetime(2005, 7, 26),
expire_date=datetime(2005, 9, 1)
)
- a2 = Article.objects.create(
+ Article.objects.create(
headline="Article 2", pub_date=datetime(2005, 7, 27),
expire_date=datetime(2005, 7, 28)
)
@@ -117,7 +117,7 @@ def test_latest(self):
def test_latest_manual(self):
# You can still use latest() with a model that doesn't have
# "get_latest_by" set -- just pass in the field name manually.
- p1 = Person.objects.create(name="Ralph", birthday=datetime(1950, 1, 1))
+ Person.objects.create(name="Ralph", birthday=datetime(1950, 1, 1))
p2 = Person.objects.create(name="Stephanie", birthday=datetime(1960, 2, 3))
self.assertRaises(AssertionError, Person.objects.latest)
self.assertEqual(Person.objects.latest("birthday"), p2)
Oops, something went wrong.

0 comments on commit 96d1d4e

Please sign in to comment.