From 0004daa536890fdb389c895baaa21bea6a1f7073 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 2 Jan 2019 18:18:19 -0500 Subject: [PATCH] Used 4 space hanging indent for dictionaries. Thanks Mariusz Felisiak for auditing. --- django/contrib/admin/options.py | 8 +- .../contrib/admin/templatetags/admin_list.py | 31 ++-- django/contrib/auth/admin.py | 5 +- django/contrib/gis/admin/options.py | 69 ++++----- django/contrib/gis/gdal/geometries.py | 33 ++--- django/contrib/gis/gdal/geomtype.py | 39 +++--- django/contrib/gis/utils/layermapping.py | 16 +-- django/contrib/gis/utils/srs.py | 12 +- django/db/models/fields/__init__.py | 8 +- django/forms/formsets.py | 16 ++- django/template/defaulttags.py | 19 +-- django/utils/feedgenerator.py | 6 +- tests/admin_filters/tests.py | 18 ++- tests/admin_views/admin.py | 12 +- tests/admin_views/tests.py | 59 ++++---- tests/fixtures/tests.py | 22 +-- tests/forms_tests/tests/test_forms.py | 10 +- tests/gis_tests/geoapp/sitemaps.py | 7 +- tests/gis_tests/geoapp/test_functions.py | 14 +- tests/gis_tests/geogapp/tests.py | 10 +- tests/gis_tests/layermap/models.py | 29 ++-- tests/gis_tests/layermap/tests.py | 14 +- tests/introspection/tests.py | 8 +- tests/logging_tests/tests.py | 7 +- tests/mail/tests.py | 10 +- tests/model_forms/tests.py | 28 ++-- tests/model_formsets_regress/tests.py | 10 +- tests/requests/tests.py | 132 +++++++++++------- tests/timezones/tests.py | 31 ++-- tests/utils_tests/test_datastructures.py | 11 +- tests/view_tests/tests/test_debug.py | 12 +- 31 files changed, 399 insertions(+), 307 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index e5d79d2c6d..0d10d29a04 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -2087,9 +2087,11 @@ class InlineModelAdmin(BaseModelAdmin): 'class_name': p._meta.verbose_name, 'instance': p} ) - params = {'class_name': self._meta.model._meta.verbose_name, - 'instance': self.instance, - 'related_objects': get_text_list(objs, _('and'))} + params = { + 'class_name': self._meta.model._meta.verbose_name, + 'instance': self.instance, + 'related_objects': get_text_list(objs, _('and')), + } msg = _("Deleting %(class_name)s %(instance)s would require " "deleting the following protected related objects: " "%(related_objects)s") diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 99013f0d9f..b03e4b6470 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -36,10 +36,12 @@ def paginator_number(cl, i): elif i == cl.page_num: return format_html('{} ', i + 1) else: - return format_html('{} ', - cl.get_query_string({PAGE_VAR: i}), - mark_safe(' class="end"' if i == cl.paginator.num_pages - 1 else ''), - i + 1) + return format_html( + '{} ', + cl.get_query_string({PAGE_VAR: i}), + mark_safe(' class="end"' if i == cl.paginator.num_pages - 1 else ''), + i + 1, + ) def pagination(cl): @@ -190,8 +192,7 @@ def result_headers(cl): def _boolean_icon(field_val): - icon_url = static('admin/img/icon-%s.svg' % - {True: 'yes', False: 'no', None: 'unknown'}[field_val]) + icon_url = static('admin/img/icon-%s.svg' % {True: 'yes', False: 'no', None: 'unknown'}[field_val]) return format_html('{}', icon_url, field_val) @@ -279,11 +280,7 @@ def items_for_result(cl, result, form): ) if cl.is_popup else '', result_repr) - yield format_html('<{}{}>{}', - table_tag, - row_class, - link_or_text, - table_tag) + yield format_html('<{}{}>{}', table_tag, row_class, link_or_text, table_tag) else: # By default the fields come from ModelAdmin.list_editable, but if we pull # the fields out of the form instead of list_editable custom admins @@ -334,11 +331,13 @@ def result_list(cl): for h in headers: if h['sortable'] and h['sorted']: num_sorted_fields += 1 - return {'cl': cl, - 'result_hidden_fields': list(result_hidden_fields(cl)), - 'result_headers': headers, - 'num_sorted_fields': num_sorted_fields, - 'results': list(results(cl))} + return { + 'cl': cl, + 'result_hidden_fields': list(result_hidden_fields(cl)), + 'result_headers': headers, + 'num_sorted_fields': num_sorted_fields, + 'results': list(results(cl)), + } @register.tag(name='result_list') diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index 1056297468..6709e63485 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -44,8 +44,9 @@ class UserAdmin(admin.ModelAdmin): fieldsets = ( (None, {'fields': ('username', 'password')}), (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}), - (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', - 'groups', 'user_permissions')}), + (_('Permissions'), { + 'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'), + }), (_('Important dates'), {'fields': ('last_login', 'date_joined')}), ) add_fieldsets = ( diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index fe74df36ff..9b758a742d 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -86,40 +86,41 @@ class GeoModelAdmin(ModelAdmin): wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()] wms_options = ', %s' % ', '.join(wms_options) - params = {'default_lon': self.default_lon, - 'default_lat': self.default_lat, - 'default_zoom': self.default_zoom, - 'display_wkt': self.debug or self.display_wkt, - 'geom_type': OGRGeomType(db_field.geom_type), - 'field_name': db_field.name, - 'is_collection': is_collection, - 'scrollable': self.scrollable, - 'layerswitcher': self.layerswitcher, - 'collection_type': collection_type, - 'is_generic': db_field.geom_type == 'GEOMETRY', - 'is_linestring': db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'), - 'is_polygon': db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'), - 'is_point': db_field.geom_type in ('POINT', 'MULTIPOINT'), - 'num_zoom': self.num_zoom, - 'max_zoom': self.max_zoom, - 'min_zoom': self.min_zoom, - 'units': self.units, # likely should get from object - 'max_resolution': self.max_resolution, - 'max_extent': self.max_extent, - 'modifiable': self.modifiable, - 'mouse_position': self.mouse_position, - 'scale_text': self.scale_text, - 'map_width': self.map_width, - 'map_height': self.map_height, - 'point_zoom': self.point_zoom, - 'srid': self.map_srid, - 'display_srid': self.display_srid, - 'wms_url': self.wms_url, - 'wms_layer': self.wms_layer, - 'wms_name': self.wms_name, - 'wms_options': wms_options, - 'debug': self.debug, - } + params = { + 'default_lon': self.default_lon, + 'default_lat': self.default_lat, + 'default_zoom': self.default_zoom, + 'display_wkt': self.debug or self.display_wkt, + 'geom_type': OGRGeomType(db_field.geom_type), + 'field_name': db_field.name, + 'is_collection': is_collection, + 'scrollable': self.scrollable, + 'layerswitcher': self.layerswitcher, + 'collection_type': collection_type, + 'is_generic': db_field.geom_type == 'GEOMETRY', + 'is_linestring': db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'), + 'is_polygon': db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'), + 'is_point': db_field.geom_type in ('POINT', 'MULTIPOINT'), + 'num_zoom': self.num_zoom, + 'max_zoom': self.max_zoom, + 'min_zoom': self.min_zoom, + 'units': self.units, # likely should get from object + 'max_resolution': self.max_resolution, + 'max_extent': self.max_extent, + 'modifiable': self.modifiable, + 'mouse_position': self.mouse_position, + 'scale_text': self.scale_text, + 'map_width': self.map_width, + 'map_height': self.map_height, + 'point_zoom': self.point_zoom, + 'srid': self.map_srid, + 'display_srid': self.display_srid, + 'wms_url': self.wms_url, + 'wms_layer': self.wms_layer, + 'wms_name': self.wms_name, + 'wms_options': wms_options, + 'debug': self.debug, + } return OLMap diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 7adfe1ad87..6bc5df53cf 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -696,19 +696,20 @@ class MultiPolygon(GeometryCollection): # Class mapping dictionary (using the OGRwkbGeometryType as the key) -GEO_CLASSES = {1: Point, - 2: LineString, - 3: Polygon, - 4: MultiPoint, - 5: MultiLineString, - 6: MultiPolygon, - 7: GeometryCollection, - 101: LinearRing, - 1 + OGRGeomType.wkb25bit: Point, - 2 + OGRGeomType.wkb25bit: LineString, - 3 + OGRGeomType.wkb25bit: Polygon, - 4 + OGRGeomType.wkb25bit: MultiPoint, - 5 + OGRGeomType.wkb25bit: MultiLineString, - 6 + OGRGeomType.wkb25bit: MultiPolygon, - 7 + OGRGeomType.wkb25bit: GeometryCollection, - } +GEO_CLASSES = { + 1: Point, + 2: LineString, + 3: Polygon, + 4: MultiPoint, + 5: MultiLineString, + 6: MultiPolygon, + 7: GeometryCollection, + 101: LinearRing, + 1 + OGRGeomType.wkb25bit: Point, + 2 + OGRGeomType.wkb25bit: LineString, + 3 + OGRGeomType.wkb25bit: Polygon, + 4 + OGRGeomType.wkb25bit: MultiPoint, + 5 + OGRGeomType.wkb25bit: MultiLineString, + 6 + OGRGeomType.wkb25bit: MultiPolygon, + 7 + OGRGeomType.wkb25bit: GeometryCollection, +} diff --git a/django/contrib/gis/gdal/geomtype.py b/django/contrib/gis/gdal/geomtype.py index 3e5fea7484..591c680c59 100644 --- a/django/contrib/gis/gdal/geomtype.py +++ b/django/contrib/gis/gdal/geomtype.py @@ -7,25 +7,26 @@ class OGRGeomType: wkb25bit = -2147483648 # Dictionary of acceptable OGRwkbGeometryType s and their string names. - _types = {0: 'Unknown', - 1: 'Point', - 2: 'LineString', - 3: 'Polygon', - 4: 'MultiPoint', - 5: 'MultiLineString', - 6: 'MultiPolygon', - 7: 'GeometryCollection', - 100: 'None', - 101: 'LinearRing', - 102: 'PointZ', - 1 + wkb25bit: 'Point25D', - 2 + wkb25bit: 'LineString25D', - 3 + wkb25bit: 'Polygon25D', - 4 + wkb25bit: 'MultiPoint25D', - 5 + wkb25bit: 'MultiLineString25D', - 6 + wkb25bit: 'MultiPolygon25D', - 7 + wkb25bit: 'GeometryCollection25D', - } + _types = { + 0: 'Unknown', + 1: 'Point', + 2: 'LineString', + 3: 'Polygon', + 4: 'MultiPoint', + 5: 'MultiLineString', + 6: 'MultiPolygon', + 7: 'GeometryCollection', + 100: 'None', + 101: 'LinearRing', + 102: 'PointZ', + 1 + wkb25bit: 'Point25D', + 2 + wkb25bit: 'LineString25D', + 3 + wkb25bit: 'Polygon25D', + 4 + wkb25bit: 'MultiPoint25D', + 5 + wkb25bit: 'MultiLineString25D', + 6 + wkb25bit: 'MultiPolygon25D', + 7 + wkb25bit: 'GeometryCollection25D', + } # Reverse type dictionary, keyed by lowercase of the name. _str_types = {v.lower(): k for k, v in _types.items()} diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index 1faef51b8b..91537ba3ac 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -48,14 +48,14 @@ class LayerMapping: "A class that maps OGR Layers to GeoDjango Models." # Acceptable 'base' types for a multi-geometry type. - MULTI_TYPES = {1: OGRGeomType('MultiPoint'), - 2: OGRGeomType('MultiLineString'), - 3: OGRGeomType('MultiPolygon'), - OGRGeomType('Point25D').num: OGRGeomType('MultiPoint25D'), - OGRGeomType('LineString25D').num: OGRGeomType('MultiLineString25D'), - OGRGeomType('Polygon25D').num: OGRGeomType('MultiPolygon25D'), - } - + MULTI_TYPES = { + 1: OGRGeomType('MultiPoint'), + 2: OGRGeomType('MultiLineString'), + 3: OGRGeomType('MultiPolygon'), + OGRGeomType('Point25D').num: OGRGeomType('MultiPoint25D'), + OGRGeomType('LineString25D').num: OGRGeomType('MultiLineString25D'), + OGRGeomType('Polygon25D').num: OGRGeomType('MultiPolygon25D'), + } # Acceptable Django field types and corresponding acceptable OGR # counterparts. FIELD_TYPES = { diff --git a/django/contrib/gis/utils/srs.py b/django/contrib/gis/utils/srs.py index 4171a37ca4..b10cf263b3 100644 --- a/django/contrib/gis/utils/srs.py +++ b/django/contrib/gis/utils/srs.py @@ -53,12 +53,12 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, # Initializing the keyword arguments dictionary for both PostGIS # and SpatiaLite. - kwargs = {'srid': srs.srid, - 'auth_name': auth_name, - 'auth_srid': auth_srid or srs.srid, - 'proj4text': srs.proj4, - } - + kwargs = { + 'srid': srs.srid, + 'auth_name': auth_name, + 'auth_srid': auth_srid or srs.srid, + 'proj4text': srs.proj4, + } # Backend-specific fields for the SpatialRefSys model. srs_field_names = {f.name for f in SpatialRefSys._meta.get_fields()} if 'srtext' in srs_field_names: diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 298fec193d..d0a1324c79 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -854,9 +854,11 @@ class Field(RegisterLookupMixin): def formfield(self, form_class=None, choices_form_class=None, **kwargs): """Return a django.forms.Field instance for this field.""" - defaults = {'required': not self.blank, - 'label': capfirst(self.verbose_name), - 'help_text': self.help_text} + defaults = { + 'required': not self.blank, + 'label': capfirst(self.verbose_name), + 'help_text': self.help_text, + } if self.has_default(): if callable(self.default): defaults['initial'] = self.default diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 1b95bfa4c5..ed93fa852e 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -427,11 +427,17 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, # limit is simply max_num + DEFAULT_MAX_NUM (which is 2*DEFAULT_MAX_NUM # if max_num is None in the first place) absolute_max = max_num + DEFAULT_MAX_NUM - attrs = {'form': form, 'extra': extra, - 'can_order': can_order, 'can_delete': can_delete, - 'min_num': min_num, 'max_num': max_num, - 'absolute_max': absolute_max, 'validate_min': validate_min, - 'validate_max': validate_max} + attrs = { + 'form': form, + 'extra': extra, + 'can_order': can_order, + 'can_delete': can_delete, + 'min_num': min_num, + 'max_num': max_num, + 'absolute_max': absolute_max, + 'validate_min': validate_min, + 'validate_max': validate_max, + } return type(form.__name__ + 'FormSet', (formset,), attrs) diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index f9ea6cf535..c4a37c25dd 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -399,15 +399,16 @@ class SpacelessNode(Node): class TemplateTagNode(Node): - mapping = {'openblock': BLOCK_TAG_START, - 'closeblock': BLOCK_TAG_END, - 'openvariable': VARIABLE_TAG_START, - 'closevariable': VARIABLE_TAG_END, - 'openbrace': SINGLE_BRACE_START, - 'closebrace': SINGLE_BRACE_END, - 'opencomment': COMMENT_TAG_START, - 'closecomment': COMMENT_TAG_END, - } + mapping = { + 'openblock': BLOCK_TAG_START, + 'closeblock': BLOCK_TAG_END, + 'openvariable': VARIABLE_TAG_START, + 'closevariable': VARIABLE_TAG_END, + 'openbrace': SINGLE_BRACE_START, + 'closebrace': SINGLE_BRACE_END, + 'opencomment': COMMENT_TAG_START, + 'closecomment': COMMENT_TAG_END, + } def __init__(self, tagtype): self.tagtype = tagtype diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 5aba705f5b..f08e89b25c 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -198,8 +198,10 @@ class RssFeed(SyndicationFeed): handler.endElement("rss") def rss_attributes(self): - return {"version": self._version, - "xmlns:atom": "http://www.w3.org/2005/Atom"} + return { + 'version': self._version, + 'xmlns:atom': 'http://www.w3.org/2005/Atom', + } def write_items(self, handler): for item in self.items: diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py index 01e1076141..4ff7d012e5 100644 --- a/tests/admin_filters/tests.py +++ b/tests/admin_filters/tests.py @@ -322,8 +322,10 @@ class ListFiltersTests(TestCase): request.user = self.alfred changelist = modeladmin.get_changelist(request) - request = self.request_factory.get('/', {'date_registered__gte': self.today, - 'date_registered__lt': self.tomorrow}) + request = self.request_factory.get('/', { + 'date_registered__gte': self.today, + 'date_registered__lt': self.tomorrow}, + ) request.user = self.alfred changelist = modeladmin.get_changelist_instance(request) @@ -344,8 +346,10 @@ class ListFiltersTests(TestCase): ) ) - request = self.request_factory.get('/', {'date_registered__gte': self.today.replace(day=1), - 'date_registered__lt': self.next_month}) + request = self.request_factory.get('/', { + 'date_registered__gte': self.today.replace(day=1), + 'date_registered__lt': self.next_month}, + ) request.user = self.alfred changelist = modeladmin.get_changelist_instance(request) @@ -370,8 +374,10 @@ class ListFiltersTests(TestCase): ) ) - request = self.request_factory.get('/', {'date_registered__gte': self.today.replace(month=1, day=1), - 'date_registered__lt': self.next_year}) + request = self.request_factory.get('/', { + 'date_registered__gte': self.today.replace(month=1, day=1), + 'date_registered__lt': self.next_year}, + ) request.user = self.alfred changelist = modeladmin.get_changelist_instance(request) diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 5c4151c270..d09e7fa084 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -730,16 +730,20 @@ class RelatedPrepopulatedInline1(admin.StackedInline): model = RelatedPrepopulated extra = 1 autocomplete_fields = ['fk', 'm2m'] - prepopulated_fields = {'slug1': ['name', 'pubdate'], - 'slug2': ['status', 'name']} + prepopulated_fields = { + 'slug1': ['name', 'pubdate'], + 'slug2': ['status', 'name'], + } class RelatedPrepopulatedInline2(admin.TabularInline): model = RelatedPrepopulated extra = 1 autocomplete_fields = ['fk', 'm2m'] - prepopulated_fields = {'slug1': ['name', 'pubdate'], - 'slug2': ['status', 'name']} + prepopulated_fields = { + 'slug1': ['name', 'pubdate'], + 'slug2': ['status', 'name'], + } class RelatedPrepopulatedInline3(admin.TabularInline): diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index d4bd873d2a..93a93454d9 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1650,11 +1650,12 @@ class AdminViewPermissionsTest(TestCase): def test_add_view(self): """Test add view restricts access and actually adds items.""" - add_dict = {'title': 'Døm ikke', - 'content': '

great article

', - 'date_0': '2008-03-18', 'date_1': '10:54:39', - 'section': self.s1.pk} - + add_dict = { + 'title': 'Døm ikke', + 'content': '

great article

', + 'date_0': '2008-03-18', 'date_1': '10:54:39', + 'section': self.s1.pk, + } # Change User should not have access to add articles self.client.force_login(self.changeuser) # make sure the view removes test cookie @@ -1754,10 +1755,12 @@ class AdminViewPermissionsTest(TestCase): def test_change_view(self): """Change view should restrict access and allow users to edit items.""" - change_dict = {'title': 'Ikke fordømt', - 'content': '

edited article

', - 'date_0': '2008-03-18', 'date_1': '10:54:39', - 'section': self.s1.pk} + change_dict = { + 'title': 'Ikke fordømt', + 'content': '

edited article

', + 'date_0': '2008-03-18', 'date_1': '10:54:39', + 'section': self.s1.pk, + } article_change_url = reverse('admin:admin_views_article_change', args=(self.a1.pk,)) article_changelist_url = reverse('admin:admin_views_article_changelist') @@ -6023,15 +6026,16 @@ class AdminViewOnSiteTests(TestCase): # The form validation should fail because 'some_required_info' is # not included on the parent form, and the family_name of the parent # does not match that of the child - post_data = {"family_name": "Test1", - "dependentchild_set-TOTAL_FORMS": "1", - "dependentchild_set-INITIAL_FORMS": "0", - "dependentchild_set-MAX_NUM_FORMS": "1", - "dependentchild_set-0-id": "", - "dependentchild_set-0-parent": "", - "dependentchild_set-0-family_name": "Test2"} - response = self.client.post(reverse('admin:admin_views_parentwithdependentchildren_add'), - post_data) + post_data = { + 'family_name': 'Test1', + 'dependentchild_set-TOTAL_FORMS': '1', + 'dependentchild_set-INITIAL_FORMS': '0', + 'dependentchild_set-MAX_NUM_FORMS': '1', + 'dependentchild_set-0-id': '', + 'dependentchild_set-0-parent': '', + 'dependentchild_set-0-family_name': 'Test2', + } + response = self.client.post(reverse('admin:admin_views_parentwithdependentchildren_add'), post_data) self.assertFormError(response, 'adminform', 'some_required_info', ['This field is required.']) msg = "The form 'adminform' in context 0 does not contain the non-field error 'Error'" with self.assertRaisesMessage(AssertionError, msg): @@ -6050,18 +6054,19 @@ class AdminViewOnSiteTests(TestCase): Verifying that if the parent form fails validation, the inlines also run validation even if validation is contingent on parent form data """ - pwdc = ParentWithDependentChildren.objects.create(some_required_info=6, - family_name="Test1") + pwdc = ParentWithDependentChildren.objects.create(some_required_info=6, family_name='Test1') # The form validation should fail because 'some_required_info' is # not included on the parent form, and the family_name of the parent # does not match that of the child - post_data = {"family_name": "Test2", - "dependentchild_set-TOTAL_FORMS": "1", - "dependentchild_set-INITIAL_FORMS": "0", - "dependentchild_set-MAX_NUM_FORMS": "1", - "dependentchild_set-0-id": "", - "dependentchild_set-0-parent": str(pwdc.id), - "dependentchild_set-0-family_name": "Test1"} + post_data = { + 'family_name': 'Test2', + 'dependentchild_set-TOTAL_FORMS': '1', + 'dependentchild_set-INITIAL_FORMS': '0', + 'dependentchild_set-MAX_NUM_FORMS': '1', + 'dependentchild_set-0-id': '', + 'dependentchild_set-0-parent': str(pwdc.id), + 'dependentchild_set-0-family_name': 'Test1', + } response = self.client.post( reverse('admin:admin_views_parentwithdependentchildren_change', args=(pwdc.id,)), post_data ) diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 37b21fa296..059b0ed80a 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -53,15 +53,19 @@ class DumpDataAssertMixin: use_base_manager=False, exclude_list=[], primary_keys=''): new_io = StringIO() filename = filename and os.path.join(tempfile.gettempdir(), filename) - management.call_command('dumpdata', *args, **{'format': format, - 'stdout': new_io, - 'stderr': new_io, - 'output': filename, - 'use_natural_foreign_keys': natural_foreign_keys, - 'use_natural_primary_keys': natural_primary_keys, - 'use_base_manager': use_base_manager, - 'exclude': exclude_list, - 'primary_keys': primary_keys}) + management.call_command( + 'dumpdata', + *args, + format=format, + stdout=new_io, + stderr=new_io, + output=filename, + use_natural_foreign_keys=natural_foreign_keys, + use_natural_primary_keys=natural_primary_keys, + use_base_manager=use_base_manager, + exclude=exclude_list, + primary_keys=primary_keys, + ) if filename: with open(filename, "r") as f: command_output = f.read() diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index bad24b5230..d4e421d6ac 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2872,8 +2872,14 @@ Good luck picking a username that doesn't already exist.

self.assertEqual(form.errors, {'name': ['bad value not allowed']}) form = NameForm(data={'name': ['should be overly', 'long for the field names']}) self.assertFalse(form.is_valid()) - self.assertEqual(form.errors, {'name': ['Ensure this value has at most 10 characters (it has 16).', - 'Ensure this value has at most 10 characters (it has 24).']}) + self.assertEqual( + form.errors, { + 'name': [ + 'Ensure this value has at most 10 characters (it has 16).', + 'Ensure this value has at most 10 characters (it has 24).', + ], + } + ) form = NameForm(data={'name': ['fname', 'lname']}) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data, {'name': 'fname lname'}) diff --git a/tests/gis_tests/geoapp/sitemaps.py b/tests/gis_tests/geoapp/sitemaps.py index 1a3101290a..91e5d82bb4 100644 --- a/tests/gis_tests/geoapp/sitemaps.py +++ b/tests/gis_tests/geoapp/sitemaps.py @@ -2,6 +2,7 @@ from django.contrib.gis.sitemaps import KMLSitemap, KMZSitemap from .models import City, Country -sitemaps = {'kml': KMLSitemap([City, Country]), - 'kmz': KMZSitemap([City, Country]), - } +sitemaps = { + 'kml': KMLSitemap([City, Country]), + 'kmz': KMZSitemap([City, Country]), +} diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index 4b09cebb3e..e7eec26dd6 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -365,15 +365,17 @@ class GISFunctionsTests(FuncTestMixin, TestCase): if oracle: # SELECT SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOM.SDO_POINTONSURFACE(GEOAPP_COUNTRY.MPOLY, 0.05)) # FROM GEOAPP_COUNTRY; - ref = {'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326), - 'Texas': fromstr('POINT (-103.002434 36.500397)', srid=4326), - } + ref = { + 'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326), + 'Texas': fromstr('POINT (-103.002434 36.500397)', srid=4326), + } else: # Using GEOSGeometry to compute the reference point on surface values # -- since PostGIS also uses GEOS these should be the same. - ref = {'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface, - 'Texas': Country.objects.get(name='Texas').mpoly.point_on_surface - } + ref = { + 'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface, + 'Texas': Country.objects.get(name='Texas').mpoly.point_on_surface + } qs = Country.objects.annotate(point_on_surface=functions.PointOnSurface('mpoly')) for country in qs: diff --git a/tests/gis_tests/geogapp/tests.py b/tests/gis_tests/geogapp/tests.py index 7f6c441ba5..9cf8ab92f7 100644 --- a/tests/gis_tests/geogapp/tests.py +++ b/tests/gis_tests/geogapp/tests.py @@ -66,11 +66,11 @@ class GeographyTest(TestCase): # Getting the shapefile and mapping dictionary. shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) co_shp = os.path.join(shp_path, 'counties', 'counties.shp') - co_mapping = {'name': 'Name', - 'state': 'State', - 'mpoly': 'MULTIPOLYGON', - } - + co_mapping = { + 'name': 'Name', + 'state': 'State', + 'mpoly': 'MULTIPOLYGON', + } # Reference county names, number of polygons, and state names. names = ['Bexar', 'Galveston', 'Harris', 'Honolulu', 'Pueblo'] num_polys = [1, 2, 1, 19, 1] # Number of polygons for each. diff --git a/tests/gis_tests/layermap/models.py b/tests/gis_tests/layermap/models.py index de1dd6c944..7c029a0ee8 100644 --- a/tests/gis_tests/layermap/models.py +++ b/tests/gis_tests/layermap/models.py @@ -77,18 +77,21 @@ co_mapping = { 'mpoly': 'MULTIPOLYGON', # Will convert POLYGON features into MULTIPOLYGONS. } -cofeat_mapping = {'name': 'Name', - 'poly': 'POLYGON', - } +cofeat_mapping = { + 'name': 'Name', + 'poly': 'POLYGON', +} -city_mapping = {'name': 'Name', - 'population': 'Population', - 'density': 'Density', - 'dt': 'Created', - 'point': 'POINT', - } +city_mapping = { + 'name': 'Name', + 'population': 'Population', + 'density': 'Density', + 'dt': 'Created', + 'point': 'POINT', +} -inter_mapping = {'name': 'Name', - 'length': 'Length', - 'path': 'LINESTRING', - } +inter_mapping = { + 'name': 'Name', + 'length': 'Length', + 'path': 'LINESTRING', +} diff --git a/tests/gis_tests/layermap/tests.py b/tests/gis_tests/layermap/tests.py index a1b288eafa..460d6f6a4d 100644 --- a/tests/gis_tests/layermap/tests.py +++ b/tests/gis_tests/layermap/tests.py @@ -261,13 +261,13 @@ class LayerMapTest(TestCase): def test_model_inheritance(self): "Tests LayerMapping on inherited models. See #12093." - icity_mapping = {'name': 'Name', - 'population': 'Population', - 'density': 'Density', - 'point': 'POINT', - 'dt': 'Created', - } - + icity_mapping = { + 'name': 'Name', + 'population': 'Population', + 'density': 'Density', + 'point': 'POINT', + 'dt': 'Created', + } # Parent model has geometry field. lm1 = LayerMapping(ICity1, city_shp, icity_mapping) lm1.save() diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py index c61720d12b..a616ee0f98 100644 --- a/tests/introspection/tests.py +++ b/tests/introspection/tests.py @@ -163,10 +163,10 @@ class IntrospectionTests(TransactionTestCase): def test_get_key_columns(self): with connection.cursor() as cursor: key_columns = connection.introspection.get_key_columns(cursor, Article._meta.db_table) - self.assertEqual( - set(key_columns), - {('reporter_id', Reporter._meta.db_table, 'id'), - ('response_to_id', Article._meta.db_table, 'id')}) + self.assertEqual(set(key_columns), { + ('reporter_id', Reporter._meta.db_table, 'id'), + ('response_to_id', Article._meta.db_table, 'id'), + }) def test_get_primary_key_column(self): with connection.cursor() as cursor: diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 37010ab7d0..3ab905eab6 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -537,9 +537,10 @@ format=%(message)s self.temp_file = NamedTemporaryFile() self.temp_file.write(logging_conf.encode()) self.temp_file.flush() - sdict = {'LOGGING_CONFIG': '"logging.config.fileConfig"', - 'LOGGING': 'r"%s"' % self.temp_file.name} - self.write_settings('settings.py', sdict=sdict) + self.write_settings('settings.py', sdict={ + 'LOGGING_CONFIG': '"logging.config.fileConfig"', + 'LOGGING': 'r"%s"' % self.temp_file.name, + }) def tearDown(self): self.temp_file.close() diff --git a/tests/mail/tests.py b/tests/mail/tests.py index f0f91e7b40..f06e053074 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -323,9 +323,13 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): ) def test_unicode_headers(self): - email = EmailMessage("Gżegżółka", "Content", "from@example.com", ["to@example.com"], - headers={"Sender": '"Firstname Sürname" ', - "Comments": 'My Sürname is non-ASCII'}) + email = EmailMessage( + 'Gżegżółka', 'Content', 'from@example.com', ['to@example.com'], + headers={ + 'Sender': '"Firstname Sürname" ', + 'Comments': 'My Sürname is non-ASCII', + }, + ) message = email.message() self.assertEqual(message['Subject'], '=?utf-8?b?R8W8ZWfFvMOzxYJrYQ==?=') self.assertEqual(message['Sender'], '=?utf-8?q?Firstname_S=C3=BCrname?= ') diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 77075e52f9..f4f3169bc1 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1297,9 +1297,11 @@ class ModelFormBasicTests(TestCase): def test_basic_creation(self): self.assertEqual(Category.objects.count(), 0) - f = BaseCategoryForm({'name': 'Entertainment', - 'slug': 'entertainment', - 'url': 'entertainment'}) + f = BaseCategoryForm({ + 'name': 'Entertainment', + 'slug': 'entertainment', + 'url': 'entertainment', + }) self.assertTrue(f.is_valid()) self.assertEqual(f.cleaned_data['name'], 'Entertainment') self.assertEqual(f.cleaned_data['slug'], 'entertainment') @@ -1712,15 +1714,23 @@ class ModelMultipleChoiceFieldTests(TestCase): person1 = Writer.objects.create(name="Person 1") person2 = Writer.objects.create(name="Person 2") - form = WriterForm(initial={'persons': [person1, person2]}, - data={'initial-persons': [str(person1.pk), str(person2.pk)], - 'persons': [str(person1.pk), str(person2.pk)]}) + form = WriterForm( + initial={'persons': [person1, person2]}, + data={ + 'initial-persons': [str(person1.pk), str(person2.pk)], + 'persons': [str(person1.pk), str(person2.pk)], + }, + ) self.assertTrue(form.is_valid()) self.assertFalse(form.has_changed()) - form = WriterForm(initial={'persons': [person1, person2]}, - data={'initial-persons': [str(person1.pk), str(person2.pk)], - 'persons': [str(person2.pk)]}) + form = WriterForm( + initial={'persons': [person1, person2]}, + data={ + 'initial-persons': [str(person1.pk), str(person2.pk)], + 'persons': [str(person2.pk)], + }, + ) self.assertTrue(form.is_valid()) self.assertTrue(form.has_changed()) diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py index 0f86bbdb06..2232977481 100644 --- a/tests/model_formsets_regress/tests.py +++ b/tests/model_formsets_regress/tests.py @@ -296,10 +296,12 @@ class FormsetTests(TestCase): def test_extraneous_query_is_not_run(self): Formset = modelformset_factory(Network, fields="__all__") - data = {'test-TOTAL_FORMS': '1', - 'test-INITIAL_FORMS': '0', - 'test-MAX_NUM_FORMS': '', - 'test-0-name': 'Random Place'} + data = { + 'test-TOTAL_FORMS': '1', + 'test-INITIAL_FORMS': '0', + 'test-MAX_NUM_FORMS': '', + 'test-0-name': 'Random Place', + } with self.assertNumQueries(1): formset = Formset(data, prefix="test") formset.save() diff --git a/tests/requests/tests.py b/tests/requests/tests.py index 45e33ea651..c5efdad3c7 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -238,10 +238,12 @@ class RequestsTests(SimpleTestCase): def test_stream(self): payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload}, + ) self.assertEqual(request.read(), b'name=value') def test_read_after_value(self): @@ -250,10 +252,12 @@ class RequestsTests(SimpleTestCase): POST or body. """ payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) self.assertEqual(request.POST, {'name': ['value']}) self.assertEqual(request.body, b'name=value') self.assertEqual(request.read(), b'name=value') @@ -264,10 +268,12 @@ class RequestsTests(SimpleTestCase): from request. """ payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) self.assertEqual(request.read(2), b'na') with self.assertRaises(RawPostDataException): request.body @@ -310,10 +316,12 @@ class RequestsTests(SimpleTestCase): 'value', '--boundary--' ''])) - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) self.assertEqual(request.POST, {'name': ['value']}) with self.assertRaises(RawPostDataException): request.body @@ -334,10 +342,12 @@ class RequestsTests(SimpleTestCase): b'--boundary--' b'']) payload = FakePayload(payload_data) - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/related; boundary=boundary', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/related; boundary=boundary', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) self.assertEqual(request.POST, {}) self.assertEqual(request.body, payload_data) @@ -356,18 +366,22 @@ class RequestsTests(SimpleTestCase): 'value', '--boundary--' ''])) - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', - 'CONTENT_LENGTH': 0, - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', + 'CONTENT_LENGTH': 0, + 'wsgi.input': payload, + }) self.assertEqual(request.POST, {}) def test_POST_binary_only(self): payload = b'\r\n\x01\x00\x00\x00ab\x00\x00\xcd\xcc,@' - environ = {'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/octet-stream', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': BytesIO(payload)} + environ = { + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/octet-stream', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': BytesIO(payload), + } request = WSGIRequest(environ) self.assertEqual(request.POST, {}) self.assertEqual(request.FILES, {}) @@ -382,10 +396,12 @@ class RequestsTests(SimpleTestCase): def test_read_by_lines(self): payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) self.assertEqual(list(request), [b'name=value']) def test_POST_after_body_read(self): @@ -393,10 +409,12 @@ class RequestsTests(SimpleTestCase): POST should be populated even if body is read first """ payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) request.body # evaluate self.assertEqual(request.POST, {'name': ['value']}) @@ -406,10 +424,12 @@ class RequestsTests(SimpleTestCase): the stream is read second. """ payload = FakePayload('name=value') - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) request.body # evaluate self.assertEqual(request.read(1), b'n') self.assertEqual(request.POST, {'name': ['value']}) @@ -426,10 +446,12 @@ class RequestsTests(SimpleTestCase): 'value', '--boundary--' ''])) - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': payload}) + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': payload, + }) request.body # evaluate # Consume enough data to mess up the parsing: self.assertEqual(request.read(13), b'--boundary\r\nC') @@ -464,11 +486,12 @@ class RequestsTests(SimpleTestCase): raise IOError("kaboom!") payload = b'name=value' - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'application/x-www-form-urlencoded', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': ExplodingBytesIO(payload)}) - + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': ExplodingBytesIO(payload), + }) with self.assertRaises(UnreadablePostError): request.body @@ -504,11 +527,12 @@ class RequestsTests(SimpleTestCase): raise IOError("kaboom!") payload = b'x' - request = WSGIRequest({'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': 'multipart/form-data; boundary=foo_', - 'CONTENT_LENGTH': len(payload), - 'wsgi.input': ExplodingBytesIO(payload)}) - + request = WSGIRequest({ + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary=foo_', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': ExplodingBytesIO(payload), + }) with self.assertRaises(UnreadablePostError): request.FILES diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index 42be78ae25..06ac51594c 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -866,14 +866,18 @@ class TemplateTests(SimpleTestCase): # Use a pytz timezone as argument tpl = Template("{% load tz %}{{ dt|timezone:tz }}") - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), - 'tz': pytz.timezone('Europe/Paris')}) + ctx = Context({ + 'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), + 'tz': pytz.timezone('Europe/Paris'), + }) self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00") # Use a pytz timezone name as argument tpl = Template("{% load tz %}{{ dt|timezone:'Europe/Paris' }}") - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), - 'tz': pytz.timezone('Europe/Paris')}) + ctx = Context({ + 'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), + 'tz': pytz.timezone('Europe/Paris'), + }) self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00") def test_localtime_templatetag_invalid_argument(self): @@ -913,8 +917,11 @@ class TemplateTests(SimpleTestCase): "{% endtimezone %}" "{% endtimezone %}" ) - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC), - 'tz1': ICT, 'tz2': None}) + ctx = Context({ + 'dt': datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC), + 'tz1': ICT, + 'tz2': None, + }) self.assertEqual( tpl.render(ctx), "2011-09-01T13:20:30+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00" @@ -927,13 +934,17 @@ class TemplateTests(SimpleTestCase): tpl = Template("{% load tz %}{% timezone tz %}{{ dt }}{% endtimezone %}") # Use a pytz timezone as argument - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), - 'tz': pytz.timezone('Europe/Paris')}) + ctx = Context({ + 'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), + 'tz': pytz.timezone('Europe/Paris'), + }) self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00") # Use a pytz timezone name as argument - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), - 'tz': 'Europe/Paris'}) + ctx = Context({ + 'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), + 'tz': 'Europe/Paris', + }) self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00") def test_timezone_templatetag_invalid_argument(self): diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index 0db21fe5b2..806ad23721 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -32,9 +32,7 @@ class OrderedSetTests(SimpleTestCase): class MultiValueDictTests(SimpleTestCase): def test_multivaluedict(self): - d = MultiValueDict({'name': ['Adrian', 'Simon'], - 'position': ['Developer']}) - + d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}) self.assertEqual(d['name'], 'Simon') self.assertEqual(d.get('name'), 'Simon') self.assertEqual(d.getlist('name'), ['Adrian', 'Simon']) @@ -42,22 +40,17 @@ class MultiValueDictTests(SimpleTestCase): sorted(d.items()), [('name', 'Simon'), ('position', 'Developer')] ) - self.assertEqual( sorted(d.lists()), [('name', ['Adrian', 'Simon']), ('position', ['Developer'])] ) - with self.assertRaises(MultiValueDictKeyError) as cm: d.__getitem__('lastname') self.assertEqual(str(cm.exception), "'lastname'") - self.assertIsNone(d.get('lastname')) self.assertEqual(d.get('lastname', 'nonexistent'), 'nonexistent') self.assertEqual(d.getlist('lastname'), []) - self.assertEqual(d.getlist('doesnotexist', ['Adrian', 'Simon']), - ['Adrian', 'Simon']) - + self.assertEqual(d.getlist('doesnotexist', ['Adrian', 'Simon']), ['Adrian', 'Simon']) d.setlist('lastname', ['Holovaty', 'Willison']) self.assertEqual(d.getlist('lastname'), ['Holovaty', 'Willison']) self.assertEqual(sorted(d.values()), ['Developer', 'Simon', 'Willison']) diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 533d454c69..4b90acd05c 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -728,14 +728,14 @@ class PlainTextReportTests(SimpleTestCase): class ExceptionReportTestMixin: - # Mixin used in the ExceptionReporterFilterTests and # AjaxResponseExceptionReporterFilter tests below - - breakfast_data = {'sausage-key': 'sausage-value', - 'baked-beans-key': 'baked-beans-value', - 'hash-brown-key': 'hash-brown-value', - 'bacon-key': 'bacon-value'} + breakfast_data = { + 'sausage-key': 'sausage-value', + 'baked-beans-key': 'baked-beans-value', + 'hash-brown-key': 'hash-brown-value', + 'bacon-key': 'bacon-value', + } def verify_unsafe_response(self, view, check_for_vars=True, check_for_POST_params=True):