From b67ab75e82ec59dd4eeca119eeaf570d7c88556c Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 11 Oct 2013 07:25:14 -0400 Subject: [PATCH] Fixed assorted flake8 errors. --- django/conf/locale/id/formats.py | 2 +- django/conf/locale/lv/formats.py | 2 +- django/contrib/gis/admin/options.py | 2 +- django/contrib/gis/gdal/geometries.py | 2 +- django/contrib/gis/gdal/srs.py | 2 +- django/contrib/gis/gdal/tests/test_geom.py | 2 +- django/contrib/gis/geos/polygon.py | 6 ++++-- .../gis/geos/tests/test_geos_mutation.py | 6 +++--- .../gis/geos/tests/test_mutable_list.py | 9 ++++++--- django/contrib/gis/maps/google/gmap.py | 2 +- django/contrib/gis/tests/distapp/tests.py | 2 +- django/contrib/gis/tests/geoapp/tests.py | 2 +- django/contrib/gis/tests/layermap/tests.py | 6 ++++-- django/contrib/gis/tests/test_geoforms.py | 14 +++++++------- django/contrib/gis/utils/wkt.py | 3 ++- django/core/files/uploadhandler.py | 2 ++ django/core/signing.py | 2 +- django/db/models/base.py | 2 +- django/db/models/fields/files.py | 5 ++++- django/dispatch/saferef.py | 4 ++-- django/forms/fields.py | 2 +- django/forms/widgets.py | 2 +- django/template/context.py | 2 +- django/templatetags/cache.py | 2 +- django/utils/autoreload.py | 6 +++++- extras/csrf_migration_helper.py | 2 +- tests/admin_changelist/tests.py | 6 +++--- tests/admin_inlines/tests.py | 6 +++--- tests/admin_widgets/urls.py | 2 +- tests/aggregation_regress/tests.py | 18 +++++++++--------- tests/cache/tests.py | 6 +++--- tests/expressions_regress/tests.py | 2 +- tests/forms_tests/tests/test_formsets.py | 2 +- tests/multiple_database/tests.py | 4 ++-- tests/or_lookups/tests.py | 2 +- tests/prefetch_related/tests.py | 14 +++++++------- tests/queries/tests.py | 6 ++++-- tests/swappable_models/models.py | 4 ++-- 38 files changed, 92 insertions(+), 73 deletions(-) diff --git a/django/conf/locale/id/formats.py b/django/conf/locale/id/formats.py index d2a6ce6f4d..aff32fb126 100644 --- a/django/conf/locale/id/formats.py +++ b/django/conf/locale/id/formats.py @@ -12,7 +12,7 @@ YEAR_MONTH_FORMAT = 'F Y' MONTH_DAY_FORMAT = 'j F' SHORT_DATE_FORMAT = 'd-m-Y' SHORT_DATETIME_FORMAT = 'd-m-Y G.i.s' -FIRST_DAY_OF_WEEK = 1 #Monday +FIRST_DAY_OF_WEEK = 1 # Monday # The *_INPUT_FORMATS strings use the Python strftime format syntax, # see http://docs.python.org/library/datetime.html#strftime-strptime-behavior diff --git a/django/conf/locale/lv/formats.py b/django/conf/locale/lv/formats.py index db1952e973..c2c9f9da37 100644 --- a/django/conf/locale/lv/formats.py +++ b/django/conf/locale/lv/formats.py @@ -12,7 +12,7 @@ YEAR_MONTH_FORMAT = r'Y. \g. F' MONTH_DAY_FORMAT = 'j. F' SHORT_DATE_FORMAT = r'j.m.Y' SHORT_DATETIME_FORMAT = 'j.m.Y H:i:s' -FIRST_DAY_OF_WEEK = 1 #Monday +FIRST_DAY_OF_WEEK = 1 # Monday # The *_INPUT_FORMATS strings use the Python strftime format syntax, # see http://docs.python.org/library/datetime.html#strftime-strptime-behavior diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index 3c748b5b80..2385efd79e 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -101,7 +101,7 @@ class GeoModelAdmin(ModelAdmin): 'num_zoom' : self.num_zoom, 'max_zoom' : self.max_zoom, 'min_zoom' : self.min_zoom, - 'units' : self.units, #likely shoud get from object + 'units' : self.units, # likely should get from object 'max_resolution' : self.max_resolution, 'max_extent' : self.max_extent, 'modifiable' : self.modifiable, diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 6f8c830e1d..a168c79686 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -151,7 +151,7 @@ class OGRGeometry(GDALBase): def from_bbox(cls, bbox): "Constructs a Polygon from a bounding box (4-tuple)." x0, y0, x1, y1 = bbox - return OGRGeometry( 'POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' % ( + return OGRGeometry( 'POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' % ( x0, y0, x0, y1, x1, y1, x1, y0, x0, y0) ) ### Geometry set-like operations ### diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py index 66a8d4ec93..36a5e73d07 100644 --- a/django/contrib/gis/gdal/srs.py +++ b/django/contrib/gis/gdal/srs.py @@ -105,7 +105,7 @@ class SpatialReference(GDALBase): doesn't exist. Can also take a tuple as a parameter, (target, child), where child is the index of the attribute in the WKT. For example: - >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]') + >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]' >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326 >>> print(srs['GEOGCS']) WGS 84 diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index 9939a1145d..65207bf0c8 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -204,7 +204,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): "Testing Polygon objects." # Testing `from_bbox` class method - bbox = (-180,-90,180,90) + bbox = (-180, -90, 180, 90) p = OGRGeometry.from_bbox( bbox ) self.assertEqual(bbox, p.extent) diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py index 53dfd67ae6..3273aa4a1a 100644 --- a/django/contrib/gis/geos/polygon.py +++ b/django/contrib/gis/geos/polygon.py @@ -17,12 +17,14 @@ class Polygon(GEOSGeometry): Examples of initialization, where shell, hole1, and hole2 are valid LinearRing geometries: + >>> from django.contrib.gis.geos import LinearRing, Polygon + >>> shell = hole1 = hole2 = LinearRing() >>> poly = Polygon(shell, hole1, hole2) >>> poly = Polygon(shell, (hole1, hole2)) - Example where a tuple parameters are used: + >>> # Example where a tuple parameters are used: >>> poly = Polygon(((0, 0), (0, 10), (10, 10), (0, 10), (0, 0)), - ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4))) + ... ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4))) """ if not args: raise TypeError('Must provide at least one LinearRing, or a tuple, to initialize a Polygon.') diff --git a/django/contrib/gis/geos/tests/test_geos_mutation.py b/django/contrib/gis/geos/tests/test_geos_mutation.py index 337abb4d8b..38c80e3bdd 100644 --- a/django/contrib/gis/geos/tests/test_geos_mutation.py +++ b/django/contrib/gis/geos/tests/test_geos_mutation.py @@ -33,9 +33,9 @@ def api_get_extent(x): return x.extent def api_get_area(x): return x.area def api_get_length(x): return x.length -geos_function_tests = [ val for name, val in vars().items() - if hasattr(val, '__call__') - and name.startswith('api_get_') ] +geos_function_tests = [val for name, val in vars().items() + if hasattr(val, '__call__') + and name.startswith('api_get_')] @skipUnless(HAS_GEOS, "Geos is required.") diff --git a/django/contrib/gis/geos/tests/test_mutable_list.py b/django/contrib/gis/geos/tests/test_mutable_list.py index ae50a5f616..4507be5374 100644 --- a/django/contrib/gis/geos/tests/test_mutable_list.py +++ b/django/contrib/gis/geos/tests/test_mutable_list.py @@ -16,11 +16,14 @@ class UserListA(ListMixin): self._list = self._mytype(i_list) super(UserListA, self).__init__(*args, **kwargs) - def __len__(self): return len(self._list) + def __len__(self): + return len(self._list) - def __str__(self): return str(self._list) + def __str__(self): + return str(self._list) - def __repr__(self): return repr(self._list) + def __repr__(self): + return repr(self._list) def _set_list(self, length, items): # this would work: diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py index 95cf2c9d99..39c0c5516b 100644 --- a/django/contrib/gis/maps/google/gmap.py +++ b/django/contrib/gis/maps/google/gmap.py @@ -81,7 +81,7 @@ class GoogleMap(object): # level and a center coordinate are provided with polygons/polylines, # no automatic determination will occur. self.calc_zoom = False - if self.polygons or self.polylines or self.markers: + if self.polygons or self.polylines or self.markers: if center is None or zoom is None: self.calc_zoom = True diff --git a/django/contrib/gis/tests/distapp/tests.py b/django/contrib/gis/tests/distapp/tests.py index fb951ca24d..67dbad0ecb 100644 --- a/django/contrib/gis/tests/distapp/tests.py +++ b/django/contrib/gis/tests/distapp/tests.py @@ -189,7 +189,7 @@ class DistanceTest(TestCase): self.assertAlmostEqual(spheroid_distances[i], c.distance.m, tol) if postgis: # PostGIS uses sphere-only distances by default, testing these as well. - qs = AustraliaCity.objects.exclude(id=hillsdale.id).distance(hillsdale.point) + qs = AustraliaCity.objects.exclude(id=hillsdale.id).distance(hillsdale.point) for i, c in enumerate(qs): self.assertAlmostEqual(sphere_distances[i], c.distance.m, tol) diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index 68e1b09873..adb8426f67 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -568,7 +568,7 @@ class GeoQuerySetTest(TestCase): # The reference KML depends on the version of PostGIS used # (the output stopped including altitude in 1.3.3). if connection.ops.spatial_version >= (1, 3, 3): - ref_kml = '-104.609252,38.255001' + ref_kml = '-104.609252,38.255001' else: ref_kml = '-104.609252,38.255001,0' diff --git a/django/contrib/gis/tests/layermap/tests.py b/django/contrib/gis/tests/layermap/tests.py index fff3004350..c2101ba8c7 100644 --- a/django/contrib/gis/tests/layermap/tests.py +++ b/django/contrib/gis/tests/layermap/tests.py @@ -163,8 +163,10 @@ class LayerMapTest(TestCase): # Passing in invalid ForeignKey mapping parameters -- must be a dictionary # mapping for the model the ForeignKey points to. - bad_fk_map1 = copy(co_mapping); bad_fk_map1['state'] = 'name' - bad_fk_map2 = copy(co_mapping); bad_fk_map2['state'] = {'nombre' : 'State'} + bad_fk_map1 = copy(co_mapping) + bad_fk_map1['state'] = 'name' + bad_fk_map2 = copy(co_mapping) + bad_fk_map2['state'] = {'nombre' : 'State'} self.assertRaises(TypeError, LayerMapping, County, co_shp, bad_fk_map1, transform=False) self.assertRaises(LayerMapError, LayerMapping, County, co_shp, bad_fk_map2, transform=False) diff --git a/django/contrib/gis/tests/test_geoforms.py b/django/contrib/gis/tests/test_geoforms.py index 65941ac770..7c2f67e551 100644 --- a/django/contrib/gis/tests/test_geoforms.py +++ b/django/contrib/gis/tests/test_geoforms.py @@ -163,7 +163,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertFalse(invalid.is_valid()) self.assertTrue('Invalid geometry value' in str(invalid.errors)) - for invalid in [geom for key, geom in self.geometries.items() if key!='point']: + for invalid in [geo for key, geo in self.geometries.items() if key!='point']: self.assertFalse(PointForm(data={'p': invalid.wkt}).is_valid()) def test_multipointfield(self): @@ -176,7 +176,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(PointForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='multipoint']: + for invalid in [geo for key, geo in self.geometries.items() if key!='multipoint']: self.assertFalse(PointForm(data={'p': invalid.wkt}).is_valid()) def test_linestringfield(self): @@ -189,7 +189,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(LineStringForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='linestring']: + for invalid in [geo for key, geo in self.geometries.items() if key!='linestring']: self.assertFalse(LineStringForm(data={'p': invalid.wkt}).is_valid()) def test_multilinestringfield(self): @@ -202,7 +202,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(LineStringForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='multilinestring']: + for invalid in [geo for key, geo in self.geometries.items() if key!='multilinestring']: self.assertFalse(LineStringForm(data={'p': invalid.wkt}).is_valid()) def test_polygonfield(self): @@ -215,7 +215,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(PolygonForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='polygon']: + for invalid in [geo for key, geo in self.geometries.items() if key!='polygon']: self.assertFalse(PolygonForm(data={'p': invalid.wkt}).is_valid()) def test_multipolygonfield(self): @@ -228,7 +228,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(PolygonForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='multipolygon']: + for invalid in [geo for key, geo in self.geometries.items() if key!='multipolygon']: self.assertFalse(PolygonForm(data={'p': invalid.wkt}).is_valid()) def test_geometrycollectionfield(self): @@ -241,7 +241,7 @@ class SpecializedFieldTest(SimpleTestCase): self.assertMapWidget(form) self.assertFalse(GeometryForm().is_valid()) - for invalid in [geom for key, geom in self.geometries.items() if key!='geometrycollection']: + for invalid in [geo for key, geo in self.geometries.items() if key!='geometrycollection']: self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid()) def test_osm_widget(self): diff --git a/django/contrib/gis/utils/wkt.py b/django/contrib/gis/utils/wkt.py index bd85591375..81df084297 100644 --- a/django/contrib/gis/utils/wkt.py +++ b/django/contrib/gis/utils/wkt.py @@ -10,10 +10,11 @@ def precision_wkt(geom, prec): integer or a string). If the precision is an integer, then the decimal places of coordinates WKT will be truncated to that number: + >>> from django.contrib.gis.geos import Point >>> pnt = Point(5, 23) >>> pnt.wkt 'POINT (5.0000000000000000 23.0000000000000000)' - >>> precision(geom, 1) + >>> precision_wkt(pnt, 1) 'POINT (5.0 23.0)' If the precision is a string, it must be valid Python format string diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py index 914e2c51fa..185aca72cc 100644 --- a/django/core/files/uploadhandler.py +++ b/django/core/files/uploadhandler.py @@ -199,6 +199,8 @@ def load_handler(path, *args, **kwargs): Given a path to a handler, return an instance of that handler. E.g.:: + >>> from django.http import HttpRequest + >>> request = HttpRequest() >>> load_handler('django.core.files.uploadhandler.TemporaryFileUploadHandler', request) diff --git a/django/core/signing.py b/django/core/signing.py index c3b2c3ed36..15b9eaec6e 100644 --- a/django/core/signing.py +++ b/django/core/signing.py @@ -187,7 +187,7 @@ class TimestampSigner(Signer): Retrieve original value and check it wasn't signed more than max_age seconds ago. """ - result = super(TimestampSigner, self).unsign(value) + result = super(TimestampSigner, self).unsign(value) value, timestamp = result.rsplit(self.sep, 1) timestamp = baseconv.base62.decode(timestamp) if max_age is not None: diff --git a/django/db/models/base.py b/django/db/models/base.py index 9409454d3e..c96507d5a1 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -164,7 +164,7 @@ class ModelBase(type): # Basic setup for proxy models. if is_proxy: base = None - for parent in [cls for cls in parents if hasattr(cls, '_meta')]: + for parent in [kls for kls in parents if hasattr(kls, '_meta')]: if parent._meta.abstract: if parent._meta.fields: raise TypeError("Abstract base class containing model fields not permitted for proxy model '%s'." % name) diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 557ec6ec8a..08ac4413a0 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -142,11 +142,14 @@ class FileDescriptor(object): The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:: + >>> from myapp.models import MyModel + >>> instance = MyModel.objects.get(pk=1) >>> instance.file.size Assigns a file object on assignment so you can do:: - >>> instance.file = File(...) + >>> with open('/tmp/hello.world', 'r') as f: + ... instance.file = File(f) """ def __init__(self, field): diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py index c7731d41fe..b816e71159 100644 --- a/django/dispatch/saferef.py +++ b/django/dispatch/saferef.py @@ -23,7 +23,7 @@ def safeRef(target, onDelete = None): if target.__self__ is not None: # Turn a bound method into a BoundMethodWeakref instance. # Keep track of these instances for lookup by disconnect(). - assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference"""%( target,) + assert hasattr(target, '__func__'), """safeRef target %r has __self__, but no __func__, don't know how to create reference""" % (target,) reference = get_bound_method_weakref( target=target, onDelete=onDelete @@ -144,7 +144,7 @@ class BoundMethodWeakref(object): def __str__(self): """Give a friendly representation of the object""" - return """%s( %s.%s )"""%( + return """%s( %s.%s )""" % ( self.__class__.__name__, self.selfName, self.funcName, diff --git a/django/forms/fields.py b/django/forms/fields.py index 4e0ee29938..b5816889f9 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -567,7 +567,7 @@ class FileField(Field): raise ValidationError(self.error_messages['invalid'], code='invalid') if self.max_length is not None and len(file_name) > self.max_length: - params = {'max': self.max_length, 'length': len(file_name)} + params = {'max': self.max_length, 'length': len(file_name)} raise ValidationError(self.error_messages['max_length'], code='max_length', params=params) if not file_name: raise ValidationError(self.error_messages['invalid'], code='invalid') diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 678b963e7e..f8246d60bf 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -117,7 +117,7 @@ def media_property(cls): if definition: extend = getattr(definition, 'extend', True) if extend: - if extend == True: + if extend is True: m = base else: m = Media() diff --git a/django/template/context.py b/django/template/context.py index 79d0b6f505..70ed3f698b 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -6,7 +6,7 @@ _standard_context_processors = None # We need the CSRF processor no matter what the user has in their settings, # because otherwise it is a security vulnerability, and we can't afford to leave # this to human error or failure to read migration instructions. -_builtin_context_processors = ('django.core.context_processors.csrf',) +_builtin_context_processors = ('django.core.context_processors.csrf',) class ContextPopException(Exception): "pop() has been called more times than push()" diff --git a/django/templatetags/cache.py b/django/templatetags/cache.py index 215f1179dc..85ce67f1cc 100644 --- a/django/templatetags/cache.py +++ b/django/templatetags/cache.py @@ -60,4 +60,4 @@ def do_cache(parser, token): return CacheNode(nodelist, parser.compile_filter(tokens[1]), tokens[2], # fragment_name can't be a variable. - [parser.compile_filter(token) for token in tokens[3:]]) + [parser.compile_filter(t) for t in tokens[3:]]) diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index 33d37c6835..e1627f4954 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -28,7 +28,11 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import os, sys, time, signal, traceback +import os +import signal +import sys +import time +import traceback try: from django.utils.six.moves import _thread as thread diff --git a/extras/csrf_migration_helper.py b/extras/csrf_migration_helper.py index 2a8853494c..1554555eda 100755 --- a/extras/csrf_migration_helper.py +++ b/extras/csrf_migration_helper.py @@ -144,7 +144,7 @@ def get_template_dirs(): from django.conf import settings dirs = set() if ('django.template.loaders.filesystem.load_template_source' in settings.TEMPLATE_LOADERS - or 'django.template.loaders.filesystem.Loader' in settings.TEMPLATE_LOADERS): + or 'django.template.loaders.filesystem.Loader' in settings.TEMPLATE_LOADERS): dirs.update(map(unicode, settings.TEMPLATE_DIRS)) if ('django.template.loaders.app_directories.load_template_source' in settings.TEMPLATE_LOADERS diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index f9ef079904..54a4993171 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -505,7 +505,7 @@ class ChangeListTests(TestCase): admin.site.register(UnorderedObject, UnorderedObjectAdmin) model_admin = UnorderedObjectAdmin(UnorderedObject, admin.site) counter = 0 if ascending else 51 - for page in range (0, 5): + for page in range(0, 5): request = self._mocked_authenticated_request('/unorderedobject/?p=%s' % page, superuser) response = model_admin.changelist_view(request) for result in response.context_data['cl'].result_list: @@ -550,7 +550,7 @@ class ChangeListTests(TestCase): admin.site.register(OrderedObject, OrderedObjectAdmin) model_admin = OrderedObjectAdmin(OrderedObject, admin.site) counter = 0 if ascending else 51 - for page in range (0, 5): + for page in range(0, 5): request = self._mocked_authenticated_request('/orderedobject/?p=%s' % page, superuser) response = model_admin.changelist_view(request) for result in response.context_data['cl'].result_list: @@ -588,7 +588,7 @@ class ChangeListTests(TestCase): user_parents = self._create_superuser('parents') # Test with user 'noparents' - m = DynamicListFilterChildAdmin(Child, admin.site) + m = DynamicListFilterChildAdmin(Child, admin.site) request = self._mocked_authenticated_request('/child/', user_noparents) response = m.changelist_view(request) self.assertEqual(response.context_data['cl'].list_filter, ['name', 'age']) diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py index 871852425a..6dfef9695a 100644 --- a/tests/admin_inlines/tests.py +++ b/tests/admin_inlines/tests.py @@ -170,7 +170,7 @@ class TestInline(TestCase): holder = Holder.objects.create(pk=123456789, dummy=42) inner = Inner.objects.create(pk=987654321, holder=holder, dummy=42, readonly='') response = self.client.get('/admin/admin_inlines/holder/%i/' % holder.id) - inner_shortcut = 'r/%s/%s/'%(ContentType.objects.get_for_model(inner).pk, inner.pk) + inner_shortcut = 'r/%s/%s/' % (ContentType.objects.get_for_model(inner).pk, inner.pk) self.assertContains(response, inner_shortcut) def test_custom_pk_shortcut(self): @@ -182,8 +182,8 @@ class TestInline(TestCase): child1 = ChildModel1.objects.create(my_own_pk="bar", name="Bar", parent=parent) child2 = ChildModel2.objects.create(my_own_pk="baz", name="Baz", parent=parent) response = self.client.get('/admin/admin_inlines/parentmodelwithcustompk/foo/') - child1_shortcut = 'r/%s/%s/'%(ContentType.objects.get_for_model(child1).pk, child1.pk) - child2_shortcut = 'r/%s/%s/'%(ContentType.objects.get_for_model(child2).pk, child2.pk) + child1_shortcut = 'r/%s/%s/' % (ContentType.objects.get_for_model(child1).pk, child1.pk) + child2_shortcut = 'r/%s/%s/' % (ContentType.objects.get_for_model(child2).pk, child2.pk) self.assertContains(response, child1_shortcut) self.assertContains(response, child2_shortcut) diff --git a/tests/admin_widgets/urls.py b/tests/admin_widgets/urls.py index 3da5d25bc8..94c841765f 100644 --- a/tests/admin_widgets/urls.py +++ b/tests/admin_widgets/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import patterns, include -from . import widgetadmin +from . import widgetadmin urlpatterns = patterns('', diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index 9fcaefe6f5..111ef79b5e 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -1017,20 +1017,20 @@ class AggregationTests(TestCase): tests aggregations with generic reverse relations """ - b = Book.objects.get(name='Practical Django Projects') - ItemTag.objects.create(object_id=b.id, tag='intermediate', - content_type=ContentType.objects.get_for_model(b)) - ItemTag.objects.create(object_id=b.id, tag='django', - content_type=ContentType.objects.get_for_model(b)) + django_book = Book.objects.get(name='Practical Django Projects') + ItemTag.objects.create(object_id=django_book.id, tag='intermediate', + content_type=ContentType.objects.get_for_model(django_book)) + ItemTag.objects.create(object_id=django_book.id, tag='django', + content_type=ContentType.objects.get_for_model(django_book)) # Assign a tag to model with same PK as the book above. If the JOIN # used in aggregation doesn't have content type as part of the # condition the annotation will also count the 'hi mom' tag for b. - wmpk = WithManualPK.objects.create(id=b.pk) + wmpk = WithManualPK.objects.create(id=django_book.pk) ItemTag.objects.create(object_id=wmpk.id, tag='hi mom', content_type=ContentType.objects.get_for_model(wmpk)) - b = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence') - ItemTag.objects.create(object_id=b.id, tag='intermediate', - content_type=ContentType.objects.get_for_model(b)) + ai_book = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence') + ItemTag.objects.create(object_id=ai_book.id, tag='intermediate', + content_type=ContentType.objects.get_for_model(ai_book)) self.assertEqual(Book.objects.aggregate(Count('tags')), {'tags__count': 3}) results = Book.objects.annotate(Count('tags')).order_by('-tags__count', 'name') diff --git a/tests/cache/tests.py b/tests/cache/tests.py index d46c61df67..6912e8f755 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -149,7 +149,7 @@ class DummyCacheTests(unittest.TestCase): 'ascii': 'ascii_value', 'unicode_ascii': 'Iñtërnâtiônàlizætiøn1', 'Iñtërnâtiônàlizætiøn': 'Iñtërnâtiônàlizætiøn2', - 'ascii2': {'x' : 1 } + 'ascii2': {'x' : 1} } for (key, value) in stuff.items(): self.cache.set(key, value) @@ -434,7 +434,7 @@ class BaseCacheTests(object): it is an absolute expiration timestamp instead of a relative offset. Test that we honour this convention. Refs #12399. ''' - self.cache.set('key1', 'eggs', 60*60*24*30 + 1) #30 days + 1 second + self.cache.set('key1', 'eggs', 60*60*24*30 + 1) # 30 days + 1 second self.assertEqual(self.cache.get('key1'), 'eggs') self.cache.add('key2', 'ham', 60*60*24*30 + 1) @@ -1432,7 +1432,7 @@ class CacheI18nTest(TestCase): self.assertEqual(key, key2) @override_settings(USE_I18N=False, USE_L10N=False) - def test_cache_key_no_i18n (self): + def test_cache_key_no_i18n(self): request = self._get_request() lang = translation.get_language() tz = force_text(timezone.get_current_timezone_name(), errors='ignore') diff --git a/tests/expressions_regress/tests.py b/tests/expressions_regress/tests.py index eb807cb050..a637d88e68 100644 --- a/tests/expressions_regress/tests.py +++ b/tests/expressions_regress/tests.py @@ -367,7 +367,7 @@ class FTimeDeltaTests(TestCase): def test_delta_invalid_op_mod(self): raised = False try: - r = repr(Experiment.objects.filter(end__lt=F('start')%self.deltas[0])) + r = 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.") diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 4ac910a421..6eadf6028d 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -1071,7 +1071,7 @@ class FormsFormsetTestCase(TestCase): def test_formset_total_error_count(self): """A valid formset should have 0 total errors.""" - data = [ # formset_data, expected error count + data = [ # formset_data, expected error count ([('Calexico', '100')], 0), ([('Calexico', '')], 1), ([('', 'invalid')], 2), diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 37f59061ac..edc4b99f09 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -113,7 +113,7 @@ class QueryTestCase(TestCase): dive = Book.objects.using('other').create(title="Dive into Python", published=datetime.date(2009, 5, 4)) - dive = Book.objects.using('other').get(published=datetime.date(2009, 5, 4)) + dive = Book.objects.using('other').get(published=datetime.date(2009, 5, 4)) self.assertEqual(dive.title, "Dive into Python") self.assertRaises(Book.DoesNotExist, Book.objects.using('default').get, published=datetime.date(2009, 5, 4)) @@ -125,7 +125,7 @@ class QueryTestCase(TestCase): self.assertEqual(dive.title, "Dive into Python") self.assertRaises(Book.DoesNotExist, Book.objects.using('default').get, title__iexact="dive INTO python") - dive = Book.objects.using('other').get(published__year=2009) + dive = Book.objects.using('other').get(published__year=2009) self.assertEqual(dive.title, "Dive into Python") self.assertEqual(dive.published, datetime.date(2009, 5, 4)) self.assertRaises(Book.DoesNotExist, Book.objects.using('default').get, published__year=2009) diff --git a/tests/or_lookups/tests.py b/tests/or_lookups/tests.py index 264d999575..add9b81b3c 100644 --- a/tests/or_lookups/tests.py +++ b/tests/or_lookups/tests.py @@ -24,7 +24,7 @@ class OrLookupsTests(TestCase): def test_filter_or(self): self.assertQuerysetEqual( - Article.objects.filter(headline__startswith='Hello') | Article.objects.filter(headline__startswith='Goodbye'), [ + Article.objects.filter(headline__startswith='Hello') | Article.objects.filter(headline__startswith='Goodbye'), [ 'Hello', 'Goodbye', 'Hello and goodbye' diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 9d5a5290da..6e0b617161 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -321,9 +321,9 @@ class GenericRelationTests(TestCase): [t.created_by for t in TaggedItem.objects.all()]) def test_generic_relation(self): - b = Bookmark.objects.create(url='http://www.djangoproject.com/') - t1 = TaggedItem.objects.create(content_object=b, tag='django') - t2 = TaggedItem.objects.create(content_object=b, tag='python') + bookmark = Bookmark.objects.create(url='http://www.djangoproject.com/') + t1 = TaggedItem.objects.create(content_object=bookmark, tag='django') + t2 = TaggedItem.objects.create(content_object=bookmark, tag='python') with self.assertNumQueries(2): tags = [t.tag for b in Bookmark.objects.prefetch_related('tags') @@ -509,8 +509,8 @@ class NullableTest(TestCase): co_serfs = [list(e.boss.serfs.all()) if e.boss is not None else [] for e in qs] - qs2 = Employee.objects.select_related('boss') - co_serfs2 = [list(e.boss.serfs.all()) if e.boss is not None else [] + qs2 = Employee.objects.select_related('boss') + co_serfs2 = [list(e.boss.serfs.all()) if e.boss is not None else [] for e in qs2] self.assertEqual(co_serfs, co_serfs2) @@ -522,8 +522,8 @@ class NullableTest(TestCase): co_serfs = [list(e.boss.serfs.all()) if e.boss is not None else [] for e in qs] - qs2 = Employee.objects.all() - co_serfs2 = [list(e.boss.serfs.all()) if e.boss is not None else [] + qs2 = Employee.objects.all() + co_serfs2 = [list(e.boss.serfs.all()) if e.boss is not None else [] for e in qs2] self.assertEqual(co_serfs, co_serfs2) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 6930f3093d..32ffc06dbb 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -1558,7 +1558,9 @@ class Queries5Tests(TestCase): # extra() qs = Ranking.objects.extra(select={'good': 'case when rank > 2 then 1 else 0 end'}) dicts = qs.values().order_by('id') - for d in dicts: del d['id']; del d['author_id'] + for d in dicts: + del d['id'] + del d['author_id'] self.assertEqual( [sorted(d.items()) for d in dicts], [[('good', 0), ('rank', 2)], [('good', 0), ('rank', 1)], [('good', 1), ('rank', 3)]] @@ -2668,7 +2670,7 @@ class NullJoinPromotionOrTest(TestCase): # problem here was that b__name generates a LOUTER JOIN, then # b__c__name generates join to c, which the ORM tried to promote but # failed as that join isn't nullable. - q_obj = ( + q_obj = ( Q(d__name='foo')| Q(b__name='foo')| Q(b__c__name='foo') diff --git a/tests/swappable_models/models.py b/tests/swappable_models/models.py index 92692d4396..c5b4425489 100644 --- a/tests/swappable_models/models.py +++ b/tests/swappable_models/models.py @@ -2,7 +2,7 @@ from django.db import models class Article(models.Model): - title = models.CharField(max_length=100) + title = models.CharField(max_length=100) publication_date = models.DateField() class Meta: @@ -10,6 +10,6 @@ class Article(models.Model): class AlternateArticle(models.Model): - title = models.CharField(max_length=100) + title = models.CharField(max_length=100) publication_date = models.DateField() byline = models.CharField(max_length=100)