diff options
| author | Loic Bistuer <loic.bistuer@sixmedia.com> | 2013-12-09 00:20:06 +0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-12-10 15:12:48 -0500 |
| commit | a2814846ca006b4fbf3a893ec52cd9d444b3a3eb (patch) | |
| tree | 780498814e830e2b8ee6ac435575afdc2e8e63f6 | |
| parent | 0873200e7f61315ad375061a3dc6d37b514ff985 (diff) | |
Fixed E124 pep8 warnings.
45 files changed, 371 insertions, 262 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index a2a7df945a..318c393c09 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -42,7 +42,8 @@ class AdminForm(object): def __iter__(self): for name, options in self.fieldsets: - yield Fieldset(self.form, name, + yield Fieldset( + self.form, name, readonly_fields=self.readonly_fields, model_admin=self.model_admin, **options diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 51e8a1b2e6..4c5adaf0f8 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1520,7 +1520,8 @@ class ModelAdmin(BaseModelAdmin): selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) - context = dict(self.admin_site.each_context(), + context = dict( + self.admin_site.each_context(), module_name=force_text(opts.verbose_name_plural), selection_note=_('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, selection_note_all=selection_note_all % {'total_count': cl.result_count}, @@ -1587,7 +1588,8 @@ class ModelAdmin(BaseModelAdmin): else: title = _("Are you sure?") - context = dict(self.admin_site.each_context(), + context = dict( + self.admin_site.each_context(), title=title, object_name=object_name, object=obj, diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index e620154312..7b633bef89 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -398,7 +398,8 @@ class AdminSite(object): for app in app_list: app['models'].sort(key=lambda x: x['name']) - context = dict(self.each_context(), + context = dict( + self.each_context(), title=self.index_title, app_list=app_list, ) diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 777bfbac81..0181f665ad 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -95,7 +95,8 @@ def result_headers(cl): """ ordering_field_columns = cl.get_ordering_field_columns() for i, field_name in enumerate(cl.list_display): - text, attr = label_for_field(field_name, cl.model, + text, attr = label_for_field( + field_name, cl.model, model_admin=cl.model_admin, return_attr=True ) diff --git a/django/contrib/admindocs/tests/test_fields.py b/django/contrib/admindocs/tests/test_fields.py index dd465111a1..3f4efedb9c 100644 --- a/django/contrib/admindocs/tests/test_fields.py +++ b/django/contrib/admindocs/tests/test_fields.py @@ -21,7 +21,8 @@ class TestFieldType(unittest.TestCase): pass def test_field_name(self): - self.assertRaises(AttributeError, + self.assertRaises( + AttributeError, views.get_readable_field_data_type, "NotAField" ) diff --git a/django/contrib/admindocs/urls.py b/django/contrib/admindocs/urls.py index 8aa4dcf946..3dc55657df 100644 --- a/django/contrib/admindocs/urls.py +++ b/django/contrib/admindocs/urls.py @@ -4,38 +4,29 @@ from django.contrib.admindocs import views urlpatterns = patterns('', url('^$', views.BaseAdminDocsView.as_view(template_name='admin_doc/index.html'), - name='django-admindocs-docroot' - ), + name='django-admindocs-docroot'), url('^bookmarklets/$', views.BookmarkletsView.as_view(), - name='django-admindocs-bookmarklets' - ), + name='django-admindocs-bookmarklets'), url('^tags/$', views.TemplateTagIndexView.as_view(), - name='django-admindocs-tags' - ), + name='django-admindocs-tags'), url('^filters/$', views.TemplateFilterIndexView.as_view(), - name='django-admindocs-filters' - ), + name='django-admindocs-filters'), url('^views/$', views.ViewIndexView.as_view(), - name='django-admindocs-views-index' - ), + name='django-admindocs-views-index'), url('^views/(?P<view>[^/]+)/$', views.ViewDetailView.as_view(), - name='django-admindocs-views-detail' - ), + name='django-admindocs-views-detail'), url('^models/$', views.ModelIndexView.as_view(), - name='django-admindocs-models-index' - ), + name='django-admindocs-models-index'), url('^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', views.ModelDetailView.as_view(), - name='django-admindocs-models-detail' - ), + name='django-admindocs-models-detail'), url('^templates/(?P<template>.*)/$', views.TemplateDetailView.as_view(), - name='django-admindocs-templates' - ), + name='django-admindocs-templates'), ) diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index 8514f3bfcf..9bfc070ab2 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -48,8 +48,8 @@ class UserAdmin(admin.ModelAdmin): add_fieldsets = ( (None, { 'classes': ('wide',), - 'fields': ('username', 'password1', 'password2')} - ), + 'fields': ('username', 'password1', 'password2'), + }), ) form = UserChangeForm add_form = UserCreationForm diff --git a/django/contrib/auth/tests/test_basic.py b/django/contrib/auth/tests/test_basic.py index e5a3e676b8..34b6142632 100644 --- a/django/contrib/auth/tests/test_basic.py +++ b/django/contrib/auth/tests/test_basic.py @@ -130,7 +130,8 @@ class BasicTestCase(TestCase): "Check the operation of the createsuperuser management command" # We can use the management command to create a superuser new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe", email="joe@somewhere.org", @@ -146,7 +147,8 @@ class BasicTestCase(TestCase): # We can supress output on the management command new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe2", email="joe2@somewhere.org", @@ -159,7 +161,8 @@ class BasicTestCase(TestCase): self.assertEqual(u.email, 'joe2@somewhere.org') self.assertFalse(u.has_usable_password()) - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe+admin@somewhere.org", email="joe@somewhere.org", @@ -182,7 +185,8 @@ class BasicTestCase(TestCase): locale.getdefaultlocale = lambda: (None, None) # Call the command in this new environment - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=True, username="nolocale@somewhere.org", email="nolocale@somewhere.org", @@ -212,7 +216,8 @@ class BasicTestCase(TestCase): username_field.verbose_name = ulazy('uživatel') new_io = StringIO() try: - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=True, stdout=new_io ) diff --git a/django/contrib/auth/tests/test_management.py b/django/contrib/auth/tests/test_management.py index 795b72b52e..bd51f39977 100644 --- a/django/contrib/auth/tests/test_management.py +++ b/django/contrib/auth/tests/test_management.py @@ -91,7 +91,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): "Check the operation of the createsuperuser management command" # We can use the management command to create a superuser new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe", email="joe@somewhere.org", @@ -108,7 +109,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def test_verbosity_zero(self): # We can supress output on the management command new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe2", email="joe2@somewhere.org", @@ -123,7 +125,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): def test_email_in_username(self): new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe+admin@somewhere.org", email="joe@somewhere.org", @@ -140,7 +143,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): # We skip validation because the temporary substitution of the # swappable User model messes with validation. new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, email="joe@somewhere.org", date_of_birth="1976-04-01", @@ -163,7 +167,8 @@ class CreatesuperuserManagementCommandTestCase(TestCase): # swappable User model messes with validation. new_io = StringIO() with self.assertRaises(CommandError): - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe@somewhere.org", stdout=new_io, diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 9ef499bb16..1ec5475f5b 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -452,9 +452,10 @@ class BaseGenericInlineFormSet(BaseModelFormSet): @classmethod def get_default_prefix(cls): opts = cls.model._meta - return '-'.join((opts.app_label, opts.model_name, - cls.ct_field.name, cls.ct_fk_field.name, - )) + return '-'.join( + (opts.app_label, opts.model_name, + cls.ct_field.name, cls.ct_fk_field.name) + ) def save_new(self, form, commit=True): setattr(form.instance, self.ct_field.get_attname(), diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py index cdff5396cc..66b96a0873 100644 --- a/django/contrib/gis/db/models/query.py +++ b/django/contrib/gis/db/models/query.py @@ -362,12 +362,14 @@ class GeoQuerySet(QuerySet): relative = int(bool(relative)) if not isinstance(precision, six.integer_types): raise TypeError('SVG precision keyword argument must be an integer.') - s = {'desc': 'SVG', - 'procedure_fmt': '%(geo_col)s,%(rel)s,%(precision)s', - 'procedure_args': {'rel': relative, - 'precision': precision, - } - } + s = { + 'desc': 'SVG', + 'procedure_fmt': '%(geo_col)s,%(rel)s,%(precision)s', + 'procedure_args': { + 'rel': relative, + 'precision': precision, + } + } return self._spatial_attribute('svg', s, **kwargs) def sym_difference(self, geom, **kwargs): @@ -746,11 +748,12 @@ class GeoQuerySet(QuerySet): for geometry set-like operations (e.g., intersection, difference, union, sym_difference). """ - s = {'geom_args': ('geom',), - 'select_field': GeomField(), - 'procedure_fmt': '%(geo_col)s,%(geom)s', - 'procedure_args': {'geom': geom}, - } + s = { + 'geom_args': ('geom',), + 'select_field': GeomField(), + 'procedure_fmt': '%(geo_col)s,%(geom)s', + 'procedure_args': {'geom': geom}, + } if connections[self.db].ops.oracle: s['procedure_fmt'] += ',%(tolerance)s' s['procedure_args']['tolerance'] = tolerance diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 2609ac16fd..60041cd75f 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -66,7 +66,8 @@ class BaseGeometryWidget(Widget): value.srid, self.map_srid, err) ) - context = self.build_attrs(attrs, + context = self.build_attrs( + attrs, name=name, module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), diff --git a/django/contrib/gis/tests/geoapp/test_regress.py b/django/contrib/gis/tests/geoapp/test_regress.py index 3bd74b00d1..5fd74ea997 100644 --- a/django/contrib/gis/tests/geoapp/test_regress.py +++ b/django/contrib/gis/tests/geoapp/test_regress.py @@ -33,10 +33,11 @@ class GeoRegressionTests(TestCase): def test_kmz(self): "Testing `render_to_kmz` with non-ASCII data. See #11624." name = "Åland Islands" - places = [{'name': name, - 'description': name, - 'kml': '<Point><coordinates>5.0,23.0</coordinates></Point>' - }] + places = [{ + 'name': name, + 'description': name, + 'kml': '<Point><coordinates>5.0,23.0</coordinates></Point>' + }] render_to_kmz('gis/kml/placemarks.kml', {'places': places}) @no_spatialite diff --git a/django/core/management/commands/testserver.py b/django/core/management/commands/testserver.py index 182587b0f5..79f0ff5501 100644 --- a/django/core/management/commands/testserver.py +++ b/django/core/management/commands/testserver.py @@ -37,7 +37,8 @@ class Command(BaseCommand): # multiple times. shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name use_threading = connection.features.test_db_allows_multiple_connections - call_command('runserver', + call_command( + 'runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False, diff --git a/django/core/management/validation.py b/django/core/management/validation.py index 5bf9413c20..6bdcf853d4 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -270,8 +270,7 @@ def get_validation_errors(outfile, app=None): seen_to = True if f.rel.through not in models.get_models(include_auto_created=True): e.add(opts, "'%s' specifies an m2m relation through model " - "%s, which has not been installed." % (f.name, f.rel.through) - ) + "%s, which has not been installed." % (f.name, f.rel.through)) signature = (f.rel.to, cls, f.rel.through) if signature in seen_intermediary_signatures: e.add(opts, "The model %s has two manually-defined m2m " @@ -295,13 +294,14 @@ def get_validation_errors(outfile, app=None): if not seen_related_fk or not seen_this_fk: e.add(opts, "'%s' is a manually-defined m2m relation " "through model %s, which does not have foreign keys " - "to %s and %s" % (f.name, f.rel.through._meta.object_name, - f.rel.to._meta.object_name, cls._meta.object_name) + "to %s and %s" % ( + f.name, f.rel.through._meta.object_name, + f.rel.to._meta.object_name, cls._meta.object_name + ) ) elif isinstance(f.rel.through, six.string_types): e.add(opts, "'%s' specifies an m2m relation through model %s, " - "which has not been installed" % (f.name, f.rel.through) - ) + "which has not been installed" % (f.name, f.rel.through)) rel_opts = f.rel.to._meta rel_name = f.related.get_accessor_name() diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index a2a1757ad3..3faaeffb21 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1215,8 +1215,7 @@ class BaseDatabaseOperations(object): # Structure returned by the DB-API cursor.description interface (PEP 249) FieldInfo = namedtuple('FieldInfo', - 'name type_code display_size internal_size precision scale null_ok' -) + 'name type_code display_size internal_size precision scale null_ok') class BaseDatabaseIntrospection(object): diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index b38d00c84a..e7932dd800 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -332,13 +332,15 @@ class DatabaseOperations(BaseDatabaseOperations): # Truncate already resets the AUTO_INCREMENT field from # MySQL version 5.0.13 onwards. Refs #16961. if self.connection.mysql_version < (5, 0, 13): - return ["%s %s %s %s %s;" % - (style.SQL_KEYWORD('ALTER'), + return [ + "%s %s %s %s %s;" % ( + style.SQL_KEYWORD('ALTER'), style.SQL_KEYWORD('TABLE'), style.SQL_TABLE(self.quote_name(sequence['table'])), style.SQL_KEYWORD('AUTO_INCREMENT'), style.SQL_FIELD('= 1'), - ) for sequence in sequences] + ) for sequence in sequences + ] else: return [] diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index cb23c33a5c..91e16a1b76 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -168,7 +168,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): # notification. If we don't set self.connection to None, the error # will occur a every request. self.connection = None - logger.warning('psycopg2 error while closing the connection.', + logger.warning( + 'psycopg2 error while closing the connection.', exc_info=sys.exc_info() ) raise diff --git a/django/db/migrations/optimizer.py b/django/db/migrations/optimizer.py index 435ac6766e..3e9dc42aa3 100644 --- a/django/db/migrations/optimizer.py +++ b/django/db/migrations/optimizer.py @@ -176,12 +176,14 @@ class MigrationOptimizer(object): Folds a model rename into its create """ if operation.name.lower() == other.old_name.lower(): - return [migrations.CreateModel( - other.new_name, - fields=operation.fields, - options=operation.options, - bases=operation.bases, - )] + return [ + migrations.CreateModel( + other.new_name, + fields=operation.fields, + options=operation.options, + bases=operation.bases, + ) + ] def reduce_model_rename_self(self, operation, other): """ @@ -197,57 +199,67 @@ class MigrationOptimizer(object): def reduce_create_model_add_field(self, operation, other): if operation.name.lower() == other.model_name.lower(): - return [migrations.CreateModel( - operation.name, - fields=operation.fields + [(other.name, other.field)], - options=operation.options, - bases=operation.bases, - )] + return [ + migrations.CreateModel( + operation.name, + fields=operation.fields + [(other.name, other.field)], + options=operation.options, + bases=operation.bases, + ) + ] def reduce_create_model_alter_field(self, operation, other): if operation.name.lower() == other.model_name.lower(): - return [migrations.CreateModel( - operation.name, - fields=[ - (n, other.field if n == other.name else v) - for n, v in operation.fields - ], - options=operation.options, - bases=operation.bases, - )] + return [ + migrations.CreateModel( + operation.name, + fields=[ + (n, other.field if n == other.name else v) + for n, v in operation.fields + ], + options=operation.options, + bases=operation.bases, + ) + ] def reduce_create_model_rename_field(self, operation, other): if operation.name.lower() == other.model_name.lower(): - return [migrations.CreateModel( - operation.name, - fields=[ - (other.new_name if n == other.old_name else n, v) - for n, v in operation.fields - ], - options=operation.options, - bases=operation.bases, - )] + return [ + migrations.CreateModel( + operation.name, + fields=[ + (other.new_name if n == other.old_name else n, v) + for n, v in operation.fields + ], + options=operation.options, + bases=operation.bases, + ) + ] def reduce_create_model_remove_field(self, operation, other): if operation.name.lower() == other.model_name.lower(): - return [migrations.CreateModel( - operation.name, - fields=[ - (n, v) - for n, v in operation.fields - if n.lower() != other.name.lower() - ], - options=operation.options, - bases=operation.bases, - )] + return [ + migrations.CreateModel( + operation.name, + fields=[ + (n, v) + for n, v in operation.fields + if n.lower() != other.name.lower() + ], + options=operation.options, + bases=operation.bases, + ) + ] def reduce_add_field_alter_field(self, operation, other): if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.name.lower(): - return [migrations.AddField( - model_name=operation.model_name, - name=operation.name, - field=other.field, - )] + return [ + migrations.AddField( + model_name=operation.model_name, + name=operation.name, + field=other.field, + ) + ] def reduce_add_field_delete_field(self, operation, other): if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.name.lower(): @@ -259,11 +271,13 @@ class MigrationOptimizer(object): def reduce_add_field_rename_field(self, operation, other): if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.old_name.lower(): - return [migrations.AddField( - model_name=operation.model_name, - name=other.new_name, - field=operation.field, - )] + return [ + migrations.AddField( + model_name=operation.model_name, + name=other.new_name, + field=operation.field, + ) + ] def reduce_alter_field_rename_field(self, operation, other): if operation.model_name.lower() == other.model_name.lower() and operation.name.lower() == other.old_name.lower(): diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 826471d9ed..fbdf67d4c5 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1686,8 +1686,7 @@ class BinaryField(Field): return default def get_db_prep_value(self, value, connection, prepared=False): - value = super(BinaryField, self - ).get_db_prep_value(value, connection, prepared) + value = super(BinaryField, self).get_db_prep_value(value, connection, prepared) if value is not None: return connection.Database.Binary(value) return value diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index be796f2af1..5bfb1022a8 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -963,8 +963,7 @@ class OneToOneRel(ManyToOneRel): parent_link=False, on_delete=None, related_query_name=None): super(OneToOneRel, self).__init__(field, to, field_name, related_name=related_name, limit_choices_to=limit_choices_to, - parent_link=parent_link, on_delete=on_delete, related_query_name=related_query_name, - ) + parent_link=parent_link, on_delete=on_delete, related_query_name=related_query_name) self.multiple = False diff --git a/django/forms/utils.py b/django/forms/utils.py index 85297b1a1e..9402f2612e 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -52,11 +52,10 @@ class ErrorDict(dict): def as_ul(self): if not self: return '' - return format_html('<ul class="errorlist">{0}</ul>', - format_html_join('', '<li>{0}{1}</li>', - ((k, force_text(v)) - for k, v in self.items()) - )) + return format_html( + '<ul class="errorlist">{0}</ul>', + format_html_join('', '<li>{0}{1}</li>', ((k, force_text(v)) for k, v in self.items())) + ) def as_text(self): return '\n'.join('* %s\n%s' % (k, '\n'.join(' * %s' % force_text(i) for i in v)) for k, v in self.items()) @@ -73,11 +72,10 @@ class ErrorList(list): def as_ul(self): if not self: return '' - return format_html('<ul class="errorlist">{0}</ul>', - format_html_join('', '<li>{0}</li>', - ((force_text(e),) for e in self) - ) - ) + return format_html( + '<ul class="errorlist">{0}</ul>', + format_html_join('', '<li>{0}</li>', ((force_text(e),) for e in self)) + ) def as_text(self): if not self: diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 79f3961138..aeb674d013 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -72,7 +72,7 @@ class Media(object): return path if prefix is None: if settings.STATIC_URL is None: - # backwards compatibility + # backwards compatibility prefix = settings.MEDIA_URL else: prefix = settings.STATIC_URL diff --git a/django/test/__init__.py b/django/test/__init__.py index 98ff4393a3..4b17ed18c9 100644 --- a/django/test/__init__.py +++ b/django/test/__init__.py @@ -3,7 +3,8 @@ Django Unit Test and Doctest framework. """ from django.test.client import Client, RequestFactory -from django.test.testcases import (TestCase, TransactionTestCase, +from django.test.testcases import ( + TestCase, TransactionTestCase, SimpleTestCase, LiveServerTestCase, skipIfDBFeature, skipUnlessDBFeature ) diff --git a/django/test/simple.py b/django/test/simple.py index 05a7329fae..73deef917b 100644 --- a/django/test/simple.py +++ b/django/test/simple.py @@ -123,8 +123,7 @@ def get_tests(app_module): def make_doctest(module): return doctest.DocTestSuite(module, checker=doctestOutputChecker, - runner=DocTestRunner, - ) + runner=DocTestRunner) def build_suite(app_module): diff --git a/django/utils/text.py b/django/utils/text.py index b29e125f03..5e812b4f19 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -268,8 +268,7 @@ def phone2numeric(phone): char2number = {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3', 'f': '3', 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5', 'm': '6', 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7', 't': '8', - 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9', - } + 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9'} return ''.join(char2number.get(c, c) for c in phone.lower()) phone2numeric = allow_lazy(phone2numeric) @@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh [flake8] exclude=.git,./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./django/utils/lru_cache.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/* -ignore=E124,E127,E128,E501,W601 +ignore=E127,E128,E501,W601 [metadata] license-file = LICENSE diff --git a/tests/createsuperuser/tests.py b/tests/createsuperuser/tests.py index f64e4d9915..822f05d01b 100644 --- a/tests/createsuperuser/tests.py +++ b/tests/createsuperuser/tests.py @@ -38,7 +38,8 @@ class MultiDBCreatesuperuserTestCase(TestCase): " createsuperuser command should operate on specified DB" new_io = StringIO() - call_command("createsuperuser", + call_command( + "createsuperuser", interactive=False, username="joe", email="joe@somewhere.org", diff --git a/tests/custom_columns/tests.py b/tests/custom_columns/tests.py index 155279297f..aae3712e53 100644 --- a/tests/custom_columns/tests.py +++ b/tests/custom_columns/tests.py @@ -42,7 +42,8 @@ class CustomColumnsTests(TestCase): ) def test_field_error(self): - self.assertRaises(FieldError, + self.assertRaises( + FieldError, lambda: Author.objects.filter(firstname__exact="John") ) diff --git a/tests/custom_pk/tests.py b/tests/custom_pk/tests.py index 449e724acc..09a3ee5888 100644 --- a/tests/custom_pk/tests.py +++ b/tests/custom_pk/tests.py @@ -34,7 +34,8 @@ class CustomPKTests(TestCase): self.assertEqual(Employee.objects.get(pk=123), dan) self.assertEqual(Employee.objects.get(pk=456), fran) - self.assertRaises(Employee.DoesNotExist, + self.assertRaises( + Employee.DoesNotExist, lambda: Employee.objects.get(pk=42) ) diff --git a/tests/extra_regress/tests.py b/tests/extra_regress/tests.py index e9954add9b..4eaecc19af 100644 --- a/tests/extra_regress/tests.py +++ b/tests/extra_regress/tests.py @@ -91,14 +91,18 @@ class ExtraRegressTests(TestCase): internal dictionary must remain sorted. """ self.assertEqual( - User.objects.extra(select={"alpha": "%s"}, select_params=(1,) - ).extra(select={"beta": "%s"}, select_params=(2,))[0].alpha, - 1) + (User.objects + .extra(select={"alpha": "%s"}, select_params=(1,)) + .extra(select={"beta": "%s"}, select_params=(2,))[0].alpha), + 1 + ) self.assertEqual( - User.objects.extra(select={"beta": "%s"}, select_params=(1,) - ).extra(select={"alpha": "%s"}, select_params=(2,))[0].alpha, - 2) + (User.objects + .extra(select={"beta": "%s"}, select_params=(1,)) + .extra(select={"alpha": "%s"}, select_params=(2,))[0].alpha), + 2 + ) def test_regression_7961(self): """ @@ -107,8 +111,10 @@ class ExtraRegressTests(TestCase): query as well. """ self.assertEqual( - list(User.objects.extra(select={"alpha": "%s"}, select_params=(-6,) - ).filter(id=self.u.id).values_list('id', flat=True)), + list(User.objects + .extra(select={"alpha": "%s"}, select_params=(-6,)) + .filter(id=self.u.id) + .values_list('id', flat=True)), [self.u.id] ) @@ -129,10 +135,9 @@ class ExtraRegressTests(TestCase): should still be present because of the extra() call. """ self.assertQuerysetEqual( - Order.objects.extra(where=["username=%s"], - params=["fred"], - tables=["auth_user"] - ).order_by('created_by'), + (Order.objects + .extra(where=["username=%s"], params=["fred"], tables=["auth_user"]) + .order_by('created_by')), [] ) diff --git a/tests/get_object_or_404/tests.py b/tests/get_object_or_404/tests.py index 1a0b41bc4d..75d2a1c784 100644 --- a/tests/get_object_or_404/tests.py +++ b/tests/get_object_or_404/tests.py @@ -30,7 +30,8 @@ class GetObjectOr404Tests(TestCase): ) # No articles containing "Camelot". This should raise a Http404 error. - self.assertRaises(Http404, + self.assertRaises( + Http404, get_object_or_404, a1.article_set, title__contains="Camelot" ) @@ -49,12 +50,14 @@ class GetObjectOr404Tests(TestCase): # Just as when using a get() lookup, you will get an error if more than # one object is returned. - self.assertRaises(Author.MultipleObjectsReturned, + self.assertRaises( + Author.MultipleObjectsReturned, get_object_or_404, Author.objects.all() ) # Using an empty QuerySet raises a Http404 error. - self.assertRaises(Http404, + self.assertRaises( + Http404, get_object_or_404, Article.objects.none(), title__contains="Run" ) @@ -65,7 +68,8 @@ class GetObjectOr404Tests(TestCase): ) # Http404 is returned if the list is empty. - self.assertRaises(Http404, + self.assertRaises( + Http404, get_list_or_404, a1.article_set, title__icontains="Shrubbery" ) @@ -84,7 +88,8 @@ class GetObjectOr404Tests(TestCase): def test_bad_class(self): # Given an argument klass that is not a Model, Manager, or Queryset # raises a helpful ValueError message - self.assertRaisesMessage(ValueError, + self.assertRaisesMessage( + ValueError, "Object is of type 'str', but must be a Django Model, Manager, " "or QuerySet", get_object_or_404, str("Article"), title__icontains="Run" @@ -93,14 +98,16 @@ class GetObjectOr404Tests(TestCase): class CustomClass(object): pass - self.assertRaisesMessage(ValueError, + self.assertRaisesMessage( + ValueError, "Object is of type 'CustomClass', but must be a Django Model, " "Manager, or QuerySet", get_object_or_404, CustomClass, title__icontains="Run" ) # Works for lists too - self.assertRaisesMessage(ValueError, + self.assertRaisesMessage( + ValueError, "Object is of type 'list', but must be a Django Model, Manager, " "or QuerySet", get_list_or_404, [Article], title__icontains="Run" diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py index d4aca54c91..1ddb2447fe 100644 --- a/tests/get_or_create/tests.py +++ b/tests/get_or_create/tests.py @@ -45,14 +45,16 @@ class GetOrCreateTests(TestCase): # If you don't specify a value or default value for all required # fields, you will get an error. - self.assertRaises(IntegrityError, + self.assertRaises( + IntegrityError, Person.objects.get_or_create, first_name="Tom", last_name="Smith" ) # If you specify an existing primary key, but different other fields, # then you will get an error and data will not be updated. ManualPrimaryKeyTest.objects.create(id=1, data="Original") - self.assertRaises(IntegrityError, + self.assertRaises( + IntegrityError, ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different" ) self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") @@ -181,7 +183,8 @@ class UpdateOrCreateTests(TestCase): # If you specify an existing primary key, but different other fields, # then you will get an error and data will not be updated. ManualPrimaryKeyTest.objects.create(id=1, data="Original") - self.assertRaises(IntegrityError, + self.assertRaises( + IntegrityError, ManualPrimaryKeyTest.objects.update_or_create, id=1, data="Different" ) self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original") diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py index 707115878f..e3c37bb320 100644 --- a/tests/inline_formsets/tests.py +++ b/tests/inline_formsets/tests.py @@ -123,7 +123,8 @@ class InlineFormsetFactoryTest(TestCase): Child has two ForeignKeys to Parent, so if we don't specify which one to use for the inline formset, we should get an exception. """ - six.assertRaisesRegex(self, Exception, + six.assertRaisesRegex( + self, Exception, "<class 'inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'inline_formsets.models.Parent'>", inlineformset_factory, Parent, Child ) @@ -133,7 +134,8 @@ class InlineFormsetFactoryTest(TestCase): If we specify fk_name, but it isn't a ForeignKey from the child model to the parent model, we should get an exception. """ - self.assertRaises(Exception, + self.assertRaises( + Exception, "fk_name 'school' is not a ForeignKey to <class 'inline_formsets.models.Parent'>", inlineformset_factory, Parent, Child, fk_name='school' ) @@ -143,7 +145,8 @@ class InlineFormsetFactoryTest(TestCase): If the field specified in fk_name is not a ForeignKey, we should get an exception. """ - six.assertRaisesRegex(self, Exception, + six.assertRaisesRegex( + self, Exception, "<class 'inline_formsets.models.Child'> has no field named 'test'", inlineformset_factory, Parent, Child, fk_name='test' ) diff --git a/tests/m2m_regress/tests.py b/tests/m2m_regress/tests.py index eaba53a5b4..d1f85ace3e 100644 --- a/tests/m2m_regress/tests.py +++ b/tests/m2m_regress/tests.py @@ -36,7 +36,8 @@ class M2MRegressionTests(TestCase): # The secret internal related names for self-referential many-to-many # fields shouldn't appear in the list when an error is made. - six.assertRaisesRegex(self, FieldError, + six.assertRaisesRegex( + self, FieldError, "Choices are: id, name, references, related, selfreferchild, selfreferchildsibling$", lambda: SelfRefer.objects.filter(porcupine='fred') ) diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index 8f1f7fc926..cefe74b95e 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -178,8 +178,9 @@ class ManyToOneTests(TestCase): ]) # ... and should work fine with the unicode that comes out of forms.Form.cleaned_data self.assertQuerysetEqual( - Article.objects.filter(reporter__first_name__exact='John' - ).extra(where=["many_to_one_reporter.last_name='%s'" % 'Smith']), + (Article.objects + .filter(reporter__first_name__exact='John') + .extra(where=["many_to_one_reporter.last_name='%s'" % 'Smith'])), [ "<Article: John's second story>", "<Article: This is a test>", diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py index 83c6118c9d..47852f35fa 100644 --- a/tests/middleware_exceptions/tests.py +++ b/tests/middleware_exceptions/tests.py @@ -788,6 +788,4 @@ class RootUrlconfTests(TestCase): # Removing ROOT_URLCONF is safe, as override_settings will restore # the previously defined settings. del settings.ROOT_URLCONF - self.assertRaises(AttributeError, - self.client.get, "/middleware_exceptions/view/" - ) + self.assertRaises(AttributeError, self.client.get, "/middleware_exceptions/view/") diff --git a/tests/model_validation/tests.py b/tests/model_validation/tests.py index c55a1307e1..225656e4cb 100644 --- a/tests/model_validation/tests.py +++ b/tests/model_validation/tests.py @@ -32,16 +32,18 @@ class ModelValidationTest(TestCase): post_init.connect(OnPostInit(), sender='missing-app.Model') e = ModelErrorCollection(six.StringIO()) validate_model_signals(e) - self.assertSetEqual(set(e.errors), { - ('model_validation.tests', + self.assertSetEqual( + set(e.errors), + {( + 'model_validation.tests', "The `on_post_init` function was connected to the `post_init` " "signal with a lazy reference to the 'missing-app.Model' " "sender, which has not been installed." - ), - ('model_validation.tests', + ), ( + 'model_validation.tests', "An instance of the `OnPostInit` class was connected to " "the `post_init` signal with a lazy reference to the " "'missing-app.Model' sender, which has not been installed." - ) - }) + )} + ) post_init.unresolved_references = unresolved_references diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 99cbc29951..38bfcc25dd 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -545,7 +545,8 @@ class ValidationTests(unittest.TestCase): site = AdminSite() - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.", site.register, @@ -562,7 +563,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): raw_id_fields = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -572,7 +574,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): raw_id_fields = ('non_existent_field',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -582,7 +585,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): raw_id_fields = ('name',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.raw_id_fields\[0\]', 'name' must be either a ForeignKey or ManyToManyField.", ValidationTestModelAdmin.validate, @@ -599,7 +603,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.fieldsets' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -609,7 +614,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = ({},) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.fieldsets\[0\]' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -619,7 +625,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = ((),) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.fieldsets\[0\]' does not have exactly two elements.", ValidationTestModelAdmin.validate, @@ -629,7 +636,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = (("General", ()),) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.fieldsets\[0\]\[1\]' must be a dictionary.", ValidationTestModelAdmin.validate, @@ -639,7 +647,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = (("General", {}),) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'fields' key is required in ValidationTestModelAdmin.fieldsets\[0\]\[1\] field options dict.", ValidationTestModelAdmin.validate, @@ -655,7 +664,8 @@ class ValidationTests(unittest.TestCase): fieldsets = (("General", {"fields": ("name",)}),) fields = ["name"] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "Both fieldsets and fields are specified in ValidationTestModelAdmin.", ValidationTestModelAdmin.validate, @@ -665,7 +675,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fieldsets = [(None, {'fields': ['name', 'name']})] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "There are duplicate field\(s\) in ValidationTestModelAdmin.fieldsets", ValidationTestModelAdmin.validate, @@ -675,7 +686,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): fields = ["name", "name"] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "There are duplicate field\(s\) in ValidationTestModelAdmin.fields", ValidationTestModelAdmin.validate, @@ -690,7 +702,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): form = FakeForm - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "ValidationTestModelAdmin.form does not inherit from BaseModelForm.", ValidationTestModelAdmin.validate, @@ -727,7 +740,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_vertical = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_vertical' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -737,7 +751,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_vertical = ("non_existent_field",) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -747,7 +762,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_vertical = ("name",) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_vertical\[0\]' must be a ManyToManyField.", ValidationTestModelAdmin.validate, @@ -764,7 +780,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_horizontal = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_horizontal' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -774,7 +791,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_horizontal = ("non_existent_field",) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -784,7 +802,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): filter_horizontal = ("name",) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.filter_horizontal\[0\]' must be a ManyToManyField.", ValidationTestModelAdmin.validate, @@ -801,7 +820,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): radio_fields = () - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.radio_fields' must be a dictionary.", ValidationTestModelAdmin.validate, @@ -811,7 +831,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): radio_fields = {"non_existent_field": None} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -821,7 +842,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): radio_fields = {"name": None} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.radio_fields\['name'\]' is neither an instance of ForeignKey nor does have choices set.", ValidationTestModelAdmin.validate, @@ -831,7 +853,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): radio_fields = {"state": None} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.radio_fields\['state'\]' is neither admin.HORIZONTAL nor admin.VERTICAL.", ValidationTestModelAdmin.validate, @@ -848,7 +871,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): prepopulated_fields = () - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.prepopulated_fields' must be a dictionary.", ValidationTestModelAdmin.validate, @@ -858,7 +882,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): prepopulated_fields = {"non_existent_field": None} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -868,7 +893,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): prepopulated_fields = {"slug": ("non_existent_field",)} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -878,7 +904,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): prepopulated_fields = {"users": ("name",)} - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.prepopulated_fields\['users'\]' is either a DateTimeField, ForeignKey or ManyToManyField. This isn't allowed.", ValidationTestModelAdmin.validate, @@ -895,7 +922,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_display' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -905,7 +933,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display = ('non_existent_field',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, str_prefix("ValidationTestModelAdmin.list_display\[0\], %(_)s'non_existent_field' is not a callable or an attribute of 'ValidationTestModelAdmin' or found in the model 'ValidationTestModel'."), ValidationTestModelAdmin.validate, @@ -915,7 +944,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display = ('users',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_display\[0\]', 'users' is a ManyToManyField which is not supported.", ValidationTestModelAdmin.validate, @@ -937,7 +967,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display_links = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_display_links' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -947,7 +978,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display_links = ('non_existent_field',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' which is not defined in 'list_display'.", ValidationTestModelAdmin.validate, @@ -957,7 +989,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_display_links = ('name',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'name' which is not defined in 'list_display'.", ValidationTestModelAdmin.validate, @@ -985,7 +1018,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -995,7 +1029,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = ('non_existent_field',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter\[0\]' refers to 'non_existent_field' which does not refer to a Field.", ValidationTestModelAdmin.validate, @@ -1008,7 +1043,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = (RandomClass,) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter\[0\]' is 'RandomClass' which is not a descendant of ListFilter.", ValidationTestModelAdmin.validate, @@ -1018,7 +1054,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = (('is_active', RandomClass),) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter\[0\]\[1\]' is 'RandomClass' which is not of type FieldListFilter.", ValidationTestModelAdmin.validate, @@ -1038,7 +1075,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = (('is_active', AwesomeFilter),) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter\[0\]\[1\]' is 'AwesomeFilter' which is not of type FieldListFilter.", ValidationTestModelAdmin.validate, @@ -1048,7 +1086,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_filter = (BooleanFieldListFilter,) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_filter\[0\]' is 'BooleanFieldListFilter' which is of type FieldListFilter but is not associated with a field name.", ValidationTestModelAdmin.validate, @@ -1067,7 +1106,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_per_page = 'hello' - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_per_page' should be a int.", ValidationTestModelAdmin.validate, @@ -1084,7 +1124,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): list_max_show_all = 'hello' - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.list_max_show_all' should be a int.", ValidationTestModelAdmin.validate, @@ -1101,7 +1142,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): search_fields = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.search_fields' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -1113,7 +1155,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): date_hierarchy = 'non_existent_field' - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -1123,7 +1166,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): date_hierarchy = 'name' - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.date_hierarchy is neither an instance of DateField nor DateTimeField.", ValidationTestModelAdmin.validate, @@ -1140,7 +1184,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): ordering = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.ordering' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -1150,7 +1195,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): ordering = ('non_existent_field',) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.", ValidationTestModelAdmin.validate, @@ -1160,7 +1206,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): ordering = ('?', 'name') - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.ordering' has the random ordering marker '\?', but contains other fields as well. Please either remove '\?' or the other fields.", ValidationTestModelAdmin.validate, @@ -1206,7 +1253,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): save_as = 1 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.save_as' should be a bool.", ValidationTestModelAdmin.validate, @@ -1223,7 +1271,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): save_on_top = 1 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.save_on_top' should be a bool.", ValidationTestModelAdmin.validate, @@ -1240,7 +1289,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = 10 - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.inlines' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -1253,7 +1303,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.inlines\[0\]' does not inherit from BaseModelAdmin.", ValidationTestModelAdmin.validate, @@ -1266,7 +1317,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'model' is a required attribute of 'ValidationTestModelAdmin.inlines\[0\]'.", ValidationTestModelAdmin.validate, @@ -1282,7 +1334,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestModelAdmin.inlines\[0\].model' does not inherit from models.Model.", ValidationTestModelAdmin.validate, @@ -1306,7 +1359,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestInline.fields' must be a list or tuple.", ValidationTestModelAdmin.validate, @@ -1322,7 +1376,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestInlineModel'.", ValidationTestModelAdmin.validate, @@ -1347,7 +1402,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestInline.extra' should be a int.", ValidationTestModelAdmin.validate, @@ -1372,7 +1428,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestInline.max_num' should be a int.", ValidationTestModelAdmin.validate, @@ -1400,7 +1457,8 @@ class ValidationTests(unittest.TestCase): class ValidationTestModelAdmin(ModelAdmin): inlines = [ValidationTestInline] - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ImproperlyConfigured, "'ValidationTestInline.formset' does not inherit from BaseModelFormSet.", ValidationTestModelAdmin.validate, diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py index 3582625f45..8be7929ac4 100644 --- a/tests/proxy_models/tests.py +++ b/tests/proxy_models/tests.py @@ -91,15 +91,18 @@ class ProxyModelTests(TestCase): LowerStatusPerson.objects.create(status="low", name="homer") max_id = Person.objects.aggregate(max_id=models.Max('id'))['max_id'] - self.assertRaises(Person.DoesNotExist, + self.assertRaises( + Person.DoesNotExist, MyPersonProxy.objects.get, name='Zathras' ) - self.assertRaises(Person.MultipleObjectsReturned, + self.assertRaises( + Person.MultipleObjectsReturned, MyPersonProxy.objects.get, id__lt=max_id + 1 ) - self.assertRaises(Person.DoesNotExist, + self.assertRaises( + Person.DoesNotExist, StatusPerson.objects.get, name='Zathras' ) @@ -108,7 +111,8 @@ class ProxyModelTests(TestCase): StatusPerson.objects.create(name='Foo Jr.') max_id = Person.objects.aggregate(max_id=models.Max('id'))['max_id'] - self.assertRaises(Person.MultipleObjectsReturned, + self.assertRaises( + Person.MultipleObjectsReturned, StatusPerson.objects.get, id__lt=max_id + 1 ) @@ -344,7 +348,8 @@ class ProxyModelTests(TestCase): resp = ProxyImprovement.objects.select_related().get( reporter__name__icontains='butor' ) - self.assertEqual(repr(resp), + self.assertEqual( + repr(resp), '<ProxyImprovement: ProxyImprovement:improve that>' ) @@ -352,7 +357,8 @@ class ProxyModelTests(TestCase): resp = ProxyImprovement.objects.select_related().get( associated_bug__summary__icontains='fix' ) - self.assertEqual(repr(resp), + self.assertEqual( + repr(resp), '<ProxyImprovement: ProxyImprovement:improve that>' ) diff --git a/tests/raw_query/tests.py b/tests/raw_query/tests.py index b57ce52f0b..4c30984e9c 100644 --- a/tests/raw_query/tests.py +++ b/tests/raw_query/tests.py @@ -234,6 +234,4 @@ class RawQueryTests(TestCase): ) def test_query_count(self): - self.assertNumQueries(1, - list, Author.objects.raw("SELECT * FROM raw_query_author") - ) + self.assertNumQueries(1, list, Author.objects.raw("SELECT * FROM raw_query_author")) diff --git a/tests/select_related/tests.py b/tests/select_related/tests.py index 59b19d97f6..52aff92a7c 100644 --- a/tests/select_related/tests.py +++ b/tests/select_related/tests.py @@ -100,8 +100,9 @@ class SelectRelatedTests(TestCase): ['Agaricales', 'Diptera', 'Fabales', 'Primates']) def test_select_related_with_extra(self): - s = Species.objects.all().select_related()\ - .extra(select={'a': 'select_related_species.id + 10'})[0] + s = (Species.objects.all() + .select_related() + .extra(select={'a': 'select_related_species.id + 10'})[0]) self.assertEqual(s.id + 10, s.a) def test_certain_fields(self): @@ -131,12 +132,14 @@ class SelectRelatedTests(TestCase): def test_field_traversal(self): with self.assertNumQueries(1): - s = Species.objects.all().select_related('genus__family__order' - ).order_by('id')[0:1].get().genus.family.order.name + s = (Species.objects.all() + .select_related('genus__family__order') + .order_by('id')[0:1].get().genus.family.order.name) self.assertEqual(s, 'Diptera') def test_depth_fields_fails(self): - self.assertRaises(TypeError, + self.assertRaises( + TypeError, Species.objects.select_related, 'genus__family__order', depth=4 ) diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index e7c1383373..a218194e4c 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -362,7 +362,8 @@ class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated): # we set DEBUG to False here since the template tag wouldn't work otherwise -@override_settings(**dict(TEST_SETTINGS, +@override_settings(**dict( + TEST_SETTINGS, STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage', DEBUG=False, )) @@ -569,7 +570,8 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, # we set DEBUG to False here since the template tag wouldn't work otherwise -@override_settings(**dict(TEST_SETTINGS, +@override_settings(**dict( + TEST_SETTINGS, STATICFILES_STORAGE='staticfiles_tests.storage.SimpleCachedStaticFilesStorage', DEBUG=False, )) diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py index 2945bfabce..275d7ea4be 100644 --- a/tests/template_tests/test_parser.py +++ b/tests/template_tests/test_parser.py @@ -58,9 +58,7 @@ class ParserTests(TestCase): # Filtered variables should reject access of attributes beginning with # underscores. - self.assertRaises(TemplateSyntaxError, - FilterExpression, "article._hidden|upper", p - ) + self.assertRaises(TemplateSyntaxError, FilterExpression, "article._hidden|upper", p) def test_variable_parsing(self): c = {"article": {"section": "News"}} @@ -83,9 +81,7 @@ class ParserTests(TestCase): # Variables should reject access of attributes beginning with # underscores. - self.assertRaises(TemplateSyntaxError, - Variable, "article._hidden" - ) + self.assertRaises(TemplateSyntaxError, Variable, "article._hidden") # Variables should raise on non string type with six.assertRaisesRegex(self, TypeError, "Variable must be a string or number, got <(class|type) 'dict'>"): diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 9f7831d2b7..7426155e2a 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -56,9 +56,7 @@ class AssertNumQueriesTests(TestCase): def test_func(): raise ValueError - self.assertRaises(ValueError, - self.assertNumQueries, 2, test_func - ) + self.assertRaises(ValueError, self.assertNumQueries, 2, test_func) def test_assert_num_queries_with_client(self): person = Person.objects.create(name='test') |
