From ea34426ae789d31b036f58c8fd59ce299649e91e Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 16 Jun 2016 09:07:51 -0400 Subject: [PATCH] Fixed flake8 2.6 warnings. --- django/contrib/gis/db/backends/base/models.py | 8 ++++---- django/core/management/commands/migrate.py | 2 +- .../migrations/0002_create_test_models.py | 6 +++++- tests/servers/tests.py | 14 ++++---------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/django/contrib/gis/db/backends/base/models.py b/django/contrib/gis/db/backends/base/models.py index 85f4478534..befb493919 100644 --- a/django/contrib/gis/db/backends/base/models.py +++ b/django/contrib/gis/db/backends/base/models.py @@ -40,14 +40,14 @@ class SpatialRefSysMixin(object): try: self._srs = gdal.SpatialReference(self.wkt) return self.srs - except Exception as msg: - pass + except Exception as e: + msg = e try: self._srs = gdal.SpatialReference(self.proj4text) return self.srs - except Exception as msg: - pass + except Exception as e: + msg = e raise Exception('Could not get OSR SpatialReference from WKT: %s\nError:\n%s' % (self.wkt, msg)) else: diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index a1eb190eb1..b6c8748bff 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -213,7 +213,7 @@ class Command(BaseCommand): model_keys.append(model_key) post_migrate_apps.unregister_model(*model_key) post_migrate_apps.render_multiple([ - ModelState.from_model(apps.get_model(*model_key)) for model_key in model_keys + ModelState.from_model(apps.get_model(*model)) for model in model_keys ]) # Send the post_migrate signal, so individual apps can do whatever they need diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py index 3e6cbac246..69c5b17f77 100644 --- a/tests/postgres_tests/migrations/0002_create_test_models.py +++ b/tests/postgres_tests/migrations/0002_create_test_models.py @@ -3,7 +3,11 @@ from __future__ import unicode_literals from django.db import migrations, models -from ..fields import * # NOQA +from ..fields import ( + ArrayField, BigIntegerRangeField, DateRangeField, DateTimeRangeField, + FloatRangeField, HStoreField, IntegerRangeField, JSONField, + SearchVectorField, +) from ..models import TagField diff --git a/tests/servers/tests.py b/tests/servers/tests.py index 39faba2023..57573622b0 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -104,12 +104,9 @@ class LiveServerViews(LiveServerBase): Ensure that the LiveServerTestCase serves 404s. Refs #2879. """ - try: + with self.assertRaises(HTTPError) as err: self.urlopen('/') - except HTTPError as err: - self.assertEqual(err.code, 404, 'Expected 404 response') - else: - self.fail('Expected 404 response') + self.assertEqual(err.exception.code, 404, 'Expected 404 response') def test_view(self): """ @@ -133,12 +130,9 @@ class LiveServerViews(LiveServerBase): tries to access a static file that isn't explicitly put under STATIC_ROOT. """ - try: + with self.assertRaises(HTTPError) as err: self.urlopen('/static/another_app/another_app_static_file.txt') - except HTTPError as err: - self.assertEqual(err.code, 404, 'Expected 404 response') - else: - self.fail('Expected 404 response (got %d)' % err.code) + self.assertEqual(err.exception.code, 404, 'Expected 404 response') def test_media_files(self): """