Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed E124 pep8 warnings.

  • Loading branch information...
commit a2814846ca006b4fbf3a893ec52cd9d444b3a3eb 1 parent 0873200
@loic loic authored timgraham committed
Showing with 371 additions and 262 deletions.
  1. +2 −1  django/contrib/admin/helpers.py
  2. +4 −2 django/contrib/admin/options.py
  3. +2 −1  django/contrib/admin/sites.py
  4. +2 −1  django/contrib/admin/templatetags/admin_list.py
  5. +2 −1  django/contrib/admindocs/tests/test_fields.py
  6. +9 −18 django/contrib/admindocs/urls.py
  7. +2 −2 django/contrib/auth/admin.py
  8. +10 −5 django/contrib/auth/tests/test_basic.py
  9. +10 −5 django/contrib/auth/tests/test_management.py
  10. +4 −3 django/contrib/contenttypes/generic.py
  11. +14 −11 django/contrib/gis/db/models/query.py
  12. +2 −1  django/contrib/gis/forms/widgets.py
  13. +5 −4 django/contrib/gis/tests/geoapp/test_regress.py
  14. +2 −1  django/core/management/commands/testserver.py
  15. +6 −6 django/core/management/validation.py
  16. +1 −2  django/db/backends/__init__.py
  17. +5 −3 django/db/backends/mysql/base.py
  18. +2 −1  django/db/backends/postgresql_psycopg2/base.py
  19. +64 −50 django/db/migrations/optimizer.py
  20. +1 −2  django/db/models/fields/__init__.py
  21. +1 −2  django/db/models/fields/related.py
  22. +8 −10 django/forms/utils.py
  23. +1 −1  django/forms/widgets.py
  24. +2 −1  django/test/__init__.py
  25. +1 −2  django/test/simple.py
  26. +1 −2  django/utils/text.py
  27. +1 −1  setup.cfg
  28. +2 −1  tests/createsuperuser/tests.py
  29. +2 −1  tests/custom_columns/tests.py
  30. +2 −1  tests/custom_pk/tests.py
  31. +17 −12 tests/extra_regress/tests.py
  32. +14 −7 tests/get_object_or_404/tests.py
  33. +6 −3 tests/get_or_create/tests.py
  34. +6 −3 tests/inline_formsets/tests.py
  35. +2 −1  tests/m2m_regress/tests.py
  36. +3 −2 tests/many_to_one/tests.py
  37. +1 −3 tests/middleware_exceptions/tests.py
  38. +8 −6 tests/model_validation/tests.py
  39. +116 −58 tests/modeladmin/tests.py
  40. +12 −6 tests/proxy_models/tests.py
  41. +1 −3 tests/raw_query/tests.py
  42. +8 −5 tests/select_related/tests.py
  43. +4 −2 tests/staticfiles_tests/tests.py
  44. +2 −6 tests/template_tests/test_parser.py
  45. +1 −3 tests/test_utils/tests.py
View
3  django/contrib/admin/helpers.py
@@ -42,7 +42,8 @@ def __init__(self, form, fieldsets, prepopulated_fields, readonly_fields=None, m
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
View
6 django/contrib/admin/options.py
@@ -1520,7 +1520,8 @@ def changelist_view(self, request, extra_context=None):
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 @@ def delete_view(self, request, object_id, extra_context=None):
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,
View
3  django/contrib/admin/sites.py
@@ -398,7 +398,8 @@ def index(self, request, extra_context=None):
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,
)
View
3  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
)
View
3  django/contrib/admindocs/tests/test_fields.py
@@ -21,7 +21,8 @@ def setUp(self):
pass
def test_field_name(self):
- self.assertRaises(AttributeError,
+ self.assertRaises(
+ AttributeError,
views.get_readable_field_data_type, "NotAField"
)
View
27 django/contrib/admindocs/urls.py
@@ -4,38 +4,29 @@
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'),
)
View
4 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
View
15 django/contrib/auth/tests/test_basic.py
@@ -130,7 +130,8 @@ def test_createsuperuser_management_command(self):
"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 @@ def test_createsuperuser_management_command(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",
@@ -159,7 +161,8 @@ def test_createsuperuser_management_command(self):
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 @@ def test_createsuperuser_nolocale(self):
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 @@ def test_createsuperuser_non_ascii_verbose_name(self):
username_field.verbose_name = ulazy('uživatel')
new_io = StringIO()
try:
- call_command("createsuperuser",
+ call_command(
+ "createsuperuser",
interactive=True,
stdout=new_io
)
View
15 django/contrib/auth/tests/test_management.py
@@ -91,7 +91,8 @@ def test_createsuperuser(self):
"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 @@ def test_createsuperuser(self):
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 @@ def test_verbosity_zero(self):
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 @@ def test_swappable_user(self):
# 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 @@ def test_swappable_user_missing_required_field(self):
# 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,
View
7 django/contrib/contenttypes/generic.py
@@ -452,9 +452,10 @@ def __init__(self, data=None, files=None, instance=None, save_as_new=None,
@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(),
View
25 django/contrib/gis/db/models/query.py
@@ -362,12 +362,14 @@ def svg(self, relative=False, precision=8, **kwargs):
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 @@ def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
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
View
3  django/contrib/gis/forms/widgets.py
@@ -66,7 +66,8 @@ def render(self, name, value, attrs=None):
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),
View
9 django/contrib/gis/tests/geoapp/test_regress.py
@@ -33,10 +33,11 @@ def test_update(self):
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
View
3  django/core/management/commands/testserver.py
@@ -37,7 +37,8 @@ def handle(self, *fixture_labels, **options):
# 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,
View
12 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()
View
3  django/db/backends/__init__.py
@@ -1215,8 +1215,7 @@ def modify_insert_params(self, placeholders, params):
# 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):
View
8 django/db/backends/mysql/base.py
@@ -332,13 +332,15 @@ def sequence_reset_by_name_sql(self, style, sequences):
# 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 []
View
3  django/db/backends/postgresql_psycopg2/base.py
@@ -168,7 +168,8 @@ def close(self):
# 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
View
114 django/db/migrations/optimizer.py
@@ -176,12 +176,14 @@ def reduce_model_create_rename(self, operation, other):
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 @@ def reduce_model_rename_self(self, operation, other):
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 @@ def reduce_alter_field_delete_field(self, operation, other):
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():
View
3  django/db/models/fields/__init__.py
@@ -1686,8 +1686,7 @@ def get_default(self):
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
View
3  django/db/models/fields/related.py
@@ -963,8 +963,7 @@ def __init__(self, field, to, field_name, related_name=None, limit_choices_to=No
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
View
18 django/forms/utils.py
@@ -52,11 +52,10 @@ def __str__(self):
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 @@ def __str__(self):
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:
View
2  django/forms/widgets.py
@@ -72,7 +72,7 @@ def absolute_path(self, path, prefix=None):
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
View
3  django/test/__init__.py
@@ -3,7 +3,8 @@
"""
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
)
View
3  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):
View
3  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)
View
2  setup.cfg
@@ -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
View
3  tests/createsuperuser/tests.py
@@ -38,7 +38,8 @@ def test_createsuperuser_command_with_database_option(self):
" createsuperuser command should operate on specified DB"
new_io = StringIO()
- call_command("createsuperuser",
+ call_command(
+ "createsuperuser",
interactive=False,
username="joe",
email="joe@somewhere.org",
View
3  tests/custom_columns/tests.py
@@ -42,7 +42,8 @@ def test_filter_first_name(self):
)
def test_field_error(self):
- self.assertRaises(FieldError,
+ self.assertRaises(
+ FieldError,
lambda: Author.objects.filter(firstname__exact="John")
)
View
3  tests/custom_pk/tests.py
@@ -34,7 +34,8 @@ def test_custom_pk(self):
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)
)
View
29 tests/extra_regress/tests.py
@@ -91,14 +91,18 @@ def test_regression_7957(self):
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 @@ def test_regression_7961(self):
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 @@ def test_regression_8039(self):
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')),
[]
)
View
21 tests/get_object_or_404/tests.py
@@ -30,7 +30,8 @@ def test_get_object_or_404(self):
)
# 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 @@ def test_get_object_or_404(self):
# 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 @@ def test_get_object_or_404(self):
)
# 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 @@ def test_get_object_or_404(self):
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 @@ def test_bad_class(self):
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"
View
9 tests/get_or_create/tests.py
@@ -45,14 +45,16 @@ def test_get_or_create(self):
# 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 @@ def test_manual_primary_key_test(self):
# 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")
View
9 tests/inline_formsets/tests.py
@@ -123,7 +123,8 @@ def test_exception_on_unspecified_foreign_key(self):
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 @@ def test_fk_name_not_foreign_key_field_from_child(self):
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 @@ def test_non_foreign_key_field(self):
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'
)
View
3  tests/m2m_regress/tests.py
@@ -36,7 +36,8 @@ def test_internal_related_name_not_in_error_msg(self):
# 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')
)
View
5 tests/many_to_one/tests.py
@@ -178,8 +178,9 @@ def test_selects(self):
])
# ... 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>",
View
4 tests/middleware_exceptions/tests.py
@@ -788,6 +788,4 @@ def test_missing_root_urlconf(self):
# 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/")
View
14 tests/model_validation/tests.py
@@ -32,16 +32,18 @@ def test_model_signal(self):
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
View
174 tests/modeladmin/tests.py
@@ -545,7 +545,8 @@ class ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_raw_id_fields_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_fieldsets_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 FakeForm(object):
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 @@ def test_filter_vertical_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_filter_horizontal_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_radio_fields_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_prepopulated_fields_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_list_display_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_list_display_links_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_list_filter_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 RandomClass(object):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def get_queryset(self, cl, qs):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_list_per_page_validation(self):
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 @@ def test_max_show_all_allowed_validation(self):
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 @@ def test_search_fields_validation(self):
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 @@ def test_date_hierarchy_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_ordering_validation(self):
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 ValidationTestModelAdmin(ModelAdmin):
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 ValidationTestModelAdmin(ModelAdmin):
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 @@ def test_save_as_validation(self):
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 @@ def test_save_on_top_validation(self):
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 @@ def test_inlines_validation(self):
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 ValidationTestInline(object):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
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 ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
ImproperlyConfigured,
"'ValidationTestInline.formset' does not inherit from BaseModelFormSet.",
ValidationTestModelAdmin.validate,
View
18 tests/proxy_models/tests.py
@@ -91,15 +91,18 @@ def test_proxy_included_in_ancestors(self):
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 @@ def test_proxy_included_in_ancestors(self):
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 @@ def test_proxy_bug(self):
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 @@ def test_proxy_bug(self):
resp = ProxyImprovement.objects.select_related().get(
associated_bug__summary__icontains='fix'
)
- self.assertEqual(repr(resp),
+ self.assertEqual(
+ repr(resp),
'<ProxyImprovement: ProxyImprovement:improve that>'
)
View
4 tests/raw_query/tests.py
@@ -234,6 +234,4 @@ def test_inheritance(self):
)
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"))
View
13 tests/select_related/tests.py
@@ -100,8 +100,9 @@ def test_list_with_depth(self):
['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 @@ def test_more_certain_fields(self):
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
)
View
6 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 @@ def test_post_processing_failure(self):
# 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,
))
View
8 tests/template_tests/test_parser.py
@@ -58,9 +58,7 @@ def fe_test(s, val):
# 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 @@ def test_variable_parsing(self):
# 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'>"):
View
4 tests/test_utils/tests.py
@@ -56,9 +56,7 @@ def test_assert_num_queries(self):
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')
Please sign in to comment.
Something went wrong with that request. Please try again.