summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2025-07-22 20:41:41 -0700
committernessita <124304+nessita@users.noreply.github.com>2025-07-23 20:17:55 -0300
commit69a93a88edb56ba47f624dac7a21aacc47ea474f (patch)
treef57507a4435d032493cae40e06ecb254790b67b2 /tests
parent55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff)
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/tests.py19
-rw-r--r--tests/admin_checks/tests.py15
-rw-r--r--tests/admin_filters/tests.py6
-rw-r--r--tests/admin_inlines/tests.py12
-rw-r--r--tests/admin_scripts/tests.py79
-rw-r--r--tests/admin_utils/test_logentry.py3
-rw-r--r--tests/admin_utils/tests.py3
-rw-r--r--tests/admin_views/admin.py4
-rw-r--r--tests/admin_views/test_adminsite.py4
-rw-r--r--tests/admin_views/test_skip_link_to_content.py9
-rw-r--r--tests/admin_views/tests.py98
-rw-r--r--tests/admin_widgets/tests.py19
-rw-r--r--tests/aggregation/tests.py7
-rw-r--r--tests/aggregation_regress/tests.py27
-rw-r--r--tests/apps/tests.py7
-rw-r--r--tests/auth_tests/test_auth_backends.py12
-rw-r--r--tests/auth_tests/test_basic.py5
-rw-r--r--tests/auth_tests/test_context_processors.py3
-rw-r--r--tests/auth_tests/test_forms.py9
-rw-r--r--tests/auth_tests/test_hashers.py3
-rw-r--r--tests/auth_tests/test_management.py10
-rw-r--r--tests/auth_tests/test_remote_user.py6
-rw-r--r--tests/auth_tests/test_validators.py3
-rw-r--r--tests/auth_tests/test_views.py20
-rw-r--r--tests/backends/base/test_schema.py4
-rw-r--r--tests/backends/postgresql/tests.py3
-rw-r--r--tests/backends/tests.py12
-rw-r--r--tests/basic/tests.py6
-rw-r--r--tests/cache/tests.py41
-rw-r--r--tests/check_framework/test_security.py4
-rw-r--r--tests/check_framework/test_urls.py3
-rw-r--r--tests/contenttypes_tests/test_fields.py3
-rw-r--r--tests/contenttypes_tests/test_views.py5
-rw-r--r--tests/csrf_tests/tests.py9
-rw-r--r--tests/custom_lookups/tests.py3
-rw-r--r--tests/custom_managers/tests.py6
-rw-r--r--tests/datatypes/tests.py7
-rw-r--r--tests/decorators/tests.py3
-rw-r--r--tests/defer/tests.py6
-rw-r--r--tests/defer_regress/tests.py10
-rw-r--r--tests/delete/tests.py4
-rw-r--r--tests/dispatch/tests.py3
-rw-r--r--tests/expressions_window/tests.py4
-rw-r--r--tests/extra_regress/tests.py3
-rw-r--r--tests/field_deconstruction/tests.py6
-rw-r--r--tests/file_storage/tests.py16
-rw-r--r--tests/file_uploads/tests.py26
-rw-r--r--tests/file_uploads/views.py3
-rw-r--r--tests/files/tests.py4
-rw-r--r--tests/fixtures/tests.py24
-rw-r--r--tests/fixtures_regress/tests.py28
-rw-r--r--tests/flatpages_tests/test_csrf.py5
-rw-r--r--tests/flatpages_tests/test_middleware.py15
-rw-r--r--tests/flatpages_tests/test_templatetags.py15
-rw-r--r--tests/foreign_object/models/article.py4
-rw-r--r--tests/foreign_object/tests.py3
-rw-r--r--tests/forms_tests/field_tests/test_booleanfield.py3
-rw-r--r--tests/forms_tests/field_tests/test_charfield.py3
-rw-r--r--tests/forms_tests/field_tests/test_datefield.py4
-rw-r--r--tests/forms_tests/field_tests/test_filefield.py4
-rw-r--r--tests/forms_tests/field_tests/test_typedchoicefield.py11
-rw-r--r--tests/forms_tests/field_tests/test_typedmultiplechoicefield.py11
-rw-r--r--tests/forms_tests/tests/test_forms.py261
-rw-r--r--tests/forms_tests/tests/test_formsets.py4
-rw-r--r--tests/forms_tests/tests/test_input_formats.py55
-rw-r--r--tests/forms_tests/tests/test_media.py4
-rw-r--r--tests/forms_tests/tests/tests.py10
-rw-r--r--tests/forms_tests/widget_tests/base.py3
-rw-r--r--tests/generic_relations/tests.py8
-rw-r--r--tests/generic_relations_regress/tests.py3
-rw-r--r--tests/generic_views/test_base.py9
-rw-r--r--tests/generic_views/test_dates.py18
-rw-r--r--tests/generic_views/test_list.py3
-rw-r--r--tests/get_earliest_or_latest/tests.py7
-rw-r--r--tests/get_or_create/tests.py9
-rw-r--r--tests/gis_tests/distapp/tests.py17
-rw-r--r--tests/gis_tests/gdal_tests/test_ds.py4
-rw-r--r--tests/gis_tests/gdal_tests/test_envelope.py10
-rw-r--r--tests/gis_tests/gdal_tests/test_geom.py3
-rw-r--r--tests/gis_tests/gdal_tests/test_raster.py9
-rw-r--r--tests/gis_tests/gdal_tests/test_srs.py3
-rw-r--r--tests/gis_tests/geo3d/tests.py3
-rw-r--r--tests/gis_tests/geoapp/test_feeds.py3
-rw-r--r--tests/gis_tests/geoapp/test_functions.py20
-rw-r--r--tests/gis_tests/geoapp/test_regress.py14
-rw-r--r--tests/gis_tests/geoapp/tests.py23
-rw-r--r--tests/gis_tests/geogapp/tests.py4
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py35
-rw-r--r--tests/gis_tests/inspectapp/tests.py11
-rw-r--r--tests/gis_tests/layermap/tests.py39
-rw-r--r--tests/gis_tests/relatedapp/tests.py27
-rw-r--r--tests/gis_tests/test_geoforms.py6
-rw-r--r--tests/gis_tests/test_ptr.py6
-rw-r--r--tests/gis_tests/test_spatialrefsys.py3
-rw-r--r--tests/handlers/tests.py4
-rw-r--r--tests/httpwrappers/tests.py8
-rw-r--r--tests/humanize_tests/tests.py4
-rwxr-xr-xtests/i18n/sampleproject/update_catalogs.py3
-rw-r--r--tests/i18n/test_compilation.py21
-rw-r--r--tests/i18n/test_extraction.py33
-rw-r--r--tests/i18n/tests.py44
-rw-r--r--tests/inline_formsets/tests.py4
-rw-r--r--tests/inspectdb/tests.py4
-rw-r--r--tests/lookup/tests.py14
-rw-r--r--tests/m2m_regress/models.py6
-rw-r--r--tests/m2m_through/tests.py3
-rw-r--r--tests/mail/tests.py78
-rw-r--r--tests/many_to_many/tests.py10
-rw-r--r--tests/many_to_one/tests.py18
-rw-r--r--tests/many_to_one_null/tests.py6
-rw-r--r--tests/messages_tests/test_cookie.py4
-rw-r--r--tests/middleware/test_csp.py3
-rw-r--r--tests/middleware/test_security.py6
-rw-r--r--tests/migrations/test_autodetector.py79
-rw-r--r--tests/migrations/test_base.py3
-rw-r--r--tests/migrations/test_commands.py26
-rw-r--r--tests/migrations/test_executor.py10
-rw-r--r--tests/migrations/test_loader.py4
-rw-r--r--tests/migrations/test_operations.py9
-rw-r--r--tests/migrations/test_state.py10
-rw-r--r--tests/model_forms/test_modelchoicefield.py6
-rw-r--r--tests/model_forms/tests.py121
-rw-r--r--tests/model_formsets/models.py3
-rw-r--r--tests/model_formsets/tests.py22
-rw-r--r--tests/model_formsets_regress/tests.py3
-rw-r--r--tests/model_inheritance/test_abstract_inheritance.py3
-rw-r--r--tests/model_inheritance/tests.py6
-rw-r--r--tests/model_inheritance_regress/tests.py3
-rw-r--r--tests/model_meta/tests.py4
-rw-r--r--tests/modeladmin/test_checks.py3
-rw-r--r--tests/modeladmin/tests.py35
-rw-r--r--tests/multiple_database/tests.py86
-rw-r--r--tests/nested_foreign_keys/tests.py8
-rw-r--r--tests/null_fk/tests.py8
-rw-r--r--tests/null_fk_ordering/tests.py14
-rw-r--r--tests/one_to_one/tests.py26
-rw-r--r--tests/order_with_respect_to/base_tests.py14
-rw-r--r--tests/pagination/tests.py13
-rw-r--r--tests/postgres_tests/test_array.py3
-rw-r--r--tests/postgres_tests/test_search.py4
-rw-r--r--tests/prefetch_related/test_uuid.py3
-rw-r--r--tests/prefetch_related/tests.py32
-rw-r--r--tests/proxy_model_inheritance/tests.py7
-rw-r--r--tests/proxy_models/models.py3
-rw-r--r--tests/queries/tests.py80
-rw-r--r--tests/queryset_pickle/tests.py4
-rw-r--r--tests/requests_tests/test_accept_header.py3
-rw-r--r--tests/requests_tests/tests.py9
-rwxr-xr-xtests/runtests.py3
-rw-r--r--tests/schema/fields.py3
-rw-r--r--tests/schema/tests.py28
-rw-r--r--tests/select_for_update/tests.py4
-rw-r--r--tests/select_related_regress/tests.py21
-rw-r--r--tests/serializers/test_data.py4
-rw-r--r--tests/serializers/test_json.py3
-rw-r--r--tests/serializers/tests.py8
-rw-r--r--tests/servers/tests.py5
-rw-r--r--tests/sessions_tests/tests.py28
-rw-r--r--tests/settings_tests/tests.py6
-rw-r--r--tests/signals/tests.py9
-rw-r--r--tests/sites_tests/tests.py4
-rw-r--r--tests/staticfiles_tests/test_management.py10
-rw-r--r--tests/staticfiles_tests/test_storage.py7
-rw-r--r--tests/string_lookup/tests.py3
-rw-r--r--tests/syndication_tests/tests.py3
-rw-r--r--tests/template_tests/filter_tests/test_urlize.py3
-rw-r--r--tests/template_tests/syntax_tests/i18n/test_blocktranslate.py8
-rw-r--r--tests/template_tests/syntax_tests/test_if_changed.py5
-rw-r--r--tests/template_tests/templatetags/custom.py6
-rw-r--r--tests/test_client/tests.py8
-rw-r--r--tests/test_client_regress/tests.py54
-rw-r--r--tests/test_client_regress/views.py5
-rw-r--r--tests/test_runner/test_discover_runner.py3
-rw-r--r--tests/test_runner/tests.py8
-rw-r--r--tests/test_runner_apps/sample/tests_sample.py3
-rw-r--r--tests/timezones/tests.py13
-rw-r--r--tests/transactions/tests.py23
-rw-r--r--tests/unmanaged_models/tests.py3
-rw-r--r--tests/update/tests.py3
-rw-r--r--tests/urlpatterns_reverse/tests.py14
-rw-r--r--tests/user_commands/tests.py4
-rw-r--r--tests/utils_tests/test_csp.py8
-rw-r--r--tests/utils_tests/test_dateformat.py3
-rw-r--r--tests/utils_tests/test_decorators.py3
-rw-r--r--tests/utils_tests/test_functional.py4
-rw-r--r--tests/utils_tests/test_html.py3
-rw-r--r--tests/utils_tests/test_lorem_ipsum.py4
-rw-r--r--tests/utils_tests/test_timesince.py4
-rw-r--r--tests/view_tests/tests/test_debug.py27
-rw-r--r--tests/view_tests/tests/test_i18n.py10
-rw-r--r--tests/view_tests/tests/test_static.py5
-rw-r--r--tests/view_tests/views.py11
192 files changed, 1655 insertions, 1020 deletions
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index cd2fe7c645..68f6ca453e 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -143,7 +143,8 @@ class ChangeListTests(TestCase):
def test_select_related_preserved(self):
"""
Regression test for #10348: ChangeList.get_queryset() shouldn't
- overwrite a custom select_related provided by ModelAdmin.get_queryset().
+ overwrite a custom select_related provided by
+ ModelAdmin.get_queryset().
"""
m = ChildAdmin(Child, custom_site)
request = self.factory.get("/child/")
@@ -874,7 +875,8 @@ class ChangeListTests(TestCase):
request = self.factory.get("/", data={SEARCH_VAR: search_term})
request.user = self.superuser
with self.subTest(search_term=search_term):
- # 1 query for filtered result, 1 for filtered count, 1 for total count.
+ # 1 query for filtered result, 1 for filtered count, 1 for
+ # total count.
with self.assertNumQueries(3):
cl = model_admin.get_changelist_instance(request)
self.assertCountEqual(cl.queryset, expected_result)
@@ -1347,7 +1349,9 @@ class ChangeListTests(TestCase):
self.assertEqual(queryset.count(), 1)
def test_changelist_view_list_editable_changed_objects_uses_filter(self):
- """list_editable edits use a filtered queryset to limit memory usage."""
+ """
+ list_editable edits use a filtered queryset to limit memory usage.
+ """
a = Swallow.objects.create(origin="Swallow A", load=4, speed=1)
Swallow.objects.create(origin="Swallow B", load=2, speed=2)
data = {
@@ -1367,7 +1371,8 @@ class ChangeListTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertIn("WHERE", context.captured_queries[4]["sql"])
self.assertIn("IN", context.captured_queries[4]["sql"])
- # Check only the first few characters since the UUID may have dashes.
+ # Check only the first few characters since the UUID may have
+ # dashes.
self.assertIn(str(a.pk)[:8], context.captured_queries[4]["sql"])
def test_list_editable_error_title(self):
@@ -1420,7 +1425,8 @@ class ChangeListTests(TestCase):
check_results_order()
# When an order field is defined but multiple records have the same
- # value for that field, make sure everything gets ordered by -pk as well.
+ # value for that field, make sure everything gets ordered by -pk as
+ # well.
UnorderedObjectAdmin.ordering = ["bool"]
check_results_order()
@@ -1481,7 +1487,8 @@ class ChangeListTests(TestCase):
check_results_order(ascending=True)
# When an order field is defined but multiple records have the same
- # value for that field, make sure everything gets ordered by -pk as well.
+ # value for that field, make sure everything gets ordered by -pk as
+ # well.
OrderedObjectAdmin.ordering = ["bool"]
check_results_order()
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
index fc87260c9c..430b113ac7 100644
--- a/tests/admin_checks/tests.py
+++ b/tests/admin_checks/tests.py
@@ -680,9 +680,9 @@ class SystemChecksTestCase(SimpleTestCase):
def test_fk_exclusion(self):
"""
- Regression test for #11709 - when testing for fk excluding (when exclude is
- given) make sure fk_name is honored or things blow up when there is more
- than one fk to the parent model.
+ Regression test for #11709 - when testing for fk excluding (when
+ exclude is given) make sure fk_name is honored or things blow up when
+ there is more than one fk to the parent model.
"""
class TwoAlbumFKAndAnEInline(admin.TabularInline):
@@ -859,9 +859,9 @@ class SystemChecksTestCase(SimpleTestCase):
def test_graceful_m2m_fail(self):
"""
- Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
- specifies the 'through' option is included in the 'fields' or the 'fieldsets'
- ModelAdmin options.
+ Regression test for #12203/#12237 - Fail more gracefully when a M2M
+ field that specifies the 'through' option is included in the 'fields'
+ or the 'fieldsets' ModelAdmin options.
"""
class BookAdmin(admin.ModelAdmin):
@@ -946,7 +946,8 @@ class SystemChecksTestCase(SimpleTestCase):
def test_non_model_first_field(self):
"""
Regression for ensuring ModelAdmin.field can handle first elem being a
- non-model field (test fix for UnboundLocalError introduced with r16225).
+ non-model field (test fix for UnboundLocalError introduced with
+ r16225).
"""
class SongForm(forms.ModelForm):
diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py
index 558164f75c..530d4c53b6 100644
--- a/tests/admin_filters/tests.py
+++ b/tests/admin_filters/tests.py
@@ -910,7 +910,8 @@ class ListFiltersTests(TestCase):
request.user = self.alfred
changelist = modeladmin.get_changelist_instance(request)
- # Make sure that only actual authors are present in author's list filter
+ # Make sure that only actual authors are present in author's list
+ # filter
filterspec = changelist.get_filters(request)[0][4]
expected = [(self.alfred.pk, "alfred"), (self.bob.pk, "bob")]
self.assertEqual(sorted(filterspec.lookup_choices), sorted(expected))
@@ -1029,7 +1030,8 @@ class ListFiltersTests(TestCase):
request.user = self.alfred
changelist = modeladmin.get_changelist_instance(request)
- # Make sure that only actual contributors are present in contrib's list filter
+ # Make sure that only actual contributors are present in contrib's list
+ # filter
filterspec = changelist.get_filters(request)[0][5]
expected = [(self.bob.pk, "bob"), (self.lisa.pk, "lisa")]
self.assertEqual(sorted(filterspec.lookup_choices), sorted(expected))
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index 63e7393853..0b73089950 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -241,7 +241,10 @@ class TestInline(TestDataMixin, TestCase):
)
def test_no_parent_callable_lookup(self):
- """Admin inline `readonly_field` shouldn't invoke parent ModelAdmin callable"""
+ """
+ Admin inline `readonly_field` shouldn't invoke parent ModelAdmin
+ callable
+ """
# Identically named callable isn't present in the parent ModelAdmin,
# rendering of the add view shouldn't explode
response = self.client.get(reverse("admin:admin_inlines_novel_add"))
@@ -324,7 +327,9 @@ class TestInline(TestDataMixin, TestCase):
self.assertContains(response, "Label from ModelForm.Meta")
def test_inline_hidden_field_no_column(self):
- """#18263 -- Make sure hidden fields don't get a column in tabular inlines"""
+ """
+ #18263 -- Make sure hidden fields don't get a column in tabular inlines
+ """
parent = SomeParentModel.objects.create(name="a")
SomeChildModel.objects.create(name="b", position="0", parent=parent)
SomeChildModel.objects.create(name="c", position="1", parent=parent)
@@ -1232,7 +1237,8 @@ class TestInlinePermissions(TestCase):
)
self.user.user_permissions.add(permission)
response = self.client.get(self.holder_change_url)
- # Change permission on inner2s, so we can change existing but not add new
+ # Change permission on inner2s, so we can change existing but not add
+ # new
self.assertContains(
response,
'<h2 id="inner2_set-heading" class="inline-heading">Inner2s</h2>',
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index a272fced74..97d2d7cf7e 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -191,7 +191,10 @@ class AdminScriptTestCase(SimpleTestCase):
)
def assertNotInOutput(self, stream, msg):
- "Utility assertion: assert that the given message doesn't exist in the output"
+ """
+ Utility assertion: assert that the given message doesn't exist in the
+ output
+ """
self.assertNotIn(
msg, stream, "'%s' matches actual output text '%s'" % (msg, stream)
)
@@ -503,7 +506,10 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
self.assertOutput(err, "No module named '?bad_settings'?", regex=True)
def test_custom_command(self):
- "minimal: django-admin can't execute user commands unless settings are provided"
+ """
+ minimal: django-admin can't execute user commands unless settings are
+ provided
+ """
args = ["noargs_command"]
out, err = self.run_django_admin(args)
self.assertNoOutput(out)
@@ -745,7 +751,10 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
)
def test_setup_environ_custom_template(self):
- "directory: startapp creates the correct directory with a custom template"
+ """
+ directory: startapp creates the correct directory with a custom
+ template
+ """
template_path = os.path.join(custom_templates_dir, "app_template")
args = ["startapp", "--template", template_path, "custom_settings_test"]
app_path = os.path.join(self.test_dir, "custom_settings_test")
@@ -1089,7 +1098,10 @@ class ManageMinimalSettings(AdminScriptTestCase):
self.assertOutput(err, "No installed app with label 'admin_scripts'.")
def test_builtin_with_settings(self):
- "minimal: manage.py builtin commands fail if settings are provided as argument"
+ """
+ minimal: manage.py builtin commands fail if settings are provided as
+ argument
+ """
args = ["check", "--settings=test_project.settings", "admin_scripts"]
out, err = self.run_manage(args)
self.assertNoOutput(out)
@@ -1126,7 +1138,10 @@ class ManageMinimalSettings(AdminScriptTestCase):
self.assertOutput(err, "No module named '?bad_settings'?", regex=True)
def test_custom_command(self):
- "minimal: manage.py can't execute user commands without appropriate settings"
+ """
+ minimal: manage.py can't execute user commands without appropriate
+ settings
+ """
args = ["noargs_command"]
out, err = self.run_manage(args)
self.assertNoOutput(out)
@@ -1175,7 +1190,10 @@ class ManageAlternateSettings(AdminScriptTestCase):
)
def test_builtin_with_settings(self):
- "alternate: manage.py builtin commands work with settings provided as argument"
+ """
+ alternate: manage.py builtin commands work with settings provided as
+ argument
+ """
args = ["check", "--settings=alternate_settings", "admin_scripts"]
out, err = self.run_manage(args)
self.assertOutput(out, SYSTEM_CHECK_MSG)
@@ -1331,7 +1349,9 @@ class ManageMultipleSettings(AdminScriptTestCase):
self.assertOutput(err, "No module named '?bad_settings'?", regex=True)
def test_custom_command(self):
- "multiple: manage.py can't execute user commands using default settings"
+ """
+ multiple: manage.py can't execute user commands using default settings
+ """
args = ["noargs_command"]
out, err = self.run_manage(args)
self.assertNoOutput(out)
@@ -1709,7 +1729,8 @@ class ManageRunserver(SimpleTestCase):
def test_readonly_database(self):
"""
- runserver.check_migrations() doesn't choke when a database is read-only.
+ runserver.check_migrations() doesn't choke when a database is
+ read-only.
"""
with mock.patch.object(MigrationRecorder, "has_table", return_value=False):
self.cmd.check_migrations()
@@ -1754,7 +1775,9 @@ class ManageRunserver(SimpleTestCase):
self.addCleanup(setattr, registry, "registered_checks", original_checks)
class CustomRunserverCommand(RunserverCommand):
- """Rather than mock run(), raise immediately after system checks run."""
+ """
+ Rather than mock run(), raise immediately after system checks run.
+ """
def check_migrations(self, *args, **kwargs):
raise CustomException
@@ -1921,7 +1944,8 @@ class CommandTypes(AdminScriptTestCase):
def test_version_alternative(self):
"--version is equivalent to version"
args1, args2 = ["version"], ["--version"]
- # It's possible one outputs on stderr and the other on stdout, hence the set
+ # It's possible one outputs on stderr and the other on stdout, hence
+ # the set
self.assertEqual(set(self.run_manage(args1)), set(self.run_manage(args2)))
def test_help(self):
@@ -2136,13 +2160,18 @@ class CommandTypes(AdminScriptTestCase):
self._test_base_command(args, expected_labels, option_a="'x'")
def test_base_command_with_options(self):
- "User BaseCommands can execute with multiple options when a label is provided"
+ """
+ User BaseCommands can execute with multiple options when a label is
+ provided
+ """
args = ["base_command", "testlabel", "-a", "x", "--option_b=y"]
expected_labels = "('testlabel',)"
self._test_base_command(args, expected_labels, option_a="'x'", option_b="'y'")
def test_base_command_with_wrong_option(self):
- "User BaseCommands outputs command usage when wrong option is specified"
+ """
+ User BaseCommands outputs command usage when wrong option is specified
+ """
args = ["base_command", "--invalid"]
out, err = self.run_manage(args)
self.assertNoOutput(out)
@@ -2164,8 +2193,8 @@ class CommandTypes(AdminScriptTestCase):
def test_base_run_from_argv(self):
"""
- Test run_from_argv properly terminates even with custom execute() (#19665)
- Also test proper traceback display.
+ Test run_from_argv properly terminates even with custom execute()
+ (#19665) Also test proper traceback display.
"""
err = StringIO()
command = BaseCommand(stderr=err)
@@ -2292,7 +2321,10 @@ class CommandTypes(AdminScriptTestCase):
self.assertOutput(err, "No installed app with label 'NOT_AN_APP'.")
def test_app_command_some_invalid_app_labels(self):
- "User AppCommands can execute when some of the provided app names are invalid"
+ """
+ User AppCommands can execute when some of the provided app names are
+ invalid
+ """
args = ["app_command", "auth", "NOT_AN_APP"]
out, err = self.run_manage(args)
self.assertOutput(err, "No installed app with label 'NOT_AN_APP'.")
@@ -2316,7 +2348,10 @@ class CommandTypes(AdminScriptTestCase):
self.assertOutput(err, "Enter at least one label")
def test_label_command_multiple_label(self):
- "User LabelCommands are executed multiple times if multiple labels are provided"
+ """
+ User LabelCommands are executed multiple times if multiple labels are
+ provided
+ """
args = ["label_command", "testlabel", "anotherlabel"]
out, err = self.run_manage(args)
self.assertNoOutput(err)
@@ -2558,7 +2593,9 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
)
def test_invalid_project_name(self):
- "Make sure the startproject management command validates a project name"
+ """
+ Make sure the startproject management command validates a project name
+ """
for bad_name in ("7testproject", "../testproject"):
with self.subTest(project_name=bad_name):
args = ["startproject", bad_name]
@@ -2773,7 +2810,10 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.assertTrue(os.path.exists(os.path.join(testproject_dir, "run.py")))
def test_file_without_extension(self):
- "Make sure the startproject management command is able to render custom files"
+ """
+ Make sure the startproject management command is able to render custom
+ files
+ """
template_path = os.path.join(custom_templates_dir, "project_template")
args = [
"startproject",
@@ -2845,7 +2885,8 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
def test_custom_project_destination_missing(self):
"""
- Create the directory when the provided destination directory doesn't exist.
+ Create the directory when the provided destination directory doesn't
+ exist.
"""
template_path = os.path.join(custom_templates_dir, "project_template")
args = [
diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py
index a800de0fad..37d13d24bd 100644
--- a/tests/admin_utils/test_logentry.py
+++ b/tests/admin_utils/test_logentry.py
@@ -114,7 +114,8 @@ class LogEntryTests(TestCase):
def test_logentry_change_message_localized_datetime_input(self):
"""
- Localized date/time inputs shouldn't affect changed form data detection.
+ Localized date/time inputs shouldn't affect changed form data
+ detection.
"""
post_data = {
"site": self.site.pk,
diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py
index 6d165637e7..c90836c6d8 100644
--- a/tests/admin_utils/tests.py
+++ b/tests/admin_utils/tests.py
@@ -329,7 +329,8 @@ class UtilsTests(SimpleTestCase):
self.assertEqual(label_for_field(lambda x: "nothing", Article), "--")
self.assertEqual(label_for_field("site_id", Article), "Site id")
- # The correct name and attr are returned when `__` is in the field name.
+ # The correct name and attr are returned when `__` is in the field
+ # name.
self.assertEqual(label_for_field("site__domain", Article), "Site domain")
self.assertEqual(
label_for_field("site__domain", Article, return_attr=True),
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index 5e14069bae..95d16a4770 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -1264,8 +1264,8 @@ site.register(RelatedPrepopulated, search_fields=["name"])
site.register(RelatedWithUUIDPKModel)
site.register(ReadOnlyRelatedField, ReadOnlyRelatedFieldAdmin)
-# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
-# That way we cover all four cases:
+# We intentionally register Promo and ChapterXtra1 but not Chapter nor
+# ChapterXtra2. That way we cover all four cases:
# related ForeignKey object registered in admin
# related ForeignKey object not registered in admin
# related OneToOne object registered in admin
diff --git a/tests/admin_views/test_adminsite.py b/tests/admin_views/test_adminsite.py
index 7c4841f916..9a0f632db9 100644
--- a/tests/admin_views/test_adminsite.py
+++ b/tests/admin_views/test_adminsite.py
@@ -30,8 +30,8 @@ urlpatterns = [
@override_settings(ROOT_URLCONF="admin_views.test_adminsite")
class SiteEachContextTest(TestCase):
"""
- Check each_context contains the documented variables and that available_apps context
- variable structure is the expected one.
+ Check each_context contains the documented variables and that
+ available_apps context variable structure is the expected one.
"""
request_factory = RequestFactory()
diff --git a/tests/admin_views/test_skip_link_to_content.py b/tests/admin_views/test_skip_link_to_content.py
index 80cf6e5357..3284b76495 100644
--- a/tests/admin_views/test_skip_link_to_content.py
+++ b/tests/admin_views/test_skip_link_to_content.py
@@ -36,12 +36,14 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertTrue(skip_link.is_displayed())
# Press RETURN to skip the navbar links (view site / documentation /
- # change password / log out) and focus first model in the admin_views list.
+ # change password / log out) and focus first model in the admin_views
+ # list.
skip_link.send_keys(Keys.RETURN)
self.assertFalse(skip_link.is_displayed()) # `skip link` disappear.
keys = [Keys.TAB, Keys.TAB] # The 1st TAB is the section title.
if self.browser == "firefox":
- # For some reason Firefox doesn't focus the section title ('ADMIN_VIEWS').
+ # For some reason Firefox doesn't focus the section title
+ # ('ADMIN_VIEWS').
keys.remove(Keys.TAB)
body.send_keys(keys)
actors_a_tag = self.selenium.find_element(By.LINK_TEXT, "Actors")
@@ -61,7 +63,8 @@ class SeleniumTests(AdminSeleniumTestCase):
)
self.assertEqual(self.selenium.switch_to.active_element, actors_a_tag)
- # Go to the Actor form and the first input will be focused automatically.
+ # Go to the Actor form and the first input will be focused
+ # automatically.
with self.wait_page_loaded():
actors_a_tag.send_keys(Keys.RETURN)
first_input = self.selenium.find_element(By.ID, "id_name")
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index ba322bd344..8460aa81fc 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -250,7 +250,8 @@ class AdminViewBasicTestCase(TestCase):
"article_set-INITIAL_FORMS": "3",
"article_set-MAX_NUM_FORMS": "0",
"article_set-0-id": cls.a1.pk,
- # there is no title in database, give one here or formset will fail.
+ # there is no title in database, give one here or formset will
+ # fail.
"article_set-0-title": "Norske bostaver æøå skaper problemer",
"article_set-0-content": "&lt;p&gt;Middle content&lt;/p&gt;",
"article_set-0-date_0": "2008-03-18",
@@ -992,7 +993,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(changelist_url, {"notarealfield": "5"})
self.assertRedirects(response, "%s?e=1" % changelist_url)
- # Spanning relationships through a nonexistent related object (Refs #16716)
+ # Spanning relationships through a nonexistent related object (Refs
+ # #16716)
response = self.client.get(changelist_url, {"notarealfield__whatever": "5"})
self.assertRedirects(response, "%s?e=1" % changelist_url)
@@ -1037,9 +1039,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
def test_named_group_field_choices_change_list(self):
"""
- Ensures the admin changelist shows correct values in the relevant column
- for rows corresponding to instances of a model in which a named group
- has been used in the choices option of a field.
+ Ensures the admin changelist shows correct values in the relevant
+ column for rows corresponding to instances of a model in which a named
+ group has been used in the choices option of a field.
"""
link1 = reverse("admin:admin_views_fabric_change", args=(self.fab1.pk,))
link2 = reverse("admin:admin_views_fabric_change", args=(self.fab2.pk,))
@@ -1262,8 +1264,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
def test_allowed_filtering_15103(self):
"""
Regressions test for ticket 15103 - filtering on fields defined in a
- ForeignKey 'limit_choices_to' should be allowed, otherwise raw_id_fields
- can break.
+ ForeignKey 'limit_choices_to' should be allowed, otherwise
+ raw_id_fields can break.
"""
# Filters should be allowed if they are defined on a ForeignKey
# pointing to this model.
@@ -1353,7 +1355,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(
reverse("admin:admin_views_unchangeableobject_changelist")
)
- # Check the format of the shown object -- shouldn't contain a change link
+ # Check the format of the shown object -- shouldn't contain a change
+ # link
self.assertContains(
response, '<th class="field-__str__">%s</th>' % o, html=True
)
@@ -1963,7 +1966,8 @@ class AdminJavaScriptTest(TestCase):
def test_js_minified_only_if_debug_is_false(self):
"""
- The minified versions of the JS files are only used when DEBUG is False.
+ The minified versions of the JS files are only used when DEBUG is
+ False.
"""
with override_settings(DEBUG=False):
response = self.client.get(reverse("admin:admin_views_section_add"))
@@ -2346,7 +2350,8 @@ class AdminViewPermissionsTest(TestCase):
self.assertContains(login, ERROR_MESSAGE)
new_user = User(username="jondoe", password="secret", email="super@example.com")
new_user.save()
- # check to ensure if there are multiple email addresses a user doesn't get a 500
+ # check to ensure if there are multiple email addresses a user doesn't
+ # get a 500
login = self.client.post(login_url, self.super_email_login)
self.assertContains(login, ERROR_MESSAGE)
@@ -2662,7 +2667,8 @@ class AdminViewPermissionsTest(TestCase):
)
article_changelist_url = reverse("admin:admin_views_article_changelist")
- # add user should not be able to view the list of article or change any of them
+ # add user should not be able to view the list of article or change any
+ # of them
self.client.force_login(self.adduser)
response = self.client.get(article_changelist_url)
self.assertEqual(response.status_code, 403)
@@ -2744,7 +2750,8 @@ class AdminViewPermissionsTest(TestCase):
)
self.client.post(reverse("admin:logout"))
- # Test redirection when using row-level change permissions. Refs #11513.
+ # Test redirection when using row-level change permissions. Refs
+ # #11513.
r1 = RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
r2 = RowLevelChangePermissionModel.objects.create(id=2, name="even id")
r3 = RowLevelChangePermissionModel.objects.create(id=3, name="odd id mult 3")
@@ -3093,7 +3100,8 @@ class AdminViewPermissionsTest(TestCase):
def test_history_view(self):
"""History view should restrict access."""
- # add user should not be able to view the list of article or change any of them
+ # add user should not be able to view the list of article or change any
+ # of them
self.client.force_login(self.adduser)
response = self.client.get(
reverse("admin:admin_views_article_history", args=(self.a1.pk,))
@@ -3116,7 +3124,8 @@ class AdminViewPermissionsTest(TestCase):
)
self.assertEqual(response.status_code, 200)
- # Test redirection when using row-level change permissions. Refs #11513.
+ # Test redirection when using row-level change permissions. Refs
+ # #11513.
rl1 = RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
rl2 = RowLevelChangePermissionModel.objects.create(id=2, name="even id")
logins = [
@@ -3180,12 +3189,14 @@ class AdminViewPermissionsTest(TestCase):
user has permission to add that related item.
"""
self.client.force_login(self.adduser)
- # The user can't add sections yet, so they shouldn't see the "add section" link.
+ # The user can't add sections yet, so they shouldn't see the "add
+ # section" link.
url = reverse("admin:admin_views_article_add")
add_link_text = "add_id_section"
response = self.client.get(url)
self.assertNotContains(response, add_link_text)
- # Allow the user to add sections too. Now they can see the "add section" link.
+ # Allow the user to add sections too. Now they can see the "add
+ # section" link.
user = User.objects.get(username="adduser")
perm = get_perm(Section, get_permission_codename("add", Section._meta))
user.user_permissions.add(perm)
@@ -3313,7 +3324,8 @@ class AdminViewPermissionsTest(TestCase):
# Logged in? Redirect.
self.client.force_login(self.superuser)
response = self.client.get(shortcut_url, follow=False)
- # Can't use self.assertRedirects() because User.get_absolute_url() is silly.
+ # Can't use self.assertRedirects() because User.get_absolute_url() is
+ # silly.
self.assertEqual(response.status_code, 302)
# Domain may depend on contrib.sites tests also run
self.assertRegex(response.url, "http://(testserver|example.com)/dummy/foo/")
@@ -3538,7 +3550,10 @@ class AdminViewsNoUrlTest(TestCase):
)
def test_no_standard_modeladmin_urls(self):
- """Admin index views don't break when user's ModelAdmin removes standard urls"""
+ """
+ Admin index views don't break when user's ModelAdmin removes standard
+ urls
+ """
self.client.force_login(self.changeuser)
r = self.client.get(reverse("admin:index"))
# we shouldn't get a 500 error caused by a NoReverseMatch
@@ -3920,7 +3935,9 @@ class AdminViewStringPrimaryKeyTest(TestCase):
self.assertContains(response, "Changed something")
def test_get_change_view(self):
- "Retrieving the object using urlencoded form of primary key should work"
+ """
+ Retrieving the object using urlencoded form of primary key should work
+ """
response = self.client.get(
reverse(
"admin:admin_views_modelwithstringprimarykey_change", args=(self.pk,)
@@ -3936,7 +3953,8 @@ class AdminViewStringPrimaryKeyTest(TestCase):
response = self.client.get(
reverse("admin:admin_views_modelwithstringprimarykey_changelist")
)
- # this URL now comes through reverse(), thus url quoting and iri_to_uri encoding
+ # this URL now comes through reverse(), thus url quoting and iri_to_uri
+ # encoding
pk_final_url = escape(iri_to_uri(quote(self.pk)))
change_url = reverse(
"admin:admin_views_modelwithstringprimarykey_change", args=("__fk__",)
@@ -3976,7 +3994,8 @@ class AdminViewStringPrimaryKeyTest(TestCase):
"admin:admin_views_modelwithstringprimarykey_delete", args=(quote(self.pk),)
)
response = self.client.get(url)
- # this URL now comes through reverse(), thus url quoting and iri_to_uri encoding
+ # this URL now comes through reverse(), thus url quoting and iri_to_uri
+ # encoding
change_url = reverse(
"admin:admin_views_modelwithstringprimarykey_change", args=("__fk__",)
).replace("__fk__", escape(iri_to_uri(quote(self.pk))))
@@ -3984,7 +4003,10 @@ class AdminViewStringPrimaryKeyTest(TestCase):
self.assertContains(response, should_contain)
def test_url_conflicts_with_add(self):
- "A model with a primary key that ends with add or is `add` should be visible"
+ """
+ A model with a primary key that ends with add or is `add` should be
+ visible
+ """
add_model = ModelWithStringPrimaryKey.objects.create(
pk="i have something to add"
)
@@ -4046,7 +4068,9 @@ class AdminViewStringPrimaryKeyTest(TestCase):
self.assertContains(response, should_contain)
def test_change_view_history_link(self):
- """Object history button link should work and contain the pk value quoted."""
+ """
+ Object history button link should work and contain the pk value quoted.
+ """
url = reverse(
"admin:%s_modelwithstringprimarykey_change"
% ModelWithStringPrimaryKey._meta.app_label,
@@ -4521,8 +4545,8 @@ class AdminViewListEditable(TestCase):
self.assertContains(response, "Unordered object #1")
def test_list_editable_action_submit(self):
- # List editable changes should not be executed if the action "Go" button is
- # used to submit the form.
+ # List editable changes should not be executed if the action "Go"
+ # button is used to submit the form.
data = {
"form-TOTAL_FORMS": "3",
"form-INITIAL_FORMS": "3",
@@ -4606,9 +4630,8 @@ class AdminViewListEditable(TestCase):
self.assertContains(response, '<td class="field-id">%d</td>' % story2.id, 1)
def test_pk_hidden_fields_with_list_display_links(self):
- """Similarly as test_pk_hidden_fields, but when the hidden pk fields are
- referenced in list_display_links.
- Refs #12475.
+ """Similarly as test_pk_hidden_fields, but when the hidden pk fields
+ are referenced in list_display_links. Refs #12475.
"""
story1 = OtherStory.objects.create(
title="The adventures of Guido",
@@ -5478,7 +5501,10 @@ class AdminInlineTests(TestCase):
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated")
def test_char_pk_inline(self):
- "A model with a character PK can be saved as inlines. Regression for #10992"
+ """
+ A model with a character PK can be saved as inlines. Regression for
+ #10992
+ """
# First add a new inline
self.post_data["doohickey_set-0-code"] = "DH1"
self.post_data["doohickey_set-0-name"] = "Doohickey 1"
@@ -5513,7 +5539,10 @@ class AdminInlineTests(TestCase):
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated")
def test_integer_pk_inline(self):
- "A model with an integer PK can be saved as inlines. Regression for #10992"
+ """
+ A model with an integer PK can be saved as inlines. Regression for
+ #10992
+ """
# First add a new inline
self.post_data["whatsit_set-0-index"] = "42"
self.post_data["whatsit_set-0-name"] = "Whatsit 1"
@@ -6106,7 +6135,8 @@ class SeleniumTests(AdminSeleniumTestCase):
self.selenium.get(object_url)
self.selenium.find_element(By.ID, "id_name").send_keys(" hello")
- # The slugs got prepopulated didn't change since they were originally not empty
+ # The slugs got prepopulated didn't change since they were originally
+ # not empty
slug1 = self.selenium.find_element(By.ID, "id_slug1").get_attribute("value")
slug2 = self.selenium.find_element(By.ID, "id_slug2").get_attribute("value")
self.assertEqual(slug1, "this-is-the-main-name-the-best-2012-02-18")
@@ -7168,7 +7198,8 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
def test_correct_autoescaping(self):
"""
- Make sure that non-field readonly elements are properly autoescaped (#24461)
+ Make sure that non-field readonly elements are properly autoescaped
+ (#24461)
"""
section = Section.objects.create(name="<a>evil</a>")
response = self.client.get(
@@ -7207,7 +7238,8 @@ class LimitChoicesToInAdminTest(TestCase):
last_action=datetime.datetime.today() - datetime.timedelta(days=1),
)
response = self.client.get(reverse("admin:admin_views_stumpjoke_add"))
- # The allowed option should appear twice; the limited option should not appear.
+ # The allowed option should appear twice; the limited option should not
+ # appear.
self.assertContains(response, threepwood.username, count=2)
self.assertNotContains(response, marley.username)
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 83f5481832..c47e0e3ec1 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -300,7 +300,8 @@ class AdminFormfieldForDBFieldTests(SimpleTestCase):
class AdminFormfieldForDBFieldWithRequestTests(TestDataMixin, TestCase):
def test_filter_choices_by_request_user(self):
"""
- Ensure the user can only see their own cars in the foreign key dropdown.
+ Ensure the user can only see their own cars in the foreign key
+ dropdown.
"""
self.client.force_login(self.superuser)
response = self.client.get(reverse("admin:admin_widgets_cartire_add"))
@@ -1052,8 +1053,8 @@ class DateTimePickerSeleniumTests(AdminWidgetSeleniumTestCase):
def test_calendar_nonday_class(self):
"""
- Ensure cells that are not days of the month have the `nonday` CSS class.
- Refs #4574.
+ Ensure cells that are not days of the month have the `nonday` CSS
+ class. Refs #4574.
"""
from selenium.webdriver.common.by import By
@@ -1184,9 +1185,9 @@ class DateTimePickerShortcutsSeleniumTests(AdminWidgetSeleniumTestCase):
date/time/datetime picker shortcuts work in the current time zone.
Refs #20663.
- This test case is fairly tricky, it relies on selenium still running the browser
- in the default time zone "America/Chicago" despite `override_settings` changing
- the time zone to "Asia/Singapore".
+ This test case is fairly tricky, it relies on selenium still running
+ the browser in the default time zone "America/Chicago" despite
+ `override_settings` changing the time zone to "Asia/Singapore".
"""
from selenium.webdriver.common.by import By
@@ -1502,7 +1503,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
self.select_option(from_box, str(self.peter.id))
self.select_option(from_box, str(self.lisa.id))
- # Confirm they're selected after clicking inactive buttons: ticket #26575
+ # Confirm they're selected after clicking inactive buttons: ticket
+ # #26575
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
self.selenium.find_element(By.ID, remove_button).click()
self.assertSelectedOptions(from_box, [str(self.peter.id), str(self.lisa.id)])
@@ -1515,7 +1517,8 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase):
self.select_option(to_box, str(self.jason.id))
self.select_option(to_box, str(self.john.id))
- # Confirm they're selected after clicking inactive buttons: ticket #26575
+ # Confirm they're selected after clicking inactive buttons: ticket
+ # #26575
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
self.selenium.find_element(By.ID, choose_button).click()
self.assertSelectedOptions(to_box, [str(self.jason.id), str(self.john.id)])
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 1cf3a8f66e..bd33a532b3 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1321,9 +1321,10 @@ class AggregateTestCase(TestCase):
def as_sql(self, compiler, connection, **extra_context):
copy = self.copy()
- # Most database backends do not support compiling multiple arguments on
- # the Max aggregate, and that isn't what is being tested here anyway. To
- # avoid errors, the extra argument is just dropped.
+ # Most database backends do not support compiling multiple
+ # arguments on the Max aggregate, and that isn't what is being
+ # tested here anyway. To avoid errors, the extra argument is
+ # just dropped.
copy.set_source_expressions(
copy.get_source_expressions()[0:1] + [None, None]
)
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index 9199bf3eba..3e1a6a71f9 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -314,7 +314,8 @@ class AggregationTests(TestCase):
publisher_id=self.p2.id,
rating=3.0,
)
- # Different DB backends return different types for the extra select computation
+ # Different DB backends return different types for the extra select
+ # computation
self.assertIn(obj.manufacture_cost, (11.545, Decimal("11.545")))
# Order of the annotate/extra in the query doesn't matter
@@ -335,7 +336,8 @@ class AggregationTests(TestCase):
publisher_id=self.p2.id,
rating=3.0,
)
- # Different DB backends return different types for the extra select computation
+ # Different DB backends return different types for the extra select
+ # computation
self.assertIn(obj.manufacture_cost, (11.545, Decimal("11.545")))
# Values queries can be combined with annotate and extra
@@ -498,8 +500,8 @@ class AggregationTests(TestCase):
},
)
- # Regression for #15624 - Missing SELECT columns when using values, annotate
- # and aggregate in a single query
+ # Regression for #15624 - Missing SELECT columns when using values,
+ # annotate and aggregate in a single query
self.assertEqual(
Book.objects.annotate(c=Count("authors")).values("c").aggregate(Max("c")),
{"c__max": 3},
@@ -935,11 +937,13 @@ class AggregationTests(TestCase):
.order_by()
.query
)
- # There is just one GROUP BY clause (zero commas means at most one clause).
+ # There is just one GROUP BY clause (zero commas means at most one
+ # clause).
self.assertEqual(qstr[qstr.index("GROUP BY") :].count(", "), 0)
def test_duplicate_alias(self):
- # Regression for #11256 - duplicating a default alias raises ValueError.
+ # Regression for #11256 - duplicating a default alias raises
+ # ValueError.
msg = (
"The named annotation 'authors__age__avg' conflicts with "
"the default name for another annotation."
@@ -1004,7 +1008,8 @@ class AggregationTests(TestCase):
def test_reverse_relation_name_conflict(self):
# Regression for #11256 - providing an aggregate name
- # that conflicts with a reverse-related name on the model raises ValueError
+ # that conflicts with a reverse-related name on the model raises
+ # ValueError
msg = "The annotation 'book_contact_set' conflicts with a field on the model."
with self.assertRaisesMessage(ValueError, msg):
Author.objects.annotate(book_contact_set=Avg("friends__age"))
@@ -1417,8 +1422,8 @@ class AggregationTests(TestCase):
def test_annotate_joins(self):
"""
The base table's join isn't promoted to LOUTER. This could
- cause the query generation to fail if there is an exclude() for fk-field
- in the query, too. Refs #19087.
+ cause the query generation to fail if there is an exclude() for
+ fk-field in the query, too. Refs #19087.
"""
qs = Book.objects.annotate(n=Count("pk"))
self.assertIs(qs.query.alias_map["aggregation_regress_book"].join_type, None)
@@ -1934,8 +1939,8 @@ class JoinPromotionTests(TestCase):
Count("alfa__name")
)
self.assertIn(" INNER JOIN ", str(qs.query))
- # Also, the existing join is unpromoted when doing filtering for already
- # promoted join.
+ # Also, the existing join is unpromoted when doing filtering for
+ # already promoted join.
qs = Charlie.objects.annotate(Count("alfa__name")).filter(
alfa__name__isnull=False
)
diff --git a/tests/apps/tests.py b/tests/apps/tests.py
index fba9c43a34..0f395b7fc3 100644
--- a/tests/apps/tests.py
+++ b/tests/apps/tests.py
@@ -388,7 +388,8 @@ class AppsTests(SimpleTestCase):
class LazyC(models.Model):
pass
- # Everything should be loaded - make sure the callback was executed properly.
+ # Everything should be loaded - make sure the callback was executed
+ # properly.
self.assertEqual(model_classes, [LazyA, LazyB, LazyB, LazyC, LazyA])
@@ -421,7 +422,9 @@ class AppConfigTests(SimpleTestCase):
self.assertEqual(ac.path, "foo")
def test_dunder_path(self):
- """If single element in __path__, use it (in preference to __file__)."""
+ """
+ If single element in __path__, use it (in preference to __file__).
+ """
ac = AppConfig("label", Stub(__path__=["a"], __file__="b/__init__.py"))
self.assertEqual(ac.path, "a")
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index 32fb092cf4..0ba169249b 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -457,7 +457,9 @@ class BaseModelBackendTest:
PASSWORD_HASHERS=["auth_tests.test_auth_backends.CountingMD5PasswordHasher"]
)
def test_authentication_timing(self):
- """Hasher is run once regardless of whether the user exists. Refs #20760."""
+ """
+ Hasher is run once regardless of whether the user exists. Refs #20760.
+ """
# Re-set the password, because this tests overrides PASSWORD_HASHERS
self.user.set_password("test")
self.user.save()
@@ -875,7 +877,8 @@ class InActiveUserBackendTest(TestCase):
class PermissionDeniedBackend:
"""
- Always raises PermissionDenied in `authenticate`, `has_perm` and `has_module_perms`.
+ Always raises PermissionDenied in `authenticate`, `has_perm` and
+ `has_module_perms`.
"""
def authenticate(self, request, username=None, password=None):
@@ -920,7 +923,10 @@ class PermissionDeniedBackendTest(TestCase):
@modify_settings(AUTHENTICATION_BACKENDS={"prepend": backend})
def test_permission_denied(self):
- "user is not authenticated after a backend raises permission denied #2550"
+ """
+ user is not authenticated after a backend raises permission denied
+ #2550
+ """
self.assertIsNone(authenticate(username="test", password="test"))
# user_login_failed signal is sent.
self.assertEqual(
diff --git a/tests/auth_tests/test_basic.py b/tests/auth_tests/test_basic.py
index 8d54e187fc..85155dad90 100644
--- a/tests/auth_tests/test_basic.py
+++ b/tests/auth_tests/test_basic.py
@@ -112,7 +112,10 @@ class BasicTestCase(TestCase):
@override_settings(AUTH_USER_MODEL="badsetting")
def test_swappable_user_bad_setting(self):
- "The alternate user setting must point to something in the format app.model"
+ """
+ The alternate user setting must point to something in the format
+ app.model
+ """
msg = "AUTH_USER_MODEL must be of the form 'app_label.model_name'"
with self.assertRaisesMessage(ImproperlyConfigured, msg):
get_user_model()
diff --git a/tests/auth_tests/test_context_processors.py b/tests/auth_tests/test_context_processors.py
index 7e6c6a556e..cebc1108dc 100644
--- a/tests/auth_tests/test_context_processors.py
+++ b/tests/auth_tests/test_context_processors.py
@@ -145,7 +145,8 @@ class AuthContextProcessorTests(TestCase):
# bug #12037 is tested by the {% url %} in the template:
self.assertContains(response, "url: /userpage/super/")
- # A Q() comparing a user and with another Q() (in an AND or OR fashion).
+ # A Q() comparing a user and with another Q() (in an AND or OR
+ # fashion).
Q(user=response.context["user"]) & Q(someflag=True)
# Tests for user equality. This is hard because User defines
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
index ebfaa8b051..735ac1d237 100644
--- a/tests/auth_tests/test_forms.py
+++ b/tests/auth_tests/test_forms.py
@@ -576,7 +576,8 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
]
)
def test_custom_login_allowed_policy(self):
- # The user is inactive, but our custom form policy allows them to log in.
+ # The user is inactive, but our custom form policy allows them to log
+ # in.
data = {
"username": "inactive",
"password": "password",
@@ -1322,9 +1323,9 @@ class PasswordResetFormTest(TestDataMixin, TestCase):
def test_save_plaintext_email(self):
"""
- Test the PasswordResetForm.save() method with no html_email_template_name
- parameter passed in.
- Test to ensure original behavior is unchanged after the parameter was added.
+ Test the PasswordResetForm.save() method with no
+ html_email_template_name parameter passed in. Test to ensure original
+ behavior is unchanged after the parameter was added.
"""
(user, username, email) = self.create_dummy_user()
form = PasswordResetForm({"email": email})
diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py
index ba7131406b..910238d2f5 100644
--- a/tests/auth_tests/test_hashers.py
+++ b/tests/auth_tests/test_hashers.py
@@ -379,7 +379,8 @@ class TestUtilsHashPass(SimpleTestCase):
# Revert to the old iteration count and ...
hasher.iterations = old_iterations
- # ... check if the password would get updated to the new iteration count.
+ # ... check if the password would get updated to the new iteration
+ # count.
self.assertTrue(check_password("letmein", encoded, setter))
self.assertTrue(state["upgraded"])
finally:
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 9f12e631cc..0701ac2d68 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -200,7 +200,10 @@ class ChangepasswordManagementCommandTestCase(TestCase):
@mock.patch.object(changepassword.Command, "_get_pass", return_value="not qwerty")
def test_that_changepassword_command_changes_joes_password(self, mock_get_pass):
- "Executing the changepassword management command should change joe's password"
+ """
+ Executing the changepassword management command should change joe's
+ password
+ """
self.assertTrue(self.user.check_password("qwerty"))
call_command("changepassword", username="joe", stdout=self.stdout)
@@ -413,7 +416,10 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
@override_settings(AUTH_USER_MODEL="auth_tests.CustomUser")
def test_swappable_user_missing_required_field(self):
- "A Custom superuser won't be created when a required field isn't provided"
+ """
+ A Custom superuser won't be created when a required field isn't
+ provided
+ """
# We can use the management command to create a superuser
# We skip validation because the temporary substitution of the
# swappable User model messes with validation.
diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py
index 4b5902b586..c871ea7dc8 100644
--- a/tests/auth_tests/test_remote_user.py
+++ b/tests/auth_tests/test_remote_user.py
@@ -243,7 +243,8 @@ class RemoteUserTest(TestCase):
# Known user authenticates
response = self.client.get("/remote_user/", **{self.header: self.known_user})
self.assertEqual(response.context["user"].username, "knownuser")
- # During the session, the REMOTE_USER header disappears. Should trigger logout.
+ # During the session, the REMOTE_USER header disappears. Should trigger
+ # logout.
response = self.client.get("/remote_user/")
self.assertTrue(response.context["user"].is_anonymous)
# verify the remoteuser middleware will not remove a user
@@ -262,7 +263,8 @@ class RemoteUserTest(TestCase):
"/remote_user/", **{self.header: self.known_user}
)
self.assertEqual(response.context["user"].username, "knownuser")
- # During the session, the REMOTE_USER header disappears. Should trigger logout.
+ # During the session, the REMOTE_USER header disappears. Should trigger
+ # logout.
response = await self.async_client.get("/remote_user/")
self.assertTrue(response.context["user"].is_anonymous)
# verify the remoteuser middleware will not remove a user
diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py
index fdbf495ff5..2a3a93efe8 100644
--- a/tests/auth_tests/test_validators.py
+++ b/tests/auth_tests/test_validators.py
@@ -114,7 +114,8 @@ class PasswordValidationTest(SimpleTestCase):
help_text = password_validators_help_text_html([AmpersandValidator()])
self.assertEqual(help_text, "<ul><li>Must contain &amp;</li></ul>")
- # help_text is marked safe and therefore unchanged by conditional_escape().
+ # help_text is marked safe and therefore unchanged by
+ # conditional_escape().
self.assertEqual(help_text, conditional_escape(help_text))
@override_settings(AUTH_PASSWORD_VALIDATORS=[])
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index e6419de8e6..0a4f7d28c8 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -153,8 +153,8 @@ class PasswordResetTest(AuthViewsTestCase):
self.assertEqual(len(mail.outbox), 1)
self.assertIn("http://", mail.outbox[0].body)
self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
- # optional multipart text/html email has been added. Make sure original,
- # default functionality is 100% the same
+ # optional multipart text/html email has been added. Make sure
+ # original, default functionality is 100% the same
self.assertFalse(mail.outbox[0].message().is_multipart())
def test_extra_email_context(self):
@@ -209,8 +209,8 @@ class PasswordResetTest(AuthViewsTestCase):
# the colon is interpreted as part of a username for login purposes,
# making 'evil.com' the request domain. Since HTTP_HOST is used to
# produce a meaningful reset URL, we need to be certain that the
- # HTTP_HOST header isn't poisoned. This is done as a check when get_host()
- # is invoked, but we check here as a practical consequence.
+ # HTTP_HOST header isn't poisoned. This is done as a check when
+ # get_host() is invoked, but we check here as a practical consequence.
with self.assertLogs("django.security.DisallowedHost", "ERROR"):
response = self.client.post(
"/password_reset/",
@@ -223,7 +223,10 @@ class PasswordResetTest(AuthViewsTestCase):
# Skip any 500 handler action (like sending more mail...)
@override_settings(DEBUG_PROPAGATE_EXCEPTIONS=True)
def test_poisoned_http_host_admin_site(self):
- "Poisoned HTTP_HOST headers can't be used for reset emails on admin views"
+ """
+ Poisoned HTTP_HOST headers can't be used for reset emails on admin
+ views
+ """
with self.assertLogs("django.security.DisallowedHost", "ERROR"):
response = self.client.post(
"/admin_password_reset/",
@@ -733,7 +736,8 @@ class SessionAuthenticationTests(AuthViewsTestCase):
def test_user_password_change_updates_session(self):
"""
#21649 - Ensure contrib.auth.views.password_change updates the user's
- session auth hash after a password change so the session isn't logged out.
+ session auth hash after a password change so the session isn't logged
+ out.
"""
self.login()
original_session_key = self.client.session.session_key
@@ -901,8 +905,8 @@ class LoginTest(AuthViewsTestCase):
def test_session_key_flushed_on_login(self):
"""
To avoid reusing another user's session, ensure a new, empty session is
- created if the existing session corresponds to a different authenticated
- user.
+ created if the existing session corresponds to a different
+ authenticated user.
"""
self.login()
original_session_key = self.client.session.session_key
diff --git a/tests/backends/base/test_schema.py b/tests/backends/base/test_schema.py
index 5409789b13..06a9a0e28a 100644
--- a/tests/backends/base/test_schema.py
+++ b/tests/backends/base/test_schema.py
@@ -5,7 +5,9 @@ from django.test import SimpleTestCase
class SchemaEditorTests(SimpleTestCase):
def test_effective_default_callable(self):
- """SchemaEditor.effective_default() shouldn't call callable defaults."""
+ """
+ SchemaEditor.effective_default() shouldn't call callable defaults.
+ """
class MyStr(str):
def __call__(self):
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py
index 37c5ee562b..c5fa17041c 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -373,7 +373,8 @@ class Tests(TestCase):
try:
# Start a transaction so the isolation level isn't reported as 0.
new_connection.set_autocommit(False)
- # Check the level on the psycopg connection, not the Django wrapper.
+ # Check the level on the psycopg connection, not the Django
+ # wrapper.
self.assertEqual(
new_connection.connection.isolation_level,
IsolationLevel.SERIALIZABLE,
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 172d6b630b..3e708401c5 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -57,8 +57,8 @@ class DateQuotingTest(TestCase):
def test_django_date_extract(self):
"""
- Test the custom ``django_date_extract method``, in particular against fields
- which clash with strings passed to it (e.g. 'day') (#12818).
+ Test the custom ``django_date_extract method``, in particular against
+ fields which clash with strings passed to it (e.g. 'day') (#12818).
"""
updated = datetime.datetime(2010, 2, 20)
SchoolClass.objects.create(year=2009, last_updated=updated)
@@ -234,7 +234,10 @@ class LongNameTest(TransactionTestCase):
@skipUnlessDBFeature("supports_sequence_reset")
class SequenceResetTest(TestCase):
def test_generic_relation(self):
- "Sequence names are correct when resetting generic relations (Ref #13941)"
+ """
+ Sequence names are correct when resetting generic relations (Ref
+ #13941)
+ """
# Create an object with a manually specified PK
Post.objects.create(id=10, name="1st post", text="hello world")
@@ -737,7 +740,8 @@ class FkConstraintsTests(TransactionTestCase):
def test_check_constraints(self):
"""
- Constraint checks should raise an IntegrityError when bad data is in the DB.
+ Constraint checks should raise an IntegrityError when bad data is in
+ the DB.
"""
with transaction.atomic():
# Create an Article.
diff --git a/tests/basic/tests.py b/tests/basic/tests.py
index f6eabfaed7..f8ec2715f6 100644
--- a/tests/basic/tests.py
+++ b/tests/basic/tests.py
@@ -179,7 +179,8 @@ class ModelInstanceCreationTests(TestCase):
# You can use 'in' to test for membership...
self.assertIn(a, Article.objects.all())
- # ... but there will often be more efficient ways if that is all you need:
+ # ... but there will often be more efficient ways if that is all you
+ # need:
self.assertTrue(Article.objects.filter(id=a.id).exists())
def test_save_primary_with_default(self):
@@ -785,7 +786,8 @@ class ManagerTest(SimpleTestCase):
It's particularly useful to prevent accidentally leaking new methods
into `Manager`. New `QuerySet` methods that should also be copied onto
- `Manager` will need to be added to `ManagerTest.QUERYSET_PROXY_METHODS`.
+ `Manager` will need to be added to
+ `ManagerTest.QUERYSET_PROXY_METHODS`.
"""
self.assertEqual(
sorted(BaseManager._get_queryset_methods(models.QuerySet)),
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 2636a7d6ce..0b692194de 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -156,7 +156,9 @@ class DummyCacheTests(SimpleTestCase):
self.assertIsNone(cache.get("key2"))
def test_has_key(self):
- "The has_key method doesn't ever return True for the dummy cache backend"
+ """
+ The has_key method doesn't ever return True for the dummy cache backend
+ """
cache.set("hello1", "goodbye1")
self.assertIs(cache.has_key("hello1"), False)
self.assertIs(cache.has_key("goodbye1"), False)
@@ -302,11 +304,10 @@ _caches_setting_base = {
def caches_setting_for_tests(base=None, exclude=None, **params):
- # `base` is used to pull in the memcached config from the original settings,
- # `exclude` is a set of cache names denoting which `_caches_setting_base` keys
- # should be omitted.
- # `params` are test specific overrides and `_caches_settings_base` is the
- # base config for the tests.
+ # `base` is used to pull in the memcached config from the original
+ # settings, `exclude` is a set of cache names denoting which
+ # `_caches_setting_base` keys should be omitted. `params` are test specific
+ # overrides and `_caches_settings_base` is the base config for the tests.
# This results in the following search order:
# params -> _caches_setting_base -> base
base = base or {}
@@ -469,7 +470,8 @@ class BaseCacheTests:
self.assertEqual(expensive_calculation.num_runs, 1)
def test_cache_write_for_model_instance_with_deferred(self):
- # Don't want fields with callable as default to be called on cache write
+ # Don't want fields with callable as default to be called on cache
+ # write
expensive_calculation.num_runs = 0
Poll.objects.all().delete()
Poll.objects.create(question="What?")
@@ -493,7 +495,8 @@ class BaseCacheTests:
self.assertEqual(expensive_calculation.num_runs, 1)
runs_before_cache_read = expensive_calculation.num_runs
cache.get("deferred_queryset")
- # We only want the default expensive calculation run on creation and set
+ # We only want the default expensive calculation run on creation and
+ # set
self.assertEqual(expensive_calculation.num_runs, runs_before_cache_read)
def test_expiration(self):
@@ -1166,7 +1169,8 @@ class BaseCacheTests:
@override_settings(
CACHES=caches_setting_for_tests(
BACKEND="django.core.cache.backends.db.DatabaseCache",
- # Spaces are used in the table name to ensure quoting/escaping is working
+ # Spaces are used in the table name to ensure quoting/escaping is
+ # working
LOCATION="test cache table",
)
)
@@ -1256,7 +1260,8 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
@override_settings(
CACHES=caches_setting_for_tests(
BACKEND="django.core.cache.backends.db.DatabaseCache",
- # Use another table name to avoid the 'table already exists' message.
+ # Use another table name to avoid the 'table already exists'
+ # message.
LOCATION="createcachetable_dry_run_mode",
)
)
@@ -1409,7 +1414,9 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
self.assertFalse(bad_obj.locked, "Cache was locked during pickling")
def test_incr_decr_timeout(self):
- """incr/decr does not modify expiry time (matches memcached behavior)"""
+ """
+ incr/decr does not modify expiry time (matches memcached behavior)
+ """
key = "value"
_key = cache.make_key(key)
cache.set(key, 1, timeout=cache.default_timeout * 10)
@@ -1560,9 +1567,9 @@ class BaseMemcachedTests(BaseCacheTests):
self.assertEqual(cache.get("future_foo"), "bar")
def test_memcached_deletes_key_on_failed_set(self):
- # By default memcached allows objects up to 1MB. For the cache_db session
- # backend to always use the current session, memcached needs to delete
- # the old key if it fails to set.
+ # By default memcached allows objects up to 1MB. For the cache_db
+ # session backend to always use the current session, memcached needs to
+ # delete the old key if it fails to set.
max_value_length = 2**20
cache.set("small_value", "a")
@@ -1577,7 +1584,8 @@ class BaseMemcachedTests(BaseCacheTests):
# deleted, so the return/exception behavior for the set() itself is
# not important.
pass
- # small_value should be deleted, or set if configured to accept larger values
+ # small_value should be deleted, or set if configured to accept larger
+ # values
value = cache.get("small_value")
self.assertTrue(value is None or value == large_value)
@@ -2642,7 +2650,8 @@ class CacheMiddlewareTest(SimpleTestCase):
response = default_view(request, "2")
self.assertEqual(response.content, b"Hello World 1")
- # Requesting the same view with the explicit cache should yield the same result
+ # Requesting the same view with the explicit cache should yield the
+ # same result
response = explicit_default_view(request, "3")
self.assertEqual(response.content, b"Hello World 1")
diff --git a/tests/check_framework/test_security.py b/tests/check_framework/test_security.py
index db21f13ea2..d5cc8a9ad6 100644
--- a/tests/check_framework/test_security.py
+++ b/tests/check_framework/test_security.py
@@ -215,8 +215,8 @@ class CheckStrictTransportSecurityTest(SimpleTestCase):
@override_settings(MIDDLEWARE=[], SECURE_HSTS_SECONDS=0)
def test_no_sts_no_middleware(self):
"""
- Don't warn if SECURE_HSTS_SECONDS isn't > 0 and SecurityMiddleware isn't
- installed.
+ Don't warn if SECURE_HSTS_SECONDS isn't > 0 and SecurityMiddleware
+ isn't installed.
"""
self.assertEqual(base.check_sts(None), [])
diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py
index a31c5fd856..a3b219f3a4 100644
--- a/tests/check_framework/test_urls.py
+++ b/tests/check_framework/test_urls.py
@@ -24,7 +24,8 @@ class CheckUrlConfigTests(SimpleTestCase):
@override_settings(ROOT_URLCONF="check_framework.urls.warning_in_include")
def test_check_resolver_recursive(self):
- # The resolver is checked recursively (examining URL patterns in include()).
+ # The resolver is checked recursively (examining URL patterns in
+ # include()).
result = check_url_config(None)
self.assertEqual(len(result), 1)
warning = result[0]
diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py
index 764b9fa7db..c2b12b58bc 100644
--- a/tests/contenttypes_tests/test_fields.py
+++ b/tests/contenttypes_tests/test_fields.py
@@ -61,7 +61,8 @@ class GenericForeignKeyTests(TestCase):
Answer.objects.create(text="answer", question=question)
answer = Answer.objects.defer("text").get()
old_question_obj = answer.question
- # The reverse relation is refreshed even when the text field is deferred.
+ # The reverse relation is refreshed even when the text field is
+ # deferred.
answer.refresh_from_db()
self.assertIsNot(answer.question, old_question_obj)
diff --git a/tests/contenttypes_tests/test_views.py b/tests/contenttypes_tests/test_views.py
index 8cc11de3cb..bec79105c4 100644
--- a/tests/contenttypes_tests/test_views.py
+++ b/tests/contenttypes_tests/test_views.py
@@ -63,7 +63,10 @@ class ContentTypesViewsTests(TestCase):
Site.objects.clear_cache()
def test_shortcut_with_absolute_url(self):
- "Can view a shortcut for an Author object that has a get_absolute_url method"
+ """
+ Can view a shortcut for an Author object that has a get_absolute_url
+ method
+ """
for obj in Author.objects.all():
with self.subTest(obj=obj):
short_url = "/shortcut/%s/%s/" % (
diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py
index 765d950b85..91b1046159 100644
--- a/tests/csrf_tests/tests.py
+++ b/tests/csrf_tests/tests.py
@@ -441,7 +441,8 @@ class CsrfViewMiddlewareTestMixin(CsrfFunctionTestMixin):
def test_process_request_csrf_cookie_and_token(self):
"""
- If both a cookie and a token is present, the middleware lets it through.
+ If both a cookie and a token is present, the middleware lets it
+ through.
"""
req = self._get_POST_request_with_token()
mw = CsrfViewMiddleware(post_form_view)
@@ -718,14 +719,16 @@ class CsrfViewMiddlewareTestMixin(CsrfFunctionTestMixin):
self.assertContains(response, malformed_referer_msg, status_code=403)
# missing scheme
# >>> urlsplit('//example.com/')
- # SplitResult(scheme='', netloc='example.com', path='/', query='', fragment='')
+ # SplitResult(scheme='', netloc='example.com', path='/', query='',
+ # fragment='')
req.META["HTTP_REFERER"] = "//example.com/"
self._check_referer_rejects(mw, req)
response = mw.process_view(req, post_form_view, (), {})
self.assertContains(response, malformed_referer_msg, status_code=403)
# missing netloc
# >>> urlsplit('https://')
- # SplitResult(scheme='https', netloc='', path='', query='', fragment='')
+ # SplitResult(scheme='https', netloc='', path='', query='',
+ # fragment='')
req.META["HTTP_REFERER"] = "https://"
self._check_referer_rejects(mw, req)
response = mw.process_view(req, post_form_view, (), {})
diff --git a/tests/custom_lookups/tests.py b/tests/custom_lookups/tests.py
index cc6f5c7f8f..6728c49afd 100644
--- a/tests/custom_lookups/tests.py
+++ b/tests/custom_lookups/tests.py
@@ -518,7 +518,8 @@ class YearLteTests(TestCase):
def test_custom_implementation_year_exact(self):
try:
- # Two ways to add a customized implementation for different backends:
+ # Two ways to add a customized implementation for different
+ # backends:
# First is MonkeyPatch of the class.
def as_custom_sql(self, compiler, connection):
lhs_sql, lhs_params = self.process_lhs(
diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py
index b84b157da5..3d9485c13b 100644
--- a/tests/custom_managers/tests.py
+++ b/tests/custom_managers/tests.py
@@ -65,9 +65,11 @@ class CustomManagerTests(TestCase):
for manager_name in self.custom_manager_names:
with self.subTest(manager_name=manager_name):
manager = getattr(Person, manager_name)
- # Methods with queryset_only=False are copied even if they are private.
+ # Methods with queryset_only=False are copied even if they are
+ # private.
manager._optin_private_method()
- # Methods with queryset_only=True aren't copied even if they are public.
+ # Methods with queryset_only=True aren't copied even if they
+ # are public.
msg = (
"%r object has no attribute 'optout_public_method'"
% manager.__class__.__name__
diff --git a/tests/datatypes/tests.py b/tests/datatypes/tests.py
index fa08ed878d..3469311163 100644
--- a/tests/datatypes/tests.py
+++ b/tests/datatypes/tests.py
@@ -34,7 +34,8 @@ class DataTypesTestCase(TestCase):
self.assertEqual(d2.consumed_at, datetime.datetime(2007, 4, 20, 16, 19, 59))
def test_time_field(self):
- # Test for ticket #12059: TimeField wrongly handling datetime.datetime object.
+ # Test for ticket #12059: TimeField wrongly handling datetime.datetime
+ # object.
d = Donut(name="Apple Fritter")
d.baked_time = datetime.datetime(
year=2007, month=4, day=20, hour=16, minute=19, second=59
@@ -91,8 +92,8 @@ class DataTypesTestCase(TestCase):
@skipIfDBFeature("supports_timezones")
def test_error_on_timezone(self):
- """Regression test for #8354: the MySQL and Oracle backends should raise
- an error if given a timezone-aware datetime object."""
+ """Regression test for #8354: the MySQL and Oracle backends should
+ raise an error if given a timezone-aware datetime object."""
dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=datetime.UTC)
d = Donut(name="Bear claw", consumed_at=dt)
# MySQL backend does not support timezone-aware datetimes.
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index 1f8d623e02..fce64a8834 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -134,7 +134,8 @@ def simple_dec(func):
simple_dec_m = method_decorator(simple_dec)
-# For testing method_decorator, two decorators that add an attribute to the function
+# For testing method_decorator, two decorators that add an attribute to the
+# function
def myattr_dec(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
diff --git a/tests/defer/tests.py b/tests/defer/tests.py
index 989b5c63d7..c0968080b1 100644
--- a/tests/defer/tests.py
+++ b/tests/defer/tests.py
@@ -169,7 +169,8 @@ class DeferTests(AssertionMixin, TestCase):
# You can retrieve a single column on a base class with no fields
Child.objects.create(name="c1", value="foo", related=self.s1)
obj = Child.objects.only("name").get(name="c1")
- # on an inherited model, its PK is also fetched, hence '3' deferred fields.
+ # on an inherited model, its PK is also fetched, hence '3' deferred
+ # fields.
self.assert_delayed(obj, 3)
self.assertEqual(obj.name, "c1")
self.assertEqual(obj.value, "foo")
@@ -215,7 +216,8 @@ class BigChildDeferTests(AssertionMixin, TestCase):
def test_only_baseclass_when_subclass_has_added_field(self):
# You can retrieve a single field on a baseclass
obj = BigChild.objects.only("name").get(name="b1")
- # when inherited model, its PK is also fetched, hence '4' deferred fields.
+ # when inherited model, its PK is also fetched, hence '4' deferred
+ # fields.
self.assert_delayed(obj, 4)
self.assertEqual(obj.name, "b1")
self.assertEqual(obj.value, "foo")
diff --git a/tests/defer_regress/tests.py b/tests/defer_regress/tests.py
index c45a503630..2089c8603f 100644
--- a/tests/defer_regress/tests.py
+++ b/tests/defer_regress/tests.py
@@ -96,7 +96,8 @@ class DeferRegressionTest(TestCase):
self.assertEqual(results[0].child.name, "c1")
self.assertEqual(results[0].second_child.name, "c2")
- # Regression for #16409 - make sure defer() and only() work with annotate()
+ # Regression for #16409 - make sure defer() and only() work with
+ # annotate()
self.assertIsInstance(
list(SimpleItem.objects.annotate(Count("feature")).defer("name")), list
)
@@ -105,7 +106,8 @@ class DeferRegressionTest(TestCase):
)
def test_ticket_16409(self):
- # Regression for #16409 - make sure defer() and only() work with annotate()
+ # Regression for #16409 - make sure defer() and only() work with
+ # annotate()
self.assertIsInstance(
list(SimpleItem.objects.annotate(Count("feature")).defer("name")), list
)
@@ -161,8 +163,8 @@ class DeferRegressionTest(TestCase):
self.assertEqual(
len(Item.objects.select_related("one_to_one_item").defer("value")), 1
)
- # Make sure that `only()` doesn't break when we pass in a unique relation,
- # rather than a field on the relation.
+ # Make sure that `only()` doesn't break when we pass in a unique
+ # relation, rather than a field on the relation.
self.assertEqual(len(Item.objects.only("one_to_one_item")), 1)
with self.assertNumQueries(1):
i = Item.objects.select_related("one_to_one_item")[0]
diff --git a/tests/delete/tests.py b/tests/delete/tests.py
index 09c9a0a818..7b9dcdb079 100644
--- a/tests/delete/tests.py
+++ b/tests/delete/tests.py
@@ -517,8 +517,8 @@ class DeletionTests(TestCase):
batch_size = connection.ops.bulk_batch_size(["pk"], objs)
# The related fetches are done in batches.
batches = ceil(len(objs) / batch_size)
- # One query for Avatar.objects.all() and then one related fast delete for
- # each batch.
+ # One query for Avatar.objects.all() and then one related fast delete
+ # for each batch.
fetches_to_mem = 1 + batches
# The Avatar objects are going to be deleted in batches of
# GET_ITERATOR_CHUNK_SIZE.
diff --git a/tests/dispatch/tests.py b/tests/dispatch/tests.py
index e91d29abdd..745860e83e 100644
--- a/tests/dispatch/tests.py
+++ b/tests/dispatch/tests.py
@@ -146,7 +146,8 @@ class DispatcherTests(SimpleTestCase):
try:
self.assertIsNone(wref())
finally:
- # Disconnect after reference check since it flushes the tested cache.
+ # Disconnect after reference check since it flushes the tested
+ # cache.
d_signal.disconnect(receiver_1_arg)
def test_multiple_registration(self):
diff --git a/tests/expressions_window/tests.py b/tests/expressions_window/tests.py
index 4480e15eb4..2d68099545 100644
--- a/tests/expressions_window/tests.py
+++ b/tests/expressions_window/tests.py
@@ -1293,7 +1293,9 @@ class WindowFunctionTests(TestCase):
)
def test_range_unbound(self):
- """A query with RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING."""
+ """
+ A query with RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
+ """
qs = Employee.objects.annotate(
sum=Window(
expression=Sum("salary"),
diff --git a/tests/extra_regress/tests.py b/tests/extra_regress/tests.py
index f495b2eccf..786a1b8a9a 100644
--- a/tests/extra_regress/tests.py
+++ b/tests/extra_regress/tests.py
@@ -307,7 +307,8 @@ class ExtraRegressTests(TestCase):
[("first", "second")],
)
- # Extra columns after a non-empty values_list() clause are ignored completely
+ # Extra columns after a non-empty values_list() clause are ignored
+ # completely
self.assertEqual(
list(
TestObject.objects.values_list("first", "second").extra(
diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py
index 41353cbaaf..8c500349fc 100644
--- a/tests/field_deconstruction/tests.py
+++ b/tests/field_deconstruction/tests.py
@@ -333,7 +333,8 @@ class FieldDeconstructionTests(SimpleTestCase):
def test_foreign_key_swapped(self):
with isolate_lru_cache(apps.get_swappable_settings_name):
# It doesn't matter that we swapped out user for permission;
- # there's no validation. We just want to check the setting stuff works.
+ # there's no validation. We just want to check the setting stuff
+ # works.
field = models.ForeignKey("auth.Permission", models.CASCADE)
name, path, args, kwargs = field.deconstruct()
@@ -570,7 +571,8 @@ class FieldDeconstructionTests(SimpleTestCase):
def test_many_to_many_field_swapped(self):
with isolate_lru_cache(apps.get_swappable_settings_name):
# It doesn't matter that we swapped out user for permission;
- # there's no validation. We just want to check the setting stuff works.
+ # there's no validation. We just want to check the setting stuff
+ # works.
field = models.ManyToManyField("auth.Permission")
name, path, args, kwargs = field.deconstruct()
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index fde07a955c..a0234b2f9d 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -359,7 +359,8 @@ class FileStorageTests(SimpleTestCase):
self.storage.url("""a/b\\c.file"""), "/test_media_url/a/b/c.file"
)
- # #25905: remove leading slashes from file names to prevent unsafe url output
+ # #25905: remove leading slashes from file names to prevent unsafe url
+ # output
self.assertEqual(self.storage.url("/evil.com"), "/test_media_url/evil.com")
self.assertEqual(self.storage.url(r"\evil.com"), "/test_media_url/evil.com")
self.assertEqual(self.storage.url("///evil.com"), "/test_media_url/evil.com")
@@ -406,8 +407,8 @@ class FileStorageTests(SimpleTestCase):
def test_file_storage_prevents_directory_traversal(self):
"""
- File storage prevents directory traversal (files can only be accessed if
- they're below the storage location).
+ File storage prevents directory traversal (files can only be accessed
+ if they're below the storage location).
"""
with self.assertRaises(SuspiciousFileOperation):
self.storage.exists("..")
@@ -434,7 +435,8 @@ class FileStorageTests(SimpleTestCase):
def test_makedirs_race_handling(self):
"""
- File storage should be robust against directory creation race conditions.
+ File storage should be robust against directory creation race
+ conditions.
"""
real_makedirs = os.makedirs
@@ -824,7 +826,8 @@ class FileFieldStorageTests(TestCase):
obj.normal.close()
def test_duplicate_filename(self):
- # Multiple files with the same name get _(7 random chars) appended to them.
+ # Multiple files with the same name get _(7 random chars) appended to
+ # them.
tests = [
("multiple_files", "txt"),
("multiple_files_many_extensions", "tar.gz"),
@@ -861,7 +864,8 @@ class FileFieldStorageTests(TestCase):
self.assertEqual(names[0], "tests/%s" % filename)
self.assertRegex(names[1], "tests/fi_%s.ext" % FILE_SUFFIX_REGEX)
- # Testing exception is raised when filename is too short to truncate.
+ # Testing exception is raised when filename is too short to
+ # truncate.
filename = "short.longext"
objs[0].limited_length.save(filename, ContentFile("Same Content"))
with self.assertRaisesMessage(
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index b6b4bb0c69..6374b4cee6 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -184,7 +184,8 @@ class FileUploadTests(TestCase):
def test_unicode_file_name(self):
with sys_tempfile.TemporaryDirectory() as temp_dir:
- # This file contains Chinese symbols and an accented char in the name.
+ # This file contains Chinese symbols and an accented char in the
+ # name.
with open(os.path.join(temp_dir, UNICODE_FILENAME), "w+b") as file1:
file1.write(b"b" * (2**10))
file1.seek(0)
@@ -372,12 +373,14 @@ class FileUploadTests(TestCase):
self.assertEqual(received["file"], "non-printable_chars.txt")
def test_dangerous_file_names(self):
- """Uploaded file names should be sanitized before ever reaching the view."""
+ """
+ Uploaded file names should be sanitized before ever reaching the view.
+ """
# This test simulates possible directory traversal attacks by a
- # malicious uploader We have to do some monkeybusiness here to construct
- # a malicious payload with an invalid file name (containing os.sep or
- # os.pardir). This similar to what an attacker would need to do when
- # trying such an attack.
+ # malicious uploader We have to do some monkeybusiness here to
+ # construct a malicious payload with an invalid file name (containing
+ # os.sep or os.pardir). This similar to what an attacker would need to
+ # do when trying such an attack.
payload = client.FakePayload()
for i, name in enumerate(CANDIDATE_TRAVERSAL_FILE_NAMES):
payload.write(
@@ -402,14 +405,18 @@ class FileUploadTests(TestCase):
"wsgi.input": payload,
}
response = self.client.request(**r)
- # The filenames should have been sanitized by the time it got to the view.
+ # The filenames should have been sanitized by the time it got to the
+ # view.
received = response.json()
for i, name in enumerate(CANDIDATE_TRAVERSAL_FILE_NAMES):
got = received["file%s" % i]
self.assertEqual(got, "hax0rd.txt")
def test_filename_overflow(self):
- """File names over 256 characters (dangerous on some platforms) get fixed up."""
+ """
+ File names over 256 characters (dangerous on some platforms) get fixed
+ up.
+ """
long_str = "f" * 300
cases = [
# field name, filename, expected
@@ -741,7 +748,8 @@ class FileUploadTests(TestCase):
# Maybe this is a little more complicated that it needs to be; but if
# the django.test.client.FakePayload.read() implementation changes then
# this test would fail. So we need to know exactly what kind of error
- # it raises when there is an attempt to read more than the available bytes:
+ # it raises when there is an attempt to read more than the available
+ # bytes:
try:
client.FakePayload(b"a").read(2)
except Exception as err:
diff --git a/tests/file_uploads/views.py b/tests/file_uploads/views.py
index c1d4ca5358..f4f3b5c514 100644
--- a/tests/file_uploads/views.py
+++ b/tests/file_uploads/views.py
@@ -135,7 +135,8 @@ def file_upload_interrupted_temporary_file(request):
def file_upload_getlist_count(request):
"""
- Check the .getlist() function to ensure we receive the correct number of files.
+ Check the .getlist() function to ensure we receive the correct number of
+ files.
"""
file_counts = {}
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 7e365aae39..cfda70053f 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -463,8 +463,8 @@ class FileMoveSafeTests(unittest.TestCase):
):
with self.assertRaises(OSError):
file_move_safe(self.file_a, self.file_b, allow_overwrite=True)
- # When copystat() throws PermissionError, copymode() error besides
- # PermissionError isn't ignored.
+ # When copystat() throws PermissionError, copymode() error
+ # besides PermissionError isn't ignored.
with mock.patch(
"django.core.files.move.copystat", side_effect=permission_error
):
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index bce55bc355..48e3182b59 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -239,7 +239,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
'"pub_date": "2006-06-16T13:00:00"}}]',
)
- # Specify one model from one application, and an entire other application.
+ # Specify one model from one application, and an entire other
+ # application.
self._dumpdata_assert(
["fixtures.Category", "sites"],
'[{"pk": 1, "model": "fixtures.category", "fields": '
@@ -272,7 +273,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
],
)
- # Load fixture 6, JSON file with dynamic ContentType fields. Testing ManyToOne.
+ # Load fixture 6, JSON file with dynamic ContentType fields. Testing
+ # ManyToOne.
management.call_command("loaddata", "fixture6.json", verbosity=0)
self.assertQuerySetEqual(
Tag.objects.all(),
@@ -284,7 +286,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
ordered=False,
)
- # Load fixture 7, XML file with dynamic ContentType fields. Testing ManyToOne.
+ # Load fixture 7, XML file with dynamic ContentType fields. Testing
+ # ManyToOne.
management.call_command("loaddata", "fixture7.xml", verbosity=0)
self.assertQuerySetEqual(
Tag.objects.all(),
@@ -298,7 +301,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
ordered=False,
)
- # Load fixture 8, JSON file with dynamic Permission fields. Testing ManyToMany.
+ # Load fixture 8, JSON file with dynamic Permission fields. Testing
+ # ManyToMany.
management.call_command("loaddata", "fixture8.json", verbosity=0)
self.assertQuerySetEqual(
Visa.objects.all(),
@@ -312,7 +316,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
ordered=False,
)
- # Load fixture 9, XML file with dynamic Permission fields. Testing ManyToMany.
+ # Load fixture 9, XML file with dynamic Permission fields. Testing
+ # ManyToMany.
management.call_command("loaddata", "fixture9.xml", verbosity=0)
self.assertQuerySetEqual(
Visa.objects.all(),
@@ -344,7 +349,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
'{"name": "Music for all ages", "authors": [3, 1]}}]',
)
- # But you can get natural keys if you ask for them and they are available
+ # But you can get natural keys if you ask for them and they are
+ # available
self._dumpdata_assert(
["fixtures.book"],
'[{"pk": 1, "model": "fixtures.book", "fields": '
@@ -548,7 +554,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
exclude_list=["fixtures.Article", "fixtures.Book"],
)
- # Excluding sites and fixtures.Article/Book should only leave fixtures.Category
+ # Excluding sites and fixtures.Article/Book should only leave
+ # fixtures.Category
self._dumpdata_assert(
["sites", "fixtures"],
'[{"pk": 1, "model": "fixtures.category", "fields": '
@@ -852,7 +859,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
self.assertEqual(Article.objects.get().headline, "Django pets kitten")
def test_compressed_specified_loading(self):
- # Load fixture 5 (compressed), using format *and* compression specification
+ # Load fixture 5 (compressed), using format *and* compression
+ # specification
management.call_command("loaddata", "fixture5.json.zip", verbosity=0)
self.assertEqual(
Article.objects.get().headline,
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 96d33e2df7..999555effe 100644
--- a/tests/fixtures_regress/tests.py
+++ b/tests/fixtures_regress/tests.py
@@ -307,8 +307,9 @@ class TestFixtures(TestCase):
def test_empty(self):
"""
- Test for ticket #18213 -- Loading a fixture file with no data output a warning.
- Previously empty fixture raises an error exception, see ticket #4371.
+ Test for ticket #18213 -- Loading a fixture file with no data output a
+ warning. Previously empty fixture raises an error exception, see ticket
+ #4371.
"""
msg = "No fixture data found for 'empty'. (File format may be invalid.)"
with self.assertWarnsMessage(RuntimeWarning, msg):
@@ -598,7 +599,8 @@ class TestFixtures(TestCase):
def test_fixture_dirs_with_default_fixture_path(self):
"""
settings.FIXTURE_DIRS cannot contain a default fixtures directory
- for application (app/fixtures) in order to avoid repeated fixture loading.
+ for application (app/fixtures) in order to avoid repeated fixture
+ loading.
"""
msg = (
"'%s' is a default fixture directory for the '%s' app "
@@ -612,7 +614,8 @@ class TestFixtures(TestCase):
def test_fixture_dirs_with_default_fixture_path_as_pathlib(self):
"""
settings.FIXTURE_DIRS cannot contain a default fixtures directory
- for application (app/fixtures) in order to avoid repeated fixture loading.
+ for application (app/fixtures) in order to avoid repeated fixture
+ loading.
"""
msg = (
"'%s' is a default fixture directory for the '%s' app "
@@ -686,7 +689,8 @@ class NaturalKeyFixtureTests(TestCase):
def test_nk_on_serialize(self):
"""
- Natural key requirements are taken into account when serializing models.
+ Natural key requirements are taken into account when serializing
+ models.
"""
management.call_command(
"loaddata",
@@ -869,7 +873,8 @@ class M2MNaturalKeyFixtureTests(TestCase):
def test_dependency_sorting_m2m_simple(self):
"""
- M2M relations without explicit through models SHOULD count as dependencies
+ M2M relations without explicit through models SHOULD count as
+ dependencies
Regression test for bugs that could be caused by flawed fixes to
#14226, namely if M2M checks are removed from sort_dependencies
@@ -908,7 +913,8 @@ class M2MNaturalKeyFixtureTests(TestCase):
def test_dependency_sorting_m2m_complex_circular_1(self):
"""
- Circular M2M relations with explicit through models should be serializable
+ Circular M2M relations with explicit through models should be
+ serializable
"""
A, B, C, AtoB, BtoC, CtoA = (
M2MComplexCircular1A,
@@ -929,8 +935,9 @@ class M2MNaturalKeyFixtureTests(TestCase):
def test_dependency_sorting_m2m_complex_circular_2(self):
"""
- Circular M2M relations with explicit through models should be serializable
- This test tests the circularity with explicit natural_key.dependencies
+ Circular M2M relations with explicit through models should be
+ serializable This test tests the circularity with explicit
+ natural_key.dependencies
"""
sorted_deps = serializers.sort_dependencies(
[
@@ -945,7 +952,8 @@ class M2MNaturalKeyFixtureTests(TestCase):
def test_dump_and_load_m2m_simple(self):
"""
- Test serializing and deserializing back models with simple M2M relations
+ Test serializing and deserializing back models with simple M2M
+ relations
"""
a = M2MSimpleA.objects.create(data="a")
b1 = M2MSimpleB.objects.create(data="b1")
diff --git a/tests/flatpages_tests/test_csrf.py b/tests/flatpages_tests/test_csrf.py
index 62ac5f9a14..702b0c5614 100644
--- a/tests/flatpages_tests/test_csrf.py
+++ b/tests/flatpages_tests/test_csrf.py
@@ -70,7 +70,10 @@ class FlatpageCSRFTests(TestCase):
self.client = Client(enforce_csrf_checks=True)
def test_view_flatpage(self):
- "A flatpage can be served through a view, even when the middleware is in use"
+ """
+ A flatpage can be served through a view, even when the middleware is in
+ use
+ """
response = self.client.get("/flatpage_root/flatpage/")
self.assertContains(response, "<p>Isn't it flat!</p>")
diff --git a/tests/flatpages_tests/test_middleware.py b/tests/flatpages_tests/test_middleware.py
index 581947e9f6..5d779c656c 100644
--- a/tests/flatpages_tests/test_middleware.py
+++ b/tests/flatpages_tests/test_middleware.py
@@ -69,7 +69,10 @@ class TestDataMixin:
)
class FlatpageMiddlewareTests(TestDataMixin, TestCase):
def test_view_flatpage(self):
- "A flatpage can be served through a view, even when the middleware is in use"
+ """
+ A flatpage can be served through a view, even when the middleware is in
+ use
+ """
response = self.client.get("/flatpage_root/flatpage/")
self.assertContains(response, "<p>Isn't it flat!</p>")
@@ -161,7 +164,10 @@ class FlatpageMiddlewareAppendSlashTests(TestDataMixin, TestCase):
self.assertEqual(response.status_code, 404)
def test_redirect_fallback_flatpage(self):
- "A flatpage can be served by the fallback middleware and should add a slash"
+ """
+ A flatpage can be served by the fallback middleware and should add a
+ slash
+ """
response = self.client.get("/flatpage")
self.assertRedirects(response, "/flatpage/", status_code=301)
@@ -193,7 +199,10 @@ class FlatpageMiddlewareAppendSlashTests(TestDataMixin, TestCase):
)
def test_redirect_fallback_flatpage_root(self):
- "A flatpage at / should not cause a redirect loop when APPEND_SLASH is set"
+ """
+ A flatpage at / should not cause a redirect loop when APPEND_SLASH is
+ set
+ """
fp = FlatPage.objects.create(
url="/",
title="Root",
diff --git a/tests/flatpages_tests/test_templatetags.py b/tests/flatpages_tests/test_templatetags.py
index eb36ee375b..f21940db79 100644
--- a/tests/flatpages_tests/test_templatetags.py
+++ b/tests/flatpages_tests/test_templatetags.py
@@ -50,7 +50,10 @@ class FlatpageTemplateTagTests(TestCase):
cls.fp4.sites.add(cls.site1)
def test_get_flatpages_tag(self):
- "The flatpage template tag retrieves unregistered prefixed flatpages by default"
+ """
+ The flatpage template tag retrieves unregistered prefixed flatpages by
+ default
+ """
out = Template(
"{% load flatpages %}"
"{% get_flatpages as flatpages %}"
@@ -75,7 +78,10 @@ class FlatpageTemplateTagTests(TestCase):
self.assertEqual(out, "A Flatpage,A Nested Flatpage,")
def test_get_flatpages_tag_for_user(self):
- "The flatpage template tag retrieves all flatpages for an authenticated user"
+ """
+ The flatpage template tag retrieves all flatpages for an authenticated
+ user
+ """
me = User.objects.create_user("testuser", "test@example.com", "s3krit")
out = Template(
"{% load flatpages %}"
@@ -89,7 +95,10 @@ class FlatpageTemplateTagTests(TestCase):
)
def test_get_flatpages_with_prefix(self):
- "The flatpage template tag retrieves unregistered prefixed flatpages by default"
+ """
+ The flatpage template tag retrieves unregistered prefixed flatpages by
+ default
+ """
out = Template(
"{% load flatpages %}"
"{% get_flatpages '/location/' as location_flatpages %}"
diff --git a/tests/foreign_object/models/article.py b/tests/foreign_object/models/article.py
index dedeb8fb2d..276296c8d4 100644
--- a/tests/foreign_object/models/article.py
+++ b/tests/foreign_object/models/article.py
@@ -28,8 +28,8 @@ class ColConstraint:
class ActiveTranslationField(models.ForeignObject):
"""
- This field will allow querying and fetching the currently active translation
- for Article from ArticleTranslation.
+ This field will allow querying and fetching the currently active
+ translation for Article from ArticleTranslation.
"""
requires_unique_target = False
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 696dfcd5fd..b4072d500d 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -72,7 +72,8 @@ class MultiColumnFKTests(TestCase):
getattr(membership, "person")
def test_reverse_query_returns_correct_result(self):
- # Creating a valid membership because it has the same country has the person
+ # Creating a valid membership because it has the same country has the
+ # person
Membership.objects.create(
membership_country_id=self.usa.id,
person_id=self.bob.id,
diff --git a/tests/forms_tests/field_tests/test_booleanfield.py b/tests/forms_tests/field_tests/test_booleanfield.py
index d6b5121b10..f1c06c3c01 100644
--- a/tests/forms_tests/field_tests/test_booleanfield.py
+++ b/tests/forms_tests/field_tests/test_booleanfield.py
@@ -50,7 +50,8 @@ class BooleanFieldTest(SimpleTestCase):
self.assertTrue(f.has_changed(False, "on"))
self.assertFalse(f.has_changed(True, "on"))
self.assertTrue(f.has_changed(True, ""))
- # Initial value may have mutated to a string due to show_hidden_initial (#19537)
+ # Initial value may have mutated to a string due to show_hidden_initial
+ # (#19537)
self.assertTrue(f.has_changed("False", "on"))
# HiddenInput widget sends string values for boolean but doesn't clean
# them in value_from_datadict.
diff --git a/tests/forms_tests/field_tests/test_charfield.py b/tests/forms_tests/field_tests/test_charfield.py
index 2c3f9b7ebe..e1d89523f8 100644
--- a/tests/forms_tests/field_tests/test_charfield.py
+++ b/tests/forms_tests/field_tests/test_charfield.py
@@ -80,7 +80,8 @@ class CharFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
minlength/maxlength if min_length/max_length are defined on the field
and the widget is not hidden.
"""
- # Return an empty dictionary if max_length and min_length are both None.
+ # Return an empty dictionary if max_length and min_length are both
+ # None.
f = CharField()
self.assertEqual(f.widget_attrs(TextInput()), {})
self.assertEqual(f.widget_attrs(Textarea()), {})
diff --git a/tests/forms_tests/field_tests/test_datefield.py b/tests/forms_tests/field_tests/test_datefield.py
index 65ac76319d..a8f39aa8e8 100644
--- a/tests/forms_tests/field_tests/test_datefield.py
+++ b/tests/forms_tests/field_tests/test_datefield.py
@@ -215,6 +215,6 @@ class DateFieldTest(SimpleTestCase):
try:
f.strptime("31 мая 2011", "%d-%b-%y")
except Exception as e:
- # assertIsInstance or assertRaises cannot be used because UnicodeEncodeError
- # is a subclass of ValueError
+ # assertIsInstance or assertRaises cannot be used because
+ # UnicodeEncodeError is a subclass of ValueError
self.assertEqual(e.__class__, ValueError)
diff --git a/tests/forms_tests/field_tests/test_filefield.py b/tests/forms_tests/field_tests/test_filefield.py
index 9744981471..d407df99c9 100644
--- a/tests/forms_tests/field_tests/test_filefield.py
+++ b/tests/forms_tests/field_tests/test_filefield.py
@@ -105,8 +105,8 @@ class FileFieldTest(SimpleTestCase):
# A file was not uploaded, but there is initial data
self.assertFalse(f.has_changed("resume.txt", None))
- # A file was uploaded and there is initial data (file identity is not dealt
- # with here)
+ # A file was uploaded and there is initial data (file identity is not
+ # dealt with here)
self.assertTrue(
f.has_changed(
"resume.txt", {"filename": "resume.txt", "content": "My resume"}
diff --git a/tests/forms_tests/field_tests/test_typedchoicefield.py b/tests/forms_tests/field_tests/test_typedchoicefield.py
index 52a83eca37..3537623272 100644
--- a/tests/forms_tests/field_tests/test_typedchoicefield.py
+++ b/tests/forms_tests/field_tests/test_typedchoicefield.py
@@ -19,13 +19,15 @@ class TypedChoiceFieldTest(SimpleTestCase):
self.assertEqual(1.0, f.clean("1"))
def test_typedchoicefield_3(self):
- # This can also cause weirdness: be careful (bool(-1) == True, remember)
+ # This can also cause weirdness: be careful (bool(-1) == True,
+ # remember)
f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=bool)
self.assertTrue(f.clean("-1"))
def test_typedchoicefield_4(self):
- # Even more weirdness: if you have a valid choice but your coercion function
- # can't coerce, you'll still get a validation error. Don't do this!
+ # Even more weirdness: if you have a valid choice but your coercion
+ # function can't coerce, you'll still get a validation error. Don't do
+ # this!
f = TypedChoiceField(choices=[("A", "A"), ("B", "B")], coerce=int)
msg = "'Select a valid choice. B is not one of the available choices.'"
with self.assertRaisesMessage(ValidationError, msg):
@@ -40,7 +42,8 @@ class TypedChoiceFieldTest(SimpleTestCase):
choices=[(1, "+1"), (-1, "-1")], coerce=int, required=False
)
self.assertEqual("", f.clean(""))
- # If you want cleaning an empty value to return a different type, tell the field
+ # If you want cleaning an empty value to return a different type, tell
+ # the field
def test_typedchoicefield_6(self):
f = TypedChoiceField(
diff --git a/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py b/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py
index 6810f1ed19..e874e192d8 100644
--- a/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py
+++ b/tests/forms_tests/field_tests/test_typedmultiplechoicefield.py
@@ -19,7 +19,8 @@ class TypedMultipleChoiceFieldTest(SimpleTestCase):
self.assertEqual([1.0], f.clean(["1"]))
def test_typedmultiplechoicefield_3(self):
- # This can also cause weirdness: be careful (bool(-1) == True, remember)
+ # This can also cause weirdness: be careful (bool(-1) == True,
+ # remember)
f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=bool)
self.assertEqual([True], f.clean(["-1"]))
@@ -31,8 +32,9 @@ class TypedMultipleChoiceFieldTest(SimpleTestCase):
f.clean(["1", "2"])
def test_typedmultiplechoicefield_5(self):
- # Even more weirdness: if you have a valid choice but your coercion function
- # can't coerce, you'll still get a validation error. Don't do this!
+ # Even more weirdness: if you have a valid choice but your coercion
+ # function can't coerce, you'll still get a validation error. Don't do
+ # this!
f = TypedMultipleChoiceField(choices=[("A", "A"), ("B", "B")], coerce=int)
msg = "'Select a valid choice. B is not one of the available choices.'"
with self.assertRaisesMessage(ValidationError, msg):
@@ -49,7 +51,8 @@ class TypedMultipleChoiceFieldTest(SimpleTestCase):
self.assertEqual([], f.clean([]))
def test_typedmultiplechoicefield_7(self):
- # If you want cleaning an empty value to return a different type, tell the field
+ # If you want cleaning an empty value to return a different type, tell
+ # the field
f = TypedMultipleChoiceField(
choices=[(1, "+1"), (-1, "-1")],
coerce=int,
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index ae19ef1d0c..5b0c4b9a04 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -81,9 +81,9 @@ class MultiValueDictLike(dict):
class FormsTestCase(SimpleTestCase):
- # A Form is a collection of Fields. It knows how to validate a set of data and it
- # knows how to render itself in a couple of default ways (e.g., an HTML table).
- # You can pass it data in __init__(), as a dictionary.
+ # A Form is a collection of Fields. It knows how to validate a set of data
+ # and it knows how to render itself in a couple of default ways (e.g., an
+ # HTML table). You can pass it data in __init__(), as a dictionary.
def test_form(self):
# Pass a dictionary to a Form's __init__().
@@ -268,9 +268,10 @@ aria-describedby="id_birthday_error">
self.assertIs(p.files, files)
def test_unbound_form(self):
- # If you don't pass any values to the Form's __init__(), or if you pass None,
- # the Form will be considered unbound and won't do any validation. Form.errors
- # will be an empty dictionary *but* Form.is_valid() will return False.
+ # If you don't pass any values to the Form's __init__(), or if you pass
+ # None, the Form will be considered unbound and won't do any
+ # validation. Form.errors will be an empty dictionary *but*
+ # Form.is_valid() will return False.
p = Person()
self.assertFalse(p.is_bound)
self.assertEqual(p.errors, {})
@@ -419,10 +420,10 @@ aria-describedby="id_birthday_error">
)
def test_cleaned_data_only_fields(self):
- # cleaned_data will always *only* contain a key for fields defined in the
- # Form, even if you pass extra data when you define the Form. In this
- # example, we pass a bunch of extra fields to the form constructor,
- # but cleaned_data contains only the form's fields.
+ # cleaned_data will always *only* contain a key for fields defined in
+ # the Form, even if you pass extra data when you define the Form. In
+ # this example, we pass a bunch of extra fields to the form
+ # constructor, but cleaned_data contains only the form's fields.
data = {
"first_name": "John",
"last_name": "Lennon",
@@ -511,8 +512,8 @@ aria-describedby="id_birthday_error">
)
def test_auto_id_true(self):
- # If auto_id is any True value whose str() does not contain '%s', the "id"
- # attribute will be the name of the field.
+ # If auto_id is any True value whose str() does not contain '%s', the
+ # "id" attribute will be the name of the field.
p = Person(auto_id=True)
self.assertHTMLEqual(
p.as_ul(),
@@ -525,8 +526,8 @@ aria-describedby="id_birthday_error">
)
def test_auto_id_false(self):
- # If auto_id is any False value, an "id" attribute won't be output unless it
- # was manually entered.
+ # If auto_id is any False value, an "id" attribute won't be output
+ # unless it was manually entered.
p = Person(auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -536,8 +537,9 @@ aria-describedby="id_birthday_error">
)
def test_id_on_field(self):
- # In this example, auto_id is False, but the "id" attribute for the "first_name"
- # field is given. Also note that field gets a <label>, while the others don't.
+ # In this example, auto_id is False, but the "id" attribute for the
+ # "first_name" field is given. Also note that field gets a <label>,
+ # while the others don't.
p = PersonNew(auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -548,8 +550,8 @@ aria-describedby="id_birthday_error">
)
def test_auto_id_on_form_and_field(self):
- # If the "id" attribute is specified in the Form and auto_id is True, the "id"
- # attribute in the Form gets precedence.
+ # If the "id" attribute is specified in the Form and auto_id is True,
+ # the "id" attribute in the Form gets precedence.
p = PersonNew(auto_id=True)
self.assertHTMLEqual(
p.as_ul(),
@@ -636,8 +638,8 @@ aria-describedby="id_birthday_error">
'<textarea name="message" rows="10" cols="40" required></textarea>',
)
- # as_textarea(), as_text() and as_hidden() are shortcuts for changing the output
- # widget type:
+ # as_textarea(), as_text() and as_hidden() are shortcuts for changing
+ # the output widget type:
self.assertHTMLEqual(
f["subject"].as_textarea(),
'<textarea name="subject" rows="10" cols="40" required></textarea>',
@@ -660,8 +662,8 @@ aria-describedby="id_birthday_error">
'<textarea name="message" rows="80" cols="20" required></textarea>',
)
- # Instance-level attrs are *not* carried over to as_textarea(), as_text() and
- # as_hidden():
+ # Instance-level attrs are *not* carried over to as_textarea(),
+ # as_text() and as_hidden():
self.assertHTMLEqual(
f["message"].as_text(), '<input type="text" name="message" required>'
)
@@ -702,8 +704,9 @@ aria-describedby="id_birthday_error">
</select>""",
)
- # A subtlety: If one of the choices' value is the empty string and the form is
- # unbound, then the <option> for the empty-string choice will get selected.
+ # A subtlety: If one of the choices' value is the empty string and the
+ # form is unbound, then the <option> for the empty-string choice will
+ # get selected.
class FrameworkForm(Form):
name = CharField()
language = ChoiceField(
@@ -745,9 +748,9 @@ aria-describedby="id_birthday_error">
</select>""",
)
- # When passing a custom widget instance to ChoiceField, note that setting
- # 'choices' on the widget is meaningless. The widget will use the choices
- # defined on the Field, not the ones defined on the Widget.
+ # When passing a custom widget instance to ChoiceField, note that
+ # setting 'choices' on the widget is meaningless. The widget will use
+ # the choices defined on the Field, not the ones defined on the Widget.
class FrameworkForm(Form):
name = CharField()
language = ChoiceField(
@@ -1002,7 +1005,8 @@ aria-describedby="id_birthday_error">
self.assertHTMLEqual(str(fields[0]), '<option value="john">John</option>')
def test_form_with_noniterable_boundfield(self):
- # You can iterate over any BoundField, not just those with widget=RadioSelect.
+ # You can iterate over any BoundField, not just those with
+ # widget=RadioSelect.
class BeatleForm(Form):
name = CharField()
@@ -1049,7 +1053,8 @@ aria-describedby="id_birthday_error">
self.assertIs(bool(TestForm()["name"]), True)
def test_forms_with_multiple_choice(self):
- # MultipleChoiceField is a special case, as its data is required to be a list:
+ # MultipleChoiceField is a special case, as its data is required to be
+ # a list:
class SongForm(Form):
name = CharField()
composers = MultipleChoiceField()
@@ -1226,9 +1231,9 @@ aria-describedby="id_birthday_error">
choices=[("J", "John Lennon"), ("P", "Paul McCartney")]
)
- # MultipleChoiceField rendered as_hidden() is a special case. Because it can
- # have multiple values, its as_hidden() renders multiple <input type="hidden">
- # tags.
+ # MultipleChoiceField rendered as_hidden() is a special case. Because
+ # it can have multiple values, its as_hidden() renders multiple <input
+ # type="hidden"> tags.
f = SongForm({"name": "Yesterday", "composers": ["P"]}, auto_id=False)
self.assertHTMLEqual(
f["composers"].as_hidden(),
@@ -1260,7 +1265,8 @@ aria-describedby="id_birthday_error">
)
def test_multiple_choice_checkbox(self):
- # MultipleChoiceField can also be used with the CheckboxSelectMultiple widget.
+ # MultipleChoiceField can also be used with the CheckboxSelectMultiple
+ # widget.
f = SongForm(auto_id=False)
self.assertHTMLEqual(
str(f["composers"]),
@@ -1299,9 +1305,9 @@ aria-describedby="id_birthday_error">
)
def test_checkbox_auto_id(self):
- # Regarding auto_id, CheckboxSelectMultiple is a special case. Each checkbox
- # gets a distinct ID, formed by appending an underscore plus the checkbox's
- # zero-based index.
+ # Regarding auto_id, CheckboxSelectMultiple is a special case. Each
+ # checkbox gets a distinct ID, formed by appending an underscore plus
+ # the checkbox's zero-based index.
class SongForm(Form):
name = CharField()
composers = MultipleChoiceField(
@@ -1360,7 +1366,8 @@ aria-describedby="id_birthday_error">
widget=CheckboxSelectMultiple,
)
- # The MultipleHiddenInput widget renders multiple values as hidden fields.
+ # The MultipleHiddenInput widget renders multiple values as hidden
+ # fields.
class SongFormHidden(Form):
name = CharField()
composers = MultipleChoiceField(
@@ -1379,8 +1386,8 @@ aria-describedby="id_birthday_error">
<input type="hidden" name="composers" value="P"></li>""",
)
- # When using CheckboxSelectMultiple, the framework expects a list of input and
- # returns a list of input.
+ # When using CheckboxSelectMultiple, the framework expects a list of
+ # input and returns a list of input.
f = SongForm({"name": "Yesterday"}, auto_id=False)
self.assertEqual(f.errors["composers"], ["This field is required."])
f = SongForm({"name": "Yesterday", "composers": ["J"]}, auto_id=False)
@@ -1780,9 +1787,9 @@ aria-describedby="id_birthday_error">
)
def test_dynamic_construction(self):
- # It's possible to construct a Form dynamically by adding to the self.fields
- # dictionary in __init__(). Don't forget to call Form.__init__() within the
- # subclass' __init__().
+ # It's possible to construct a Form dynamically by adding to the
+ # self.fields dictionary in __init__(). Don't forget to call
+ # Form.__init__() within the subclass' __init__().
class Person(Form):
first_name = CharField()
last_name = CharField()
@@ -1804,8 +1811,8 @@ aria-describedby="id_birthday_error">
""",
)
- # Instances of a dynamic Form do not persist fields from one Form instance to
- # the next.
+ # Instances of a dynamic Form do not persist fields from one Form
+ # instance to the next.
class MyForm(Form):
def __init__(self, data=None, auto_id=False, field_list=[]):
Form.__init__(self, data, auto_id=auto_id)
@@ -1869,8 +1876,8 @@ aria-describedby="id_birthday_error">
""",
)
- # Similarly, changes to field attributes do not persist from one Form instance
- # to the next.
+ # Similarly, changes to field attributes do not persist from one Form
+ # instance to the next.
class Person(Form):
first_name = CharField(required=False)
last_name = CharField(required=False)
@@ -1981,10 +1988,10 @@ aria-describedby="id_birthday_error">
)
def test_hidden_widget(self):
- # HiddenInput widgets are displayed differently in the as_table(), as_ul())
- # and as_p() output of a Form -- their verbose names are not displayed, and a
- # separate row is not displayed. They're displayed in the last row of the
- # form, directly after that row's form element.
+ # HiddenInput widgets are displayed differently in the as_table(),
+ # as_ul()) and as_p() output of a Form -- their verbose names are not
+ # displayed, and a separate row is not displayed. They're displayed in
+ # the last row of the form, directly after that row's form element.
class Person(Form):
first_name = CharField()
last_name = CharField()
@@ -2030,7 +2037,8 @@ aria-describedby="id_birthday_error">
'type="hidden" name="hidden_text"></div>',
)
- # With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label.
+ # With auto_id set, a HiddenInput still gets an ID, but it doesn't get
+ # a label.
p = Person(auto_id="id_%s")
self.assertHTMLEqual(
p.as_table(),
@@ -2072,10 +2080,10 @@ aria-describedby="id_birthday_error">
'<input type="hidden" name="hidden_text" id="id_hidden_text"></div>',
)
- # If a field with a HiddenInput has errors, the as_table() and as_ul() output
- # will include the error message(s) with the text "(Hidden field [fieldname]) "
- # prepended. This message is displayed at the top of the output, regardless of
- # its field's order in the form.
+ # If a field with a HiddenInput has errors, the as_table() and as_ul()
+ # output will include the error message(s) with the text "(Hidden field
+ # [fieldname]) " prepended. This message is displayed at the top of the
+ # output, regardless of its field's order in the form.
p = Person(
{"first_name": "John", "last_name": "Lennon", "birthday": "1940-10-9"},
auto_id=False,
@@ -2159,7 +2167,8 @@ aria-describedby="id_birthday_error">
)
def test_field_order(self):
- # A Form's fields are displayed in the same order in which they were defined.
+ # A Form's fields are displayed in the same order in which they were
+ # defined.
class TestForm(Form):
field1 = CharField()
field2 = CharField()
@@ -2232,10 +2241,10 @@ aria-describedby="id_birthday_error">
)
def test_form_html_attributes(self):
- # Some Field classes have an effect on the HTML attributes of their associated
- # Widget. If you set max_length in a CharField and its associated widget is
- # either a TextInput or PasswordInput, then the widget's rendered HTML will
- # include the "maxlength" attribute.
+ # Some Field classes have an effect on the HTML attributes of their
+ # associated Widget. If you set max_length in a CharField and its
+ # associated widget is either a TextInput or PasswordInput, then the
+ # widget's rendered HTML will include the "maxlength" attribute.
class UserRegistration(Form):
username = CharField(max_length=10) # uses TextInput by default
password = CharField(max_length=10, widget=PasswordInput)
@@ -2277,9 +2286,10 @@ aria-describedby="id_birthday_error">
)
def test_specifying_labels(self):
- # You can specify the label for a field by using the 'label' argument to a Field
- # class. If you don't specify 'label', Django will use the field name with
- # underscores converted to spaces, and the initial letter capitalized.
+ # You can specify the label for a field by using the 'label' argument
+ # to a Field class. If you don't specify 'label', Django will use the
+ # field name with underscores converted to spaces, and the initial
+ # letter capitalized.
class UserRegistration(Form):
username = CharField(max_length=10, label="Your username")
password1 = CharField(widget=PasswordInput)
@@ -2297,8 +2307,8 @@ aria-describedby="id_birthday_error">
""",
)
- # Labels for as_* methods will only end in a colon if they don't end in other
- # punctuation already.
+ # Labels for as_* methods will only end in a colon if they don't end in
+ # other punctuation already.
class Questions(Form):
q1 = CharField(label="The first question")
q2 = CharField(label="What is your name?")
@@ -2354,8 +2364,8 @@ aria-describedby="id_birthday_error">
""",
)
- # If label is None, Django will auto-create the label from the field name. This
- # is default behavior.
+ # If label is None, Django will auto-create the label from the field
+ # name. This is default behavior.
class UserRegistration(Form):
username = CharField(max_length=10, label=None)
password = CharField(widget=PasswordInput)
@@ -2422,16 +2432,18 @@ aria-describedby="id_birthday_error">
)
def test_initial_data(self):
- # You can specify initial data for a field by using the 'initial' argument to a
- # Field class. This initial data is displayed when a Form is rendered with *no*
- # data. It is not displayed when a Form is rendered with any data (including an
- # empty dictionary). Also, the initial value is *not* used if data for a
- # particular required field isn't provided.
+ # You can specify initial data for a field by using the 'initial'
+ # argument to a Field class. This initial data is displayed when a Form
+ # is rendered with *no* data. It is not displayed when a Form is
+ # rendered with any data (including an empty dictionary). Also, the
+ # initial value is *not* used if data for a particular required field
+ # isn't provided.
class UserRegistration(Form):
username = CharField(max_length=10, initial="django")
password = CharField(widget=PasswordInput)
- # Here, we're not submitting any data, so the initial value will be displayed.)
+ # Here, we're not submitting any data, so the initial value will be
+ # displayed.)
p = UserRegistration(auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -2442,7 +2454,8 @@ aria-describedby="id_birthday_error">
""",
)
- # Here, we're submitting data, so the initial value will *not* be displayed.
+ # Here, we're submitting data, so the initial value will *not* be
+ # displayed.
p = UserRegistration({}, auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -2480,16 +2493,17 @@ Password: <input type="password" name="password" aria-invalid="true" required></
self.assertFalse(p.is_valid())
def test_dynamic_initial_data(self):
- # The previous technique dealt with "hard-coded" initial data, but it's also
- # possible to specify initial data after you've already created the Form class
- # (i.e., at runtime). Use the 'initial' parameter to the Form constructor. This
- # should be a dictionary containing initial values for one or more fields in the
- # form, keyed by field name.
+ # The previous technique dealt with "hard-coded" initial data, but it's
+ # also possible to specify initial data after you've already created
+ # the Form class (i.e., at runtime). Use the 'initial' parameter to the
+ # Form constructor. This should be a dictionary containing initial
+ # values for one or more fields in the form, keyed by field name.
class UserRegistration(Form):
username = CharField(max_length=10)
password = CharField(widget=PasswordInput)
- # Here, we're not submitting any data, so the initial value will be displayed.)
+ # Here, we're not submitting any data, so the initial value will be
+ # displayed.)
p = UserRegistration(initial={"username": "django"}, auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -2542,10 +2556,10 @@ Password: <input type="password" name="password" aria-invalid="true" required></
""",
)
- # A dynamic 'initial' value is *not* used as a fallback if data is not provided.
- # In this example, we don't provide a value for 'username', and the
- # form raises a validation error rather than using the initial value
- # for 'username'.
+ # A dynamic 'initial' value is *not* used as a fallback if data is not
+ # provided. In this example, we don't provide a value for 'username',
+ # and the form raises a validation error rather than using the initial
+ # value for 'username'.
p = UserRegistration({"password": "secret"}, initial={"username": "django"})
self.assertEqual(p.errors["username"], ["This field is required."])
self.assertFalse(p.is_valid())
@@ -2567,8 +2581,8 @@ Password: <input type="password" name="password" aria-invalid="true" required></
)
def test_callable_initial_data(self):
- # The previous technique dealt with raw values as initial data, but it's also
- # possible to specify callable data.
+ # The previous technique dealt with raw values as initial data, but
+ # it's also possible to specify callable data.
class UserRegistration(Form):
username = CharField(max_length=10)
password = CharField(widget=PasswordInput)
@@ -2589,7 +2603,8 @@ Password: <input type="password" name="password" aria-invalid="true" required></
def initial_other_options():
return ["b", "w"]
- # Here, we're not submitting any data, so the initial value will be displayed.)
+ # Here, we're not submitting any data, so the initial value will be
+ # displayed.)
p = UserRegistration(
initial={"username": initial_django, "options": initial_options},
auto_id=False,
@@ -2987,7 +3002,8 @@ Options: <select multiple name="options" aria-invalid="true" required>
'<input type="password" name="password" required></div>',
)
- # The help text is displayed whether or not data is provided for the form.
+ # The help text is displayed whether or not data is provided for the
+ # form.
p = UserRegistration({"username": "foo"}, auto_id=False)
self.assertHTMLEqual(
p.as_ul(),
@@ -2999,8 +3015,8 @@ Options: <select multiple name="options" aria-invalid="true" required>
'required><span class="helptext">Wählen Sie mit Bedacht.</span></li>',
)
- # help_text is not displayed for hidden fields. It can be used for documentation
- # purposes, though.
+ # help_text is not displayed for hidden fields. It can be used for
+ # documentation purposes, though.
class UserRegistration(Form):
username = CharField(max_length=10, help_text="e.g., user@example.com")
password = CharField(widget=PasswordInput)
@@ -3299,9 +3315,9 @@ Options: <select multiple name="options" aria-invalid="true" required>
)
def test_subclassing_forms(self):
- # You can subclass a Form to add fields. The resulting form subclass will have
- # all of the fields of the parent Form, plus whichever fields you define in the
- # subclass.
+ # You can subclass a Form to add fields. The resulting form subclass
+ # will have all of the fields of the parent Form, plus whichever fields
+ # you define in the subclass.
class Person(Form):
first_name = CharField()
last_name = CharField()
@@ -3326,8 +3342,8 @@ Options: <select multiple name="options" aria-invalid="true" required>
<li>Instrument: <input type="text" name="instrument" required></li>""",
)
- # Yes, you can subclass multiple forms. The fields are added in the order in
- # which the parent classes are listed.
+ # Yes, you can subclass multiple forms. The fields are added in the
+ # order in which the parent classes are listed.
class Person(Form):
first_name = CharField()
last_name = CharField()
@@ -3404,8 +3420,8 @@ Options: <select multiple name="options" aria-invalid="true" required>
self.assertEqual(p.cleaned_data["last_name"], "Lennon")
self.assertEqual(p.cleaned_data["birthday"], datetime.date(1940, 10, 9))
- # Let's try submitting some bad data to make sure form.errors and field.errors
- # work as expected.
+ # Let's try submitting some bad data to make sure form.errors and
+ # field.errors work as expected.
data = {
"person1-first_name": "",
"person1-last_name": "",
@@ -3420,16 +3436,16 @@ Options: <select multiple name="options" aria-invalid="true" required>
with self.assertRaises(KeyError):
p["person1-first_name"].errors
- # In this example, the data doesn't have a prefix, but the form requires it, so
- # the form doesn't "see" the fields.
+ # In this example, the data doesn't have a prefix, but the form
+ # requires it, so the form doesn't "see" the fields.
data = {"first_name": "John", "last_name": "Lennon", "birthday": "1940-10-9"}
p = Person(data, prefix="person1")
self.assertEqual(p.errors["first_name"], ["This field is required."])
self.assertEqual(p.errors["last_name"], ["This field is required."])
self.assertEqual(p.errors["birthday"], ["This field is required."])
- # With prefixes, a single data dictionary can hold data for multiple instances
- # of the same form.
+ # With prefixes, a single data dictionary can hold data for multiple
+ # instances of the same form.
data = {
"person1-first_name": "John",
"person1-last_name": "Lennon",
@@ -3449,10 +3465,10 @@ Options: <select multiple name="options" aria-invalid="true" required>
self.assertEqual(p2.cleaned_data["last_name"], "Morrison")
self.assertEqual(p2.cleaned_data["birthday"], datetime.date(1943, 12, 8))
- # By default, forms append a hyphen between the prefix and the field name, but a
- # form can alter that behavior by implementing the add_prefix() method. This
- # method takes a field name and returns the prefixed field, according to
- # self.prefix.
+ # By default, forms append a hyphen between the prefix and the field
+ # name, but a form can alter that behavior by implementing the
+ # add_prefix() method. This method takes a field name and returns the
+ # prefixed field, according to self.prefix.
class Person(Form):
first_name = CharField()
last_name = CharField()
@@ -3504,8 +3520,9 @@ Options: <select multiple name="options" aria-invalid="true" required>
self.assertEqual(p.prefix, "bar")
def test_forms_with_null_boolean(self):
- # NullBooleanField is a bit of a special case because its presentation (widget)
- # is different than its data. This is handled transparently, though.
+ # NullBooleanField is a bit of a special case because its presentation
+ # (widget) is different than its data. This is handled transparently,
+ # though.
class Person(Form):
name = CharField()
is_cool = NullBooleanField()
@@ -3693,9 +3710,9 @@ Options: <select multiple name="options" aria-invalid="true" required>
)
def test_empty_permitted(self):
- # Sometimes (pretty much in formsets) we want to allow a form to pass validation
- # if it is completely empty. We can accomplish this by using the empty_permitted
- # argument to a form constructor.
+ # Sometimes (pretty much in formsets) we want to allow a form to pass
+ # validation if it is completely empty. We can accomplish this by using
+ # the empty_permitted argument to a form constructor.
class SongForm(Form):
artist = CharField()
name = CharField()
@@ -3713,29 +3730,31 @@ Options: <select multiple name="options" aria-invalid="true" required>
)
self.assertEqual(form.cleaned_data, {})
- # Now let's show what happens when empty_permitted=True and the form is empty.
+ # Now let's show what happens when empty_permitted=True and the form is
+ # empty.
form = SongForm(data, empty_permitted=True, use_required_attribute=False)
self.assertTrue(form.is_valid())
self.assertEqual(form.errors, {})
self.assertEqual(form.cleaned_data, {})
- # But if we fill in data for one of the fields, the form is no longer empty and
- # the whole thing must pass validation.
+ # But if we fill in data for one of the fields, the form is no longer
+ # empty and the whole thing must pass validation.
data = {"artist": "The Doors", "song": ""}
form = SongForm(data, empty_permitted=False)
self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {"name": ["This field is required."]})
self.assertEqual(form.cleaned_data, {"artist": "The Doors"})
- # If a field is not given in the data then None is returned for its data. Lets
- # make sure that when checking for empty_permitted that None is treated
- # accordingly.
+ # If a field is not given in the data then None is returned for its
+ # data. Lets make sure that when checking for empty_permitted that None
+ # is treated accordingly.
data = {"artist": None, "song": ""}
form = SongForm(data, empty_permitted=True, use_required_attribute=False)
self.assertTrue(form.is_valid())
- # However, we *really* need to be sure we are checking for None as any data in
- # initial that returns False on a boolean call needs to be treated literally.
+ # However, we *really* need to be sure we are checking for None as any
+ # data in initial that returns False on a boolean call needs to be
+ # treated literally.
class PriceForm(Form):
amount = FloatField()
qty = IntegerField()
@@ -4647,7 +4666,8 @@ aria-describedby="id_age_error"></td></tr>""",
def clean(self):
data = self.cleaned_data
- # Return a different dict. We have not changed self.cleaned_data.
+ # Return a different dict. We have not changed
+ # self.cleaned_data.
return {
"username": data["username"].lower(),
"password": "this_is_not_a_secret",
@@ -4808,7 +4828,8 @@ aria-describedby="id_age_error"></td></tr>""",
)
def test_only_hidden_fields(self):
- # A form with *only* hidden fields that has errors is going to be very unusual.
+ # A form with *only* hidden fields that has errors is going to be very
+ # unusual.
class HiddenForm(Form):
data = IntegerField(widget=HiddenInput)
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index 9f7012a11f..24068e79cb 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -192,8 +192,8 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertIs(formset.empty_form.empty_permitted, True)
def test_formset_validation(self):
- # FormSet instances can also have an error attribute if validation failed for
- # any of the forms.
+ # FormSet instances can also have an error attribute if validation
+ # failed for any of the forms.
formset = self.make_choiceformset([("Calexico", "")])
self.assertFalse(formset.is_valid())
self.assertEqual(formset.errors, [{"votes": ["This field is required."]}])
diff --git a/tests/forms_tests/tests/test_input_formats.py b/tests/forms_tests/tests/test_input_formats.py
index 30ca53ba4b..d1ffc296b1 100644
--- a/tests/forms_tests/tests/test_input_formats.py
+++ b/tests/forms_tests/tests/test_input_formats.py
@@ -65,7 +65,10 @@ class LocalizedTimeTests(SimpleTestCase):
self.assertEqual(text, "13:30:00")
def test_timeField_with_inputformat(self):
- "TimeFields with manually specified input formats can accept those formats"
+ """
+ TimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
# Parse a time in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -172,7 +175,10 @@ class CustomTimeInputFormatsTests(SimpleTestCase):
self.assertEqual(text, "01:30:00 PM")
def test_timeField_with_inputformat(self):
- "TimeFields with manually specified input formats can accept those formats"
+ """
+ TimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
# Parse a time in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -250,7 +256,10 @@ class SimpleTimeFormatTests(SimpleTestCase):
self.assertEqual(text, "13:30:00")
def test_localized_timeField(self):
- "Localized TimeFields in a non-localized environment act as unlocalized widgets"
+ """
+ Localized TimeFields in a non-localized environment act as unlocalized
+ widgets
+ """
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -273,7 +282,10 @@ class SimpleTimeFormatTests(SimpleTestCase):
self.assertEqual(text, "13:30:00")
def test_timeField_with_inputformat(self):
- "TimeFields with manually specified input formats can accept those formats"
+ """
+ TimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"])
# Parse a time in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -378,7 +390,10 @@ class LocalizedDateTests(SimpleTestCase):
self.assertEqual(text, "21.12.2010")
def test_dateField_with_inputformat(self):
- "DateFields with manually specified input formats can accept those formats"
+ """
+ DateFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -489,7 +504,10 @@ class CustomDateInputFormatsTests(SimpleTestCase):
self.assertEqual(text, "21.12.2010")
def test_dateField_with_inputformat(self):
- "DateFields with manually specified input formats can accept those formats"
+ """
+ DateFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -567,7 +585,10 @@ class SimpleDateFormatTests(SimpleTestCase):
self.assertEqual(text, "2010-12-21")
def test_localized_dateField(self):
- "Localized DateFields in a non-localized environment act as unlocalized widgets"
+ """
+ Localized DateFields in a non-localized environment act as unlocalized
+ widgets
+ """
f = forms.DateField()
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -590,7 +611,10 @@ class SimpleDateFormatTests(SimpleTestCase):
self.assertEqual(text, "2010-12-21")
def test_dateField_with_inputformat(self):
- "DateFields with manually specified input formats can accept those formats"
+ """
+ DateFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"])
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -697,7 +721,10 @@ class LocalizedDateTimeTests(SimpleTestCase):
self.assertEqual(text, "21.12.2010 13:30:00")
def test_dateTimeField_with_inputformat(self):
- "DateTimeFields with manually specified input formats can accept those formats"
+ """
+ DateTimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"])
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -814,7 +841,10 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
self.assertEqual(text, "01:30:00 PM 21/12/2010")
def test_dateTimeField_with_inputformat(self):
- "DateTimeFields with manually specified input formats can accept those formats"
+ """
+ DateTimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"])
# Parse a date in an unaccepted format; get an error
with self.assertRaises(ValidationError):
@@ -920,7 +950,10 @@ class SimpleDateTimeFormatTests(SimpleTestCase):
self.assertEqual(text, "2010-12-21 13:30:05")
def test_dateTimeField_with_inputformat(self):
- "DateTimeFields with manually specified input formats can accept those formats"
+ """
+ DateTimeFields with manually specified input formats can accept those
+ formats
+ """
f = forms.DateTimeField(
input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"]
)
diff --git a/tests/forms_tests/tests/test_media.py b/tests/forms_tests/tests/test_media.py
index 9f6b15074c..c1d0c0a568 100644
--- a/tests/forms_tests/tests/test_media.py
+++ b/tests/forms_tests/tests/test_media.py
@@ -193,8 +193,8 @@ class FormsMediaTestCase(SimpleTestCase):
)
def test_combine_media(self):
- # Media objects can be combined. Any given media resource will appear only
- # once. Duplicated media definitions are ignored.
+ # Media objects can be combined. Any given media resource will appear
+ # only once. Duplicated media definitions are ignored.
class MyWidget1(TextInput):
class Media:
css = {"all": ("path/to/css1", "/path/to/css2")}
diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py
index 086627c9e7..866faaac4d 100644
--- a/tests/forms_tests/tests/tests.py
+++ b/tests/forms_tests/tests/tests.py
@@ -79,7 +79,8 @@ class TestTicket14567(TestCase):
self.assertIsInstance(
form.cleaned_data["multi_choice_optional"], models.query.QuerySet
)
- # While we're at it, test whether a QuerySet is returned if there *is* a value.
+ # While we're at it, test whether a QuerySet is returned if there *is*
+ # a value.
self.assertIsInstance(form.cleaned_data["multi_choice"], models.query.QuerySet)
@@ -293,8 +294,8 @@ class FormsModelTestCase(TestCase):
r2 = DefaultsForm()["callable_default"].as_widget()
self.assertNotEqual(r1, r2)
- # In a ModelForm that is passed an instance, the initial values come from the
- # instance's values, not the model's defaults.
+ # In a ModelForm that is passed an instance, the initial values come
+ # from the instance's values, not the model's defaults.
foo_instance = Defaults(
name="instance value", def_date=datetime.date(1969, 4, 4), value=12
)
@@ -370,7 +371,8 @@ class RelatedModelFormTests(SimpleTestCase):
class ManyToManyExclusionTestCase(TestCase):
def test_m2m_field_exclusion(self):
- # Issue 12337. save_instance should honor the passed-in exclude keyword.
+ # Issue 12337. save_instance should honor the passed-in exclude
+ # keyword.
opt1 = ChoiceOptionModel.objects.create(id=1, name="default")
opt2 = ChoiceOptionModel.objects.create(id=2, name="option 2")
opt3 = ChoiceOptionModel.objects.create(id=3, name="option 3")
diff --git a/tests/forms_tests/widget_tests/base.py b/tests/forms_tests/widget_tests/base.py
index c29099abf2..e30b2237c6 100644
--- a/tests/forms_tests/widget_tests/base.py
+++ b/tests/forms_tests/widget_tests/base.py
@@ -29,7 +29,8 @@ class WidgetTest(SimpleTestCase):
)
# Django escapes quotes with '&quot;' while Jinja2 uses '&#34;'.
output = output.replace("&#34;", "&quot;")
- # Django escapes single quotes with '&#x27;' while Jinja2 uses '&#39;'.
+ # Django escapes single quotes with '&#x27;' while Jinja2 uses
+ # '&#39;'.
output = output.replace("&#39;", "&#x27;")
assertEqual(output, html)
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index e0c6fe2db7..1b53dbd8f4 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -197,10 +197,10 @@ class GenericRelationsTests(TestCase):
"""
Test lookups over an object without GenericRelations.
"""
- # Recall that the Mineral class doesn't have an explicit GenericRelation
- # defined. That's OK, because you can create TaggedItems explicitly.
- # However, excluding GenericRelations means your lookups have to be a
- # bit more explicit.
+ # Recall that the Mineral class doesn't have an explicit
+ # GenericRelation defined. That's OK, because you can create
+ # TaggedItems explicitly. However, excluding GenericRelations means
+ # your lookups have to be a bit more explicit.
shiny = TaggedItem.objects.create(content_object=self.quartz, tag="shiny")
clearish = TaggedItem.objects.create(content_object=self.quartz, tag="clearish")
diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py
index c670f44680..f10407b060 100644
--- a/tests/generic_relations_regress/tests.py
+++ b/tests/generic_relations_regress/tests.py
@@ -92,7 +92,8 @@ class GenericRelationTests(TestCase):
CharLink.objects.create(content_object=restaurant)
charlink = CharLink.objects.latest("pk")
self.assertIs(charlink.content_object, charlink.content_object)
- # If the model (Cafe) uses more than one level of multi-table inheritance.
+ # If the model (Cafe) uses more than one level of multi-table
+ # inheritance.
cafe = Cafe.objects.create()
CharLink.objects.create(content_object=cafe)
charlink = CharLink.objects.latest("pk")
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py
index acd938935a..cc5dcf4e39 100644
--- a/tests/generic_views/test_base.py
+++ b/tests/generic_views/test_base.py
@@ -114,7 +114,8 @@ class ViewTest(LoggingAssertionMixin, SimpleTestCase):
def test_get_and_head(self):
"""
- Test a view which supplies a GET method also responds correctly to HEAD.
+ Test a view which supplies a GET method also responds correctly to
+ HEAD.
"""
self._assert_simple(SimpleView.as_view()(self.rf.get("/")))
response = SimpleView.as_view()(self.rf.head("/"))
@@ -129,7 +130,8 @@ class ViewTest(LoggingAssertionMixin, SimpleTestCase):
def test_head_no_get(self):
"""
- Test a view which supplies no GET method responds to HEAD with HTTP 405.
+ Test a view which supplies no GET method responds to HEAD with HTTP
+ 405.
"""
response = PostOnlyView.as_view()(self.rf.head("/"))
self.assertEqual(response.status_code, 405)
@@ -608,7 +610,8 @@ class GetContextDataTest(SimpleTestCase):
self.assertEqual(context["pony"], test_view.object)
def test_object_in_get_context_data(self):
- # Checks 'object' key presence in dict returned by get_context_date #20234
+ # Checks 'object' key presence in dict returned by get_context_date
+ # #20234
test_view = views.CustomSingleObjectView()
context = test_view.get_context_data()
self.assertEqual(context["object"], test_view.object)
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index cfed82a586..140083d315 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -137,7 +137,8 @@ class ArchiveIndexViewTests(TestDataMixin, TestCase):
# 1 query for years list + 1 query for books
with self.assertNumQueries(2):
self.client.get("/dates/books/")
- # same as above + 1 query to test if books exist + 1 query to count them
+ # same as above + 1 query to test if books exist + 1 query to count
+ # them
with self.assertNumQueries(4):
self.client.get("/dates/books/paginated/")
@@ -242,7 +243,8 @@ class YearArchiveViewTests(TestDataMixin, TestCase):
self.assertEqual(list(res.context["date_list"]), [])
self.assertEqual(list(res.context["book_list"]), [])
- # Since allow_empty=True, next/prev are allowed to be empty years (#7164)
+ # Since allow_empty=True, next/prev are allowed to be empty years
+ # (#7164)
self.assertEqual(res.context["next_year"], datetime.date(2000, 1, 1))
self.assertEqual(res.context["previous_year"], datetime.date(1998, 1, 1))
@@ -409,7 +411,8 @@ class MonthArchiveViewTests(TestDataMixin, TestCase):
self.assertEqual(list(res.context["book_list"]), [])
self.assertEqual(res.context["month"], datetime.date(2000, 1, 1))
- # Since allow_empty=True, next/prev are allowed to be empty months (#7164)
+ # Since allow_empty=True, next/prev are allowed to be empty months
+ # (#7164)
self.assertEqual(res.context["next_month"], datetime.date(2000, 2, 1))
self.assertEqual(res.context["previous_month"], datetime.date(1999, 12, 1))
@@ -484,7 +487,8 @@ class MonthArchiveViewTests(TestDataMixin, TestCase):
res = self.client.get("/dates/books/2010/nov/")
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["previous_month"], datetime.date(2010, 10, 1))
- # The bug does not occur here because a Book with pubdate of Sep 1 exists
+ # The bug does not occur here because a Book with pubdate of Sep 1
+ # exists
res = self.client.get("/dates/books/2010/oct/")
self.assertEqual(res.status_code, 200)
self.assertEqual(res.context["previous_month"], datetime.date(2010, 9, 1))
@@ -578,7 +582,8 @@ class WeekArchiveViewTests(TestDataMixin, TestCase):
self.assertIsNone(res.context["next_week"])
def test_week_view_allow_future(self):
- # January 7th always falls in week 1, given Python's definition of week numbers
+ # January 7th always falls in week 1, given Python's definition of week
+ # numbers
future = datetime.date(datetime.date.today().year + 1, 1, 7)
future_sunday = future - datetime.timedelta(days=(future.weekday() + 1) % 7)
b = Book.objects.create(name="The New New Testement", pages=600, pubdate=future)
@@ -696,7 +701,8 @@ class DayArchiveViewTests(TestDataMixin, TestCase):
self.assertEqual(list(res.context["book_list"]), [])
self.assertEqual(res.context["day"], datetime.date(2000, 1, 1))
- # Since it's allow empty, next/prev are allowed to be empty months (#7164)
+ # Since it's allow empty, next/prev are allowed to be empty months
+ # (#7164)
self.assertEqual(res.context["next_day"], datetime.date(2000, 1, 2))
self.assertEqual(res.context["previous_day"], datetime.date(1999, 12, 31))
diff --git a/tests/generic_views/test_list.py b/tests/generic_views/test_list.py
index 25f6553a8a..421609d76d 100644
--- a/tests/generic_views/test_list.py
+++ b/tests/generic_views/test_list.py
@@ -229,7 +229,8 @@ class ListViewTests(TestCase):
# 1 query for authors
with self.assertNumQueries(1):
self.client.get("/list/authors/notempty/")
- # same as above + 1 query to test if authors exist + 1 query for pagination
+ # same as above + 1 query to test if authors exist + 1 query for
+ # pagination
with self.assertNumQueries(3):
self.client.get("/list/authors/notempty/paginated/")
diff --git a/tests/get_earliest_or_latest/tests.py b/tests/get_earliest_or_latest/tests.py
index 21692590cc..49c803b73a 100644
--- a/tests/get_earliest_or_latest/tests.py
+++ b/tests/get_earliest_or_latest/tests.py
@@ -50,8 +50,8 @@ class EarliestOrLatestTests(TestCase):
Article.objects.filter(pub_date__gt=datetime(2005, 7, 26)).earliest(), a2
)
- # Pass a custom field name to earliest() to change the field that's used
- # to determine the earliest object.
+ # Pass a custom field name to earliest() to change the field that's
+ # used to determine the earliest object.
self.assertEqual(Article.objects.earliest("expire_date"), a2)
self.assertEqual(
Article.objects.filter(pub_date__gt=datetime(2005, 7, 26)).earliest(
@@ -143,7 +143,8 @@ class EarliestOrLatestTests(TestCase):
a3,
)
- # latest() overrides any other ordering specified on the query (#11283).
+ # latest() overrides any other ordering specified on the query
+ # (#11283).
self.assertEqual(Article.objects.order_by("id").latest(), a4)
# Error is raised if get_latest_by isn't in Model.Meta.
diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py
index 59f84be221..d4e03d4461 100644
--- a/tests/get_or_create/tests.py
+++ b/tests/get_or_create/tests.py
@@ -125,7 +125,8 @@ class GetOrCreateTests(TestCase):
# Create an Author not tied to any books.
Author.objects.create(name="Ted")
- # There should be three Authors in total. The book object should have two.
+ # There should be three Authors in total. The book object should have
+ # two.
self.assertEqual(Author.objects.count(), 3)
self.assertEqual(book.authors.count(), 2)
@@ -371,9 +372,9 @@ class UpdateOrCreateTests(TestCase):
def test_error_contains_full_traceback(self):
"""
update_or_create should raise IntegrityErrors with the full traceback.
- This is tested by checking that a known method call is in the traceback.
- We cannot use assertRaises/assertRaises here because we need to inspect
- the actual traceback. Refs #16340.
+ This is tested by checking that a known method call is in the
+ traceback. We cannot use assertRaises/assertRaises here because we need
+ to inspect the actual traceback. Refs #16340.
"""
try:
ManualPrimaryKeyTest.objects.update_or_create(id=1, data="Different")
diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py
index f5879beeff..f8eae7ba37 100644
--- a/tests/gis_tests/distapp/tests.py
+++ b/tests/gis_tests/distapp/tests.py
@@ -159,7 +159,7 @@ class DistanceTest(TestCase):
Test distance lookups on geodetic coordinate systems.
"""
# Line is from Canberra to Sydney. Query is for all other cities within
- # a 100km of that line (which should exclude only Hobart & Adelaide).
+ # a 100km of that line (which should exclude only Hobart & # Adelaide).
line = GEOSGeometry("LINESTRING(144.9630 -37.8143,151.2607 -33.8870)", 4326)
dist_qs = AustraliaCity.objects.filter(point__distance_lte=(line, D(km=100)))
expected_cities = [
@@ -221,9 +221,9 @@ class DistanceTest(TestCase):
gq2 = Q(point__distance_gte=(wollongong.point, d2))
qs1 = AustraliaCity.objects.exclude(name="Wollongong").filter(gq1 | gq2)
- # Geodetic distance lookup but telling GeoDjango to use `distance_spheroid`
- # instead (we should get the same results b/c accuracy variance won't matter
- # in this test case).
+ # Geodetic distance lookup but telling GeoDjango to use
+ # `distance_spheroid` instead (we should get the same results b/c
+ # accuracy variance won't matter in this test case).
querysets = [qs1]
if connection.features.has_DistanceSpheroid_function:
gq3 = Q(point__distance_lte=(wollongong.point, d1, "spheroid"))
@@ -532,7 +532,8 @@ class DistanceFunctionsTests(FuncTestMixin, TestCase):
)
for city, distance in zip(qs, distances):
with self.subTest(city=city, distance=distance):
- # Testing equivalence to within a meter (kilometer on SpatiaLite).
+ # Testing equivalence to within a meter (kilometer on
+ # SpatiaLite).
tol = -3 if connection.ops.spatialite else 0
self.assertAlmostEqual(distance, city.distance.m, tol)
@@ -588,7 +589,8 @@ class DistanceFunctionsTests(FuncTestMixin, TestCase):
with self.subTest(c=c):
self.assertAlmostEqual(spheroid_distances[i], c.distance.m, tol)
if connection.ops.postgis or connection.ops.spatialite:
- # PostGIS uses sphere-only distances by default, testing these as well.
+ # PostGIS uses sphere-only distances by default, testing these as
+ # well.
qs = (
AustraliaCity.objects.exclude(id=hillsdale.id)
.annotate(distance=Distance("point", hillsdale.point))
@@ -663,7 +665,8 @@ class DistanceFunctionsTests(FuncTestMixin, TestCase):
@skipUnlessDBFeature("has_Distance_function", "has_Transform_function")
def test_distance_transform(self):
"""
- Test the `Distance` function used with `Transform` on a geographic field.
+ Test the `Distance` function used with `Transform` on a geographic
+ field.
"""
# We'll be using a Polygon (created by buffering the centroid
# of 77005 to 100m) -- which aren't allowed in geographic distance
diff --git a/tests/gis_tests/gdal_tests/test_ds.py b/tests/gis_tests/gdal_tests/test_ds.py
index ca7295be00..5bc71acf3e 100644
--- a/tests/gis_tests/gdal_tests/test_ds.py
+++ b/tests/gis_tests/gdal_tests/test_ds.py
@@ -264,8 +264,8 @@ class DataSourceTest(SimpleTestCase):
# Making sure the fields match to an appropriate OFT type.
for k, v in source.fields.items():
- # Making sure we get the proper OGR Field instance, using
- # a string value index for the feature.
+ # Making sure we get the proper OGR Field instance,
+ # using a string value index for the feature.
self.assertIsInstance(feat[k], v)
self.assertIsInstance(feat.fields[0], str)
diff --git a/tests/gis_tests/gdal_tests/test_envelope.py b/tests/gis_tests/gdal_tests/test_envelope.py
index d55aae168b..03882f7a0a 100644
--- a/tests/gis_tests/gdal_tests/test_envelope.py
+++ b/tests/gis_tests/gdal_tests/test_envelope.py
@@ -64,7 +64,10 @@ class EnvelopeTest(unittest.TestCase):
self.assertEqual((-1, -1, 5, 6), self.e)
def test05_expand_to_include_pt_2_tuple(self):
- "Testing Envelope expand_to_include -- point as a single 2-tuple parameter."
+ """
+ Testing Envelope expand_to_include -- point as a single 2-tuple
+ parameter.
+ """
self.e.expand_to_include((10, 10))
self.assertEqual((0, 0, 10, 10), self.e)
self.e.expand_to_include((-10, -10))
@@ -76,7 +79,10 @@ class EnvelopeTest(unittest.TestCase):
self.assertEqual((-1, 0, 5, 7), self.e)
def test06_expand_to_include_extent_4_tuple(self):
- "Testing Envelope expand_to_include -- extent as a single 4-tuple parameter."
+ """
+ Testing Envelope expand_to_include -- extent as a single 4-tuple
+ parameter.
+ """
self.e.expand_to_include((-1, 1, 3, 7))
self.assertEqual((-1, 0, 5, 7), self.e)
diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py
index 919e547511..6951f2f354 100644
--- a/tests/gis_tests/gdal_tests/test_geom.py
+++ b/tests/gis_tests/gdal_tests/test_geom.py
@@ -521,7 +521,8 @@ class OGRGeomTest(SimpleTestCase, TestDataMixin):
self.assertEqual(3, geom[0].coord_dim)
self.assertEqual(wkt_3d, geom.wkt)
- # Testing binary predicates, `assertIs` is used to check that bool is returned.
+ # Testing binary predicates, `assertIs` is used to check that bool is
+ # returned.
def test_equivalence_regression(self):
"Testing equivalence methods with non-OGRGeometry instances."
diff --git a/tests/gis_tests/gdal_tests/test_raster.py b/tests/gis_tests/gdal_tests/test_raster.py
index a5f1edef0b..2c2b77d5cd 100644
--- a/tests/gis_tests/gdal_tests/test_raster.py
+++ b/tests/gis_tests/gdal_tests/test_raster.py
@@ -334,7 +334,8 @@ class GDALRasterTests(SimpleTestCase):
result = rast.bands[0].data()
if numpy:
result = result.flatten().tolist()
- # Band data is equal to zero because no nodata value has been specified.
+ # Band data is equal to zero because no nodata value has been
+ # specified.
self.assertEqual(result, [0] * 4)
def test_raster_metadata_property(self):
@@ -556,7 +557,8 @@ class GDALRasterTests(SimpleTestCase):
],
}
)
- # Warp raster onto a location that does not cover any pixels of the original.
+ # Warp raster onto a location that does not cover any pixels of the
+ # original.
result = source.warp({"origin": (200000, 200000)}).bands[0].data()
if numpy:
result = result.flatten().tolist()
@@ -828,7 +830,8 @@ class GDALBandTests(SimpleTestCase):
band = rs.bands[0]
self.addCleanup(self._remove_aux_file)
- # Setting attributes in write mode raises exception in the _flush method
+ # Setting attributes in write mode raises exception in the _flush
+ # method
with self.assertRaises(GDALException):
setattr(band, "nodata_value", 10)
diff --git a/tests/gis_tests/gdal_tests/test_srs.py b/tests/gis_tests/gdal_tests/test_srs.py
index 62ebc63889..20ad834338 100644
--- a/tests/gis_tests/gdal_tests/test_srs.py
+++ b/tests/gis_tests/gdal_tests/test_srs.py
@@ -110,7 +110,8 @@ srlist = (
(("projcs", 11), "AXIS"),
),
),
- # This is really ESRI format, not WKT -- but the import should work the same
+ # This is really ESRI format, not WKT -- but the import should work the
+ # same
TestSRS(
'LOCAL_CS["Non-Earth (Meter)",LOCAL_DATUM["Local Datum",32767],'
'UNIT["Meter",1],AXIS["X",EAST],AXIS["Y",NORTH]]',
diff --git a/tests/gis_tests/geo3d/tests.py b/tests/gis_tests/geo3d/tests.py
index 7b7e6fea5a..6871a7ba93 100644
--- a/tests/gis_tests/geo3d/tests.py
+++ b/tests/gis_tests/geo3d/tests.py
@@ -226,7 +226,8 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase):
ref_union = GEOSGeometry(ref_ewkt)
union = City3D.objects.aggregate(Union("point"))["point__union"]
self.assertTrue(union.hasz)
- # Ordering of points in the resulting geometry may vary between implementations
+ # Ordering of points in the resulting geometry may vary between
+ # implementations
self.assertEqual({p.ewkt for p in ref_union}, {p.ewkt for p in union})
@skipUnlessDBFeature("supports_3d_functions")
diff --git a/tests/gis_tests/geoapp/test_feeds.py b/tests/gis_tests/geoapp/test_feeds.py
index e247d88535..b927571a29 100644
--- a/tests/gis_tests/geoapp/test_feeds.py
+++ b/tests/gis_tests/geoapp/test_feeds.py
@@ -98,7 +98,8 @@ class GeoFeedTest(TestCase):
items = chan.getElementsByTagName("item")
self.assertEqual(len(items), City.objects.count())
- # Ensuring the geo:lat and geo:lon element was added to each item in the feed.
+ # Ensuring the geo:lat and geo:lon element was added to each item in
+ # the feed.
for item in items:
self.assertChildNodes(
item, ["title", "link", "description", "guid", "geo:lat", "geo:lon"]
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index 047d6948b1..70c462a78e 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -210,8 +210,8 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
# SELECT AsSVG(geoapp_city.point, 0, 8) FROM geoapp_city
# WHERE name = 'Pueblo';
svg1 = 'cx="-104.609252" cy="-38.255001"'
- # Even though relative, only one point so it's practically the same except for
- # the 'c' letter prefix on the x,y values.
+ # Even though relative, only one point so it's practically the same
+ # except for the 'c' letter prefix on the x,y values.
svg2 = svg1.replace("c", "")
self.assertEqual(
svg1,
@@ -463,7 +463,8 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
@skipUnlessDBFeature("has_Area_function")
def test_area_with_regular_aggregate(self):
- # Create projected country objects, for this test to work on all backends.
+ # Create projected country objects, for this test to work on all
+ # backends.
for c in Country.objects.all():
CountryWebMercator.objects.create(
name=c.name, mpoly=c.mpoly.transform(3857, clone=True)
@@ -684,7 +685,8 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
@skipUnlessDBFeature("has_SnapToGrid_function")
def test_snap_to_grid(self):
- # Let's try and break snap_to_grid() with bad combinations of arguments.
+ # Let's try and break snap_to_grid() with bad combinations of
+ # arguments.
for bad_args in ((), range(3), range(5)):
with self.assertRaises(ValueError):
Country.objects.annotate(snap=functions.SnapToGrid("mpoly", *bad_args))
@@ -692,8 +694,8 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
with self.assertRaises(TypeError):
Country.objects.annotate(snap=functions.SnapToGrid("mpoly", *bad_args))
- # Boundary for San Marino, courtesy of Bjorn Sandvik of thematicmapping.org
- # from the world borders dataset he provides.
+ # Boundary for San Marino, courtesy of Bjorn Sandvik of
+ # thematicmapping.org from the world borders dataset he provides.
wkt = (
"MULTIPOLYGON(((12.41580 43.95795,12.45055 43.97972,12.45389 43.98167,"
"12.46250 43.98472,12.47167 43.98694,12.49278 43.98917,"
@@ -817,9 +819,9 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
)
if connection.ops.oracle:
- # Should be able to execute the queries; however, they won't be the same
- # as GEOS (because Oracle doesn't use GEOS internally like PostGIS or
- # SpatiaLite).
+ # Should be able to execute the queries; however, they won't be the
+ # same as GEOS (because Oracle doesn't use GEOS internally like
+ # PostGIS or SpatiaLite).
return
for c in qs:
self.assertTrue(c.mpoly.difference(geom).equals(c.difference))
diff --git a/tests/gis_tests/geoapp/test_regress.py b/tests/gis_tests/geoapp/test_regress.py
index 9a9226f341..8ac0ed3049 100644
--- a/tests/gis_tests/geoapp/test_regress.py
+++ b/tests/gis_tests/geoapp/test_regress.py
@@ -67,7 +67,10 @@ class GeoRegressionTests(TestCase):
)
def test_empty_count(self):
- "Testing that PostGISAdapter.__eq__ does check empty strings. See #13670."
+ """
+ Testing that PostGISAdapter.__eq__ does check empty strings. See
+ #13670.
+ """
# contrived example, but need a geo lookup paired with an id__in lookup
pueblo = City.objects.get(name="Pueblo")
state = State.objects.filter(poly__contains=pueblo.point)
@@ -78,7 +81,10 @@ class GeoRegressionTests(TestCase):
@skipUnlessDBFeature("allows_group_by_lob")
def test_defer_or_only_with_annotate(self):
- "Regression for #16409. Make sure defer() and only() work with annotate()"
+ """
+ Regression for #16409. Make sure defer() and only() work with
+ annotate()
+ """
self.assertIsInstance(
list(City.objects.annotate(Count("point")).defer("name")), list
)
@@ -87,7 +93,9 @@ class GeoRegressionTests(TestCase):
)
def test_boolean_conversion(self):
- "Testing Boolean value conversion with the spatial backend, see #15169."
+ """
+ Testing Boolean value conversion with the spatial backend, see #15169.
+ """
t1 = Truth.objects.create(val=True)
t2 = Truth.objects.create(val=False)
diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py
index 395043e832..84138eb431 100644
--- a/tests/gis_tests/geoapp/tests.py
+++ b/tests/gis_tests/geoapp/tests.py
@@ -367,14 +367,15 @@ class GeoLookupTest(TestCase):
"Testing the 'left' and 'right' lookup types."
# Left: A << B => true if xmax(A) < xmin(B)
# Right: A >> B => true if xmin(A) > xmax(B)
- # See: BOX2D_left() and BOX2D_right() in lwgeom_box2dfloat4.c in PostGIS source.
+ # See: BOX2D_left() and BOX2D_right() in lwgeom_box2dfloat4.c in
+ # PostGIS source.
# Getting the borders for Colorado & Kansas
co_border = State.objects.get(name="Colorado").poly
ks_border = State.objects.get(name="Kansas").poly
- # Note: Wellington has an 'X' value of 174, so it will not be considered
- # to the left of CO.
+ # Note: Wellington has an 'X' value of 174, so it will not be
+ # considered to the left of CO.
# These cities should be strictly to the right of the CO border.
cities = [
@@ -397,7 +398,8 @@ class GeoLookupTest(TestCase):
for c in qs:
self.assertIn(c.name, cities)
- # Note: Wellington has an 'X' value of 174, so it will not be considered
+ # Note: Wellington has an 'X' value of 174, so it will not be
+ # considered
# to the left of CO.
vic = City.objects.get(point__left=co_border)
self.assertEqual("Victoria", vic.name)
@@ -441,7 +443,8 @@ class GeoLookupTest(TestCase):
nullqs = State.objects.filter(poly__isnull=True)
validqs = State.objects.filter(poly__isnull=False)
- # Puerto Rico should be NULL (it's a commonwealth unincorporated territory)
+ # Puerto Rico should be NULL (it's a commonwealth unincorporated
+ # territory)
self.assertEqual(1, len(nullqs))
self.assertEqual("Puerto Rico", nullqs[0].name)
# GeometryField=None is an alias for __isnull=True.
@@ -535,8 +538,8 @@ class GeoLookupTest(TestCase):
@skipUnlessDBFeature("supports_relate_lookup")
def test_relate_lookup(self):
"Testing the 'relate' lookup type."
- # To make things more interesting, we will have our Texas reference point in
- # different SRIDs.
+ # To make things more interesting, we will have our Texas reference
+ # point in different SRIDs.
pnt1 = fromstr("POINT (649287.0363174 4177429.4494686)", srid=2847)
pnt2 = fromstr("POINT(-98.4919715741052 29.4333344025053)", srid=4326)
@@ -653,7 +656,8 @@ class GeoQuerySetTest(TestCase):
# SELECT ST_extent(point)
# FROM geoapp_city
# WHERE (name='Houston' or name='Dallas');`
- # => BOX(-96.8016128540039 29.7633724212646,-95.3631439208984 32.7820587158203)
+ # => BOX(-96.8016128540039 29.7633724212646,-95.3631439208984
+ # 32.7820587158203)
expected = (
-96.8016128540039,
29.7633724212646,
@@ -710,7 +714,8 @@ class GeoQuerySetTest(TestCase):
Testing the `Union` aggregate.
"""
tx = Country.objects.get(name="Texas").mpoly
- # Houston, Dallas -- Ordering may differ depending on backend or GEOS version.
+ # Houston, Dallas -- Ordering may differ depending on backend or GEOS
+ # version.
union = GEOSGeometry("MULTIPOINT(-96.801611 32.782057,-95.363151 29.763374)")
qs = City.objects.filter(point__within=tx)
with self.assertRaises(ValueError):
diff --git a/tests/gis_tests/geogapp/tests.py b/tests/gis_tests/geogapp/tests.py
index cb783b9465..229ce88586 100644
--- a/tests/gis_tests/geogapp/tests.py
+++ b/tests/gis_tests/geogapp/tests.py
@@ -147,8 +147,8 @@ class GeographyFunctionTests(FuncTestMixin, TestCase):
ref_dists = [0, 4899.68, 8081.30, 9115.15]
elif connection.ops.spatialite:
if connection.ops.spatial_version < (5,):
- # SpatiaLite < 5 returns non-zero distance for polygons and points
- # covered by that polygon.
+ # SpatiaLite < 5 returns non-zero distance for polygons and
+ # points covered by that polygon.
ref_dists = [326.61, 4899.68, 8081.30, 9115.15]
else:
ref_dists = [0, 4899.68, 8081.30, 9115.15]
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index ac67d6ccad..5ec997556b 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -280,7 +280,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
("POINT EMPTY", "LINESTRING EMPTY", False),
# Empty inputs of different dimensions are not equals_identical.
("POINT EMPTY", "POINT Z EMPTY", False),
- # Non-empty inputs of different dimensions are not equals_identical.
+ # Non-empty inputs of different dimensions are not
+ # equals_identical.
("POINT Z (1 2 3)", "POINT M (1 2 3)", False),
("POINT ZM (1 2 3 4)", "POINT Z (1 2 3)", False),
# Inputs with different structure are not equals_identical.
@@ -371,7 +372,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(pnt, fromstr(p.wkt))
self.assertIs(pnt == prev, False) # Use assertIs() to test __eq__.
- # Making sure that the point's X, Y components are what we expect
+ # Making sure that the point's X, Y components are what we
+ # expect
self.assertAlmostEqual(p.x, pnt.tuple[0], 9)
self.assertAlmostEqual(p.y, pnt.tuple[1], 9)
@@ -753,12 +755,14 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
# These tests are needed to ensure sanity with writable geometries.
- # Getting a polygon with interior rings, and pulling out the interior rings
+ # Getting a polygon with interior rings, and pulling out the interior
+ # rings
poly = fromstr(self.geometries.polygons[1].wkt)
ring1 = poly[0]
ring2 = poly[1]
- # These deletes should be 'harmless' since they are done on child geometries
+ # These deletes should be 'harmless' since they are done on child
+ # geometries
del ring1
del ring2
ring1 = poly[0]
@@ -776,7 +780,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
for p in self.geometries.polygons:
with self.subTest(p=p):
if p.ext_ring_cs:
- # Constructing the polygon and getting the coordinate sequence
+ # Constructing the polygon and getting the coordinate
+ # sequence
poly = fromstr(p.wkt)
cs = poly.exterior_ring.coord_seq
@@ -791,7 +796,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
for expected_value, coord_sequence in zip(p.ext_ring_cs, cs):
self.assertEqual(expected_value, coord_sequence)
- # Construct the test value to set the coordinate sequence with
+ # Construct the test value to set the coordinate
+ # sequence with
if len(expected_value) == 2:
tset = (5, 23)
else:
@@ -956,8 +962,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
# Now assuring that each point in the buffer is almost equal
for exp_ring, buf_ring in zip(exp_buf, buf, strict=True):
for exp_point, buf_point in zip(exp_ring, buf_ring, strict=True):
- # Asserting the X, Y of each point are almost equal (due to
- # floating point imprecision).
+ # Asserting the X, Y of each point are almost equal
+ # (due to floating point imprecision).
self.assertAlmostEqual(exp_point[0], buf_point[0], 9)
self.assertAlmostEqual(exp_point[1], buf_point[1], 9)
@@ -1064,11 +1070,13 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
"initialize to LinearRings"
)
with self.subTest(p=p):
- # Should only be able to use __setitem__ with LinearRing geometries.
+ # Should only be able to use __setitem__ with LinearRing
+ # geometries.
with self.assertRaisesMessage(TypeError, msg):
poly.__setitem__(0, LineString((1, 1), (2, 2)))
- # Construct the new shell by adding 500 to every point in the old shell.
+ # Construct the new shell by adding 500 to every point in the
+ # old shell.
shell_tup = poly.shell.tuple
new_coords = []
for point in shell_tup:
@@ -1615,8 +1623,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
def test_subclassing(self):
"""
- GEOSGeometry subclass may itself be subclassed without being forced-cast
- to the parent class during `__init__`.
+ GEOSGeometry subclass may itself be subclassed without being
+ forced-cast to the parent class during `__init__`.
"""
class ExtendedPolygon(Polygon):
@@ -1629,7 +1637,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
ext_poly = ExtendedPolygon(((0, 0), (0, 1), (1, 1), (0, 0)), data=3)
self.assertEqual(type(ext_poly), ExtendedPolygon)
- # ExtendedPolygon.__str__ should be called (instead of Polygon.__str__).
+ # ExtendedPolygon.__str__ should be called (instead of
+ # Polygon.__str__).
self.assertEqual(
str(ext_poly), "EXT_POLYGON - data: 3 - POLYGON ((0 0, 0 1, 1 1, 0 0))"
)
diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py
index ca5d5214dd..00a3507b59 100644
--- a/tests/gis_tests/inspectapp/tests.py
+++ b/tests/gis_tests/inspectapp/tests.py
@@ -118,8 +118,8 @@ class OGRInspectTest(SimpleTestCase):
self.skipTest("Unable to setup an OGR connection to your database")
try:
- # Writing shapefiles via GDAL currently does not support writing OGRTime
- # fields, so we need to actually use a database
+ # Writing shapefiles via GDAL currently does not support writing
+ # OGRTime fields, so we need to actually use a database
model_def = ogrinspect(
ogr_db,
"Measurement",
@@ -143,7 +143,8 @@ class OGRInspectTest(SimpleTestCase):
# The ordering of model fields might vary depending on several factors
# (version of GDAL, etc.).
if connection.vendor == "sqlite" and GDAL_VERSION < (3, 4):
- # SpatiaLite introspection is somewhat lacking on GDAL < 3.4 (#29461).
+ # SpatiaLite introspection is somewhat lacking on GDAL < 3.4
+ # (#29461).
self.assertIn(" f_decimal = models.CharField(max_length=0)", model_def)
else:
self.assertIn(
@@ -205,8 +206,8 @@ def get_ogr_db_string():
"""
db = connections.settings["default"]
- # Map from the django backend into the OGR driver name and database identifier
- # https://gdal.org/drivers/vector/
+ # Map from the django backend into the OGR driver name and database
+ # identifier https://gdal.org/drivers/vector/
#
# TODO: Support Oracle (OCI).
drivers = {
diff --git a/tests/gis_tests/layermap/tests.py b/tests/gis_tests/layermap/tests.py
index c5ed84d39c..c590defbd0 100644
--- a/tests/gis_tests/layermap/tests.py
+++ b/tests/gis_tests/layermap/tests.py
@@ -130,7 +130,8 @@ class LayerMapTest(TestCase):
self.assertEqual(Decimal(str(feat["Length"])), istate.length)
elif feat.fid == 1:
# Everything but the first two decimal digits were truncated,
- # because the Interstate model's `length` field has decimal_places=2.
+ # because the Interstate model's `length` field has
+ # decimal_places=2.
self.assertAlmostEqual(feat.get("Length"), float(istate.length), 2)
for p1, p2 in zip(feat.geom, istate.path):
@@ -138,7 +139,9 @@ class LayerMapTest(TestCase):
self.assertAlmostEqual(p1[1], p2[1], 6)
def county_helper(self, county_feat=True):
- "Helper function for ensuring the integrity of the mapped County models."
+ """
+ Helper function for ensuring the integrity of the mapped County models.
+ """
for name, n, st in zip(NAMES, NUMS, STATES):
# Should only be one record b/c of `unique` keyword.
c = County.objects.get(name=name)
@@ -157,10 +160,12 @@ class LayerMapTest(TestCase):
"""
# All the following should work.
- # Telling LayerMapping that we want no transformations performed on the data.
+ # Telling LayerMapping that we want no transformations performed on the
+ # data.
lm = LayerMapping(County, co_shp, co_mapping, transform=False)
- # Specifying the source spatial reference system via the `source_srs` keyword.
+ # Specifying the source spatial reference system via the `source_srs`
+ # keyword.
lm = LayerMapping(County, co_shp, co_mapping, source_srs=4269)
lm = LayerMapping(County, co_shp, co_mapping, source_srs="NAD83")
@@ -179,13 +184,14 @@ class LayerMapTest(TestCase):
with self.assertRaises(e):
LayerMapping(County, co_shp, co_mapping, transform=False, unique=arg)
- # No source reference system defined in the shapefile, should raise an error.
+ # No source reference system defined in the shapefile, should raise an
+ # error.
if connection.features.supports_transform:
with self.assertRaises(LayerMapError):
LayerMapping(County, co_shp, co_mapping)
- # Passing in invalid ForeignKey mapping parameters -- must be a dictionary
- # mapping for the model the ForeignKey points to.
+ # Passing in invalid ForeignKey mapping parameters -- must be a
+ # dictionary mapping for the model the ForeignKey points to.
bad_fk_map1 = copy(co_mapping)
bad_fk_map1["state"] = "name"
bad_fk_map2 = copy(co_mapping)
@@ -195,9 +201,9 @@ class LayerMapTest(TestCase):
with self.assertRaises(LayerMapError):
LayerMapping(County, co_shp, bad_fk_map2, transform=False)
- # There exist no State models for the ForeignKey mapping to work -- should raise
- # a MissingForeignKey exception (this error would be ignored if the `strict`
- # keyword is not set).
+ # There exist no State models for the ForeignKey mapping to work --
+ # should raise a MissingForeignKey exception (this error would be
+ # ignored if the `strict` keyword is not set).
lm = LayerMapping(County, co_shp, co_mapping, transform=False, unique="name")
with self.assertRaises(MissingForeignKey):
lm.save(silent=True, strict=True)
@@ -208,12 +214,13 @@ class LayerMapTest(TestCase):
)
# If a mapping is specified as a collection, all OGR fields that
- # are not collections will be converted into them. For example,
- # a Point column would be converted to MultiPoint. Other things being done
+ # are not collections will be converted into them. For example, a Point
+ # column would be converted to MultiPoint. Other things being done
# w/the keyword args:
# `transform=False`: Specifies that no transform is to be done; this
- # has the effect of ignoring the spatial reference check (because the
- # county shapefile does not have implicit spatial reference info).
+ # has the effect of ignoring the spatial reference check (because
+ # the county shapefile does not have implicit spatial reference
+ # info).
#
# `unique='name'`: Creates models on the condition that they have
# unique county names; geometries from each feature however will be
@@ -223,8 +230,8 @@ class LayerMapTest(TestCase):
lm = LayerMapping(County, co_shp, co_mapping, transform=False, unique="name")
lm.save(silent=True, strict=True)
- # A reference that doesn't use the unique keyword; a new database record will
- # created for each polygon.
+ # A reference that doesn't use the unique keyword; a new database
+ # record will created for each polygon.
lm = LayerMapping(CountyFeat, co_shp, cofeat_mapping, transform=False)
lm.save(silent=True, strict=True)
diff --git a/tests/gis_tests/relatedapp/tests.py b/tests/gis_tests/relatedapp/tests.py
index 86d7488341..34dc2bba15 100644
--- a/tests/gis_tests/relatedapp/tests.py
+++ b/tests/gis_tests/relatedapp/tests.py
@@ -51,7 +51,8 @@ class RelatedGeoModelTest(TestCase):
e3 = aggs["location__point__extent"]
# The tolerance value is to four decimal places because of differences
- # between the Oracle and PostGIS spatial backends on the extent calculation.
+ # between the Oracle and PostGIS spatial backends on the extent
+ # calculation.
tol = 4
for ref, e in [(all_extent, e1), (txpa_extent, e2), (all_extent, e3)]:
for ref_val, e_val in zip(ref, e):
@@ -85,8 +86,8 @@ class RelatedGeoModelTest(TestCase):
p5 = Point(-95.363151, 29.763374)
# The second union aggregate is for a union
- # query that includes limiting information in the WHERE clause (in other
- # words a `.filter()` precedes the call to `.aggregate(Union()`).
+ # query that includes limiting information in the WHERE clause (in
+ # other words a `.filter()` precedes the call to `.aggregate(Union()`).
ref_u1 = MultiPoint(p1, p2, p4, p5, p3, srid=4326)
ref_u2 = MultiPoint(p2, p3, srid=4326)
@@ -187,8 +188,8 @@ class RelatedGeoModelTest(TestCase):
# Incrementing through each of the models, dictionaries, and tuples
# returned by each QuerySet.
for m, d, t in zip(gqs, gvqs, gvlqs):
- # The values should be Geometry objects and not raw strings returned
- # by the spatial database.
+ # The values should be Geometry objects and not raw strings
+ # returned by the spatial database.
self.assertIsInstance(d["point"], GEOSGeometry)
self.assertIsInstance(t[1], GEOSGeometry)
self.assertEqual(m.point, d["point"])
@@ -208,7 +209,10 @@ class RelatedGeoModelTest(TestCase):
self.assertEqual(loc.point, def_loc.point)
def test09_pk_relations(self):
- "Ensuring correct primary key column is selected across relations. See #10757."
+ """
+ Ensuring correct primary key column is selected across relations. See
+ #10757.
+ """
# The expected ID values -- notice the last two location IDs
# are out of order. Dallas and Houston have location IDs that differ
# from their PKs -- this is done to ensure that the related location
@@ -426,13 +430,16 @@ class RelatedGeoModelTest(TestCase):
select_related on the related name manager of a unique FK.
"""
qs = Article.objects.select_related("author__article")
- # This triggers TypeError when `get_default_columns` has no `local_only`
- # keyword. The TypeError is swallowed if QuerySet is actually
- # evaluated as list generation swallows TypeError in CPython.
+ # This triggers TypeError when `get_default_columns` has no
+ # `local_only` keyword. The TypeError is swallowed if QuerySet is
+ # actually evaluated as list generation swallows TypeError in CPython.
str(qs.query)
def test16_annotated_date_queryset(self):
- "Ensure annotated date querysets work if spatial backend is used. See #14648."
+ """
+ Ensure annotated date querysets work if spatial backend is used. See
+ #14648.
+ """
birth_years = [
dt.year
for dt in list(
diff --git a/tests/gis_tests/test_geoforms.py b/tests/gis_tests/test_geoforms.py
index 23f94edd0e..2a1f585906 100644
--- a/tests/gis_tests/test_geoforms.py
+++ b/tests/gis_tests/test_geoforms.py
@@ -34,7 +34,8 @@ class GeometryFieldTest(SimpleTestCase):
xform_geom = GEOSGeometry(
"POINT (951640.547328465 4219369.26171664)", srid=32140
)
- # The cleaned geometry is transformed to 32140 (the widget map_srid is 3857).
+ # The cleaned geometry is transformed to 32140 (the widget map_srid is
+ # 3857).
cleaned_geom = fld.clean(
"SRID=3857;POINT (-10615777.40976205 3473169.895707852)"
)
@@ -73,7 +74,8 @@ class GeometryFieldTest(SimpleTestCase):
GEOSGeometry("POINT(5 23)", srid=pnt_fld.widget.map_srid),
pnt_fld.clean("POINT(5 23)"),
)
- # a WKT for any other geom_type will be properly transformed by `to_python`
+ # a WKT for any other geom_type will be properly transformed by
+ # `to_python`
self.assertEqual(
GEOSGeometry("LINESTRING(0 0, 1 1)", srid=pnt_fld.widget.map_srid),
pnt_fld.to_python("LINESTRING(0 0, 1 1)"),
diff --git a/tests/gis_tests/test_ptr.py b/tests/gis_tests/test_ptr.py
index a09679f5b9..cfe58ae1a8 100644
--- a/tests/gis_tests/test_ptr.py
+++ b/tests/gis_tests/test_ptr.py
@@ -37,9 +37,9 @@ class CPointerBaseTests(SimpleTestCase):
fg.ptr
# Anything that's either not None or the acceptable pointer type
- # results in a TypeError when trying to assign it to the `ptr` property.
- # Thus, memory addresses (integers) and pointers of the incorrect type
- # (in `bad_ptrs`) aren't allowed.
+ # results in a TypeError when trying to assign it to the `ptr`
+ # property. Thus, memory addresses (integers) and pointers of the
+ # incorrect type (in `bad_ptrs`) aren't allowed.
bad_ptrs = (5, ctypes.c_char_p(b"foobar"))
for bad_ptr in bad_ptrs:
for fg in (fg1, fg2):
diff --git a/tests/gis_tests/test_spatialrefsys.py b/tests/gis_tests/test_spatialrefsys.py
index d936ac8c89..e49db86d50 100644
--- a/tests/gis_tests/test_spatialrefsys.py
+++ b/tests/gis_tests/test_spatialrefsys.py
@@ -10,7 +10,8 @@ test_srs = (
"srid": 4326,
"auth_name": ("EPSG", True),
"auth_srid": 4326,
- # Only the beginning, because there are differences depending on installed libs
+ # Only the beginning, because there are differences depending on
+ # installed libs
"srtext": 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"',
"proj_re": (
r"\+proj=longlat (\+datum=WGS84 |\+towgs84=0,0,0,0,0,0,0 )\+no_defs ?"
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index e73fc15195..83dfd95713 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -58,7 +58,9 @@ class HandlerTests(SimpleTestCase):
self.assertEqual(got, ["café", "café", "caf\ufffd", "café"])
def test_non_ascii_cookie(self):
- """Non-ASCII cookies set in JavaScript are properly decoded (#20557)."""
+ """
+ Non-ASCII cookies set in JavaScript are properly decoded (#20557).
+ """
environ = self.request_factory.get("/").environ
raw_cookie = 'want="café"'.encode("utf-8").decode("iso-8859-1")
environ["HTTP_COOKIE"] = raw_cookie
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index f85d33e823..f1caec6b71 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -320,8 +320,8 @@ class HttpResponseTests(SimpleTestCase):
self.assertEqual(r.headers["key"], "=?utf-8?b?4oCg?=")
self.assertIn(b"=?utf-8?b?4oCg?=", r.serialize_headers())
- # The response also converts string or bytes keys to strings, but requires
- # them to contain ASCII
+ # The response also converts string or bytes keys to strings, but
+ # requires them to contain ASCII
r = HttpResponse()
del r.headers["Content-Type"]
r.headers["foo"] = "bar"
@@ -350,8 +350,8 @@ class HttpResponseTests(SimpleTestCase):
f = b"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz a\xcc\x88"
f = f.decode("utf-8")
h.headers["Content-Disposition"] = 'attachment; filename="%s"' % f
- # This one is triggering https://bugs.python.org/issue20747, that is Python
- # will itself insert a newline in the header
+ # This one is triggering https://bugs.python.org/issue20747, that is
+ # Python will itself insert a newline in the header
h.headers["Content-Disposition"] = (
'attachment; filename="EdelRot_Blu\u0308te (3)-0.JPG"'
)
diff --git a/tests/humanize_tests/tests.py b/tests/humanize_tests/tests.py
index 7a44c6d89b..b9f1e58ef7 100644
--- a/tests/humanize_tests/tests.py
+++ b/tests/humanize_tests/tests.py
@@ -610,8 +610,8 @@ class HumanizeTests(SimpleTestCase):
def test_inflection_for_timedelta(self):
"""
- Translation of '%d day'/'%d month'/… may differ depending on the context
- of the string it is inserted in.
+ Translation of '%d day'/'%d month'/… may differ depending on the
+ context of the string it is inserted in.
"""
test_list = [
# "%(delta)s ago" translations
diff --git a/tests/i18n/sampleproject/update_catalogs.py b/tests/i18n/sampleproject/update_catalogs.py
index 8780f629e4..af8953c312 100755
--- a/tests/i18n/sampleproject/update_catalogs.py
+++ b/tests/i18n/sampleproject/update_catalogs.py
@@ -13,7 +13,8 @@ blocktranslate. This issue is difficult to debug, it could be a problem with
extraction, interpolation, or both.
How this script helps:
- * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to templates.
+ * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to
+ templates.
* Run this script.
* Test extraction - verify the new msgid in sampleproject's django.po.
* Add a translation to sampleproject's django.po.
diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py
index 3a57dbf076..e99e3e4acc 100644
--- a/tests/i18n/test_compilation.py
+++ b/tests/i18n/test_compilation.py
@@ -199,18 +199,18 @@ class IgnoreDirectoryCompilationTests(MessageCompilationTests):
def test_no_dirs_accidentally_skipped(self):
os_walk_results = [
- # To discover .po filepaths, compilemessages uses with a starting list of
- # basedirs to inspect, which in this scenario are:
+ # To discover .po filepaths, compilemessages uses with a starting
+ # list of basedirs to inspect, which in this scenario are:
# ["conf/locale", "locale"]
- # Then os.walk is used to discover other locale dirs, ignoring dirs matching
- # `ignore_patterns`. Mock the results to place an ignored directory directly
- # before and after a directory named "locale".
+ # Then os.walk is used to discover other locale dirs, ignoring dirs
+ # matching `ignore_patterns`. Mock the results to place an ignored
+ # directory directly before and after a directory named "locale".
[("somedir", ["ignore", "locale", "ignore"], [])],
# This will result in three basedirs discovered:
# ["conf/locale", "locale", "somedir/locale"]
- # os.walk is called for each locale in each basedir looking for .po files.
- # In this scenario, we need to mock os.walk results for "en", "fr", and "it"
- # locales for each basedir:
+ # os.walk is called for each locale in each basedir looking for .po
+ # files. In this scenario, we need to mock os.walk results for
+ # "en", "fr", and "it" locales for each basedir:
[("exclude/locale/LC_MESSAGES", [], ["en.po"])],
[("exclude/locale/LC_MESSAGES", [], ["fr.po"])],
[("exclude/locale/LC_MESSAGES", [], ["it.po"])],
@@ -277,8 +277,9 @@ class CompilationErrorHandling(MessageCompilationTests):
call_command("compilemessages", locale=["ja"], verbosity=0)
def test_msgfmt_error_including_non_ascii(self):
- # po file contains invalid msgstr content (triggers non-ascii error content).
- # Make sure the output of msgfmt is unaffected by the current locale.
+ # po file contains invalid msgstr content (triggers non-ascii error
+ # content). Make sure the output of msgfmt is unaffected by the current
+ # locale.
env = os.environ.copy()
env.update({"LC_ALL": "C"})
with mock.patch(
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index e4a6260c33..b02b24ab5b 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -101,7 +101,8 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
def assertLocationCommentPresent(self, po_filename, line_number, *comment_parts):
r"""
- self.assertLocationCommentPresent('django.po', 42, 'dirA', 'dirB', 'foo.py')
+ self.assertLocationCommentPresent('django.po', 42, 'dirA', 'dirB',
+ 'foo.py')
verifies that the django.po file has a gettext-style location comment
of the form
@@ -368,7 +369,9 @@ class BasicExtractorTests(ExtractorTests):
management.call_command("makemessages", locale=[LOCALE], verbosity=0)
def test_extraction_warning(self):
- """test xgettext warning about multiple bare interpolation placeholders"""
+ """
+ test xgettext warning about multiple bare interpolation placeholders
+ """
shutil.copyfile("./code.sample", "./code_sample.py")
out = StringIO()
management.call_command("makemessages", locale=[LOCALE], stdout=out)
@@ -438,7 +441,9 @@ class BasicExtractorTests(ExtractorTests):
)
def test_template_comments(self):
- """Template comment tags on the same line of other constructs (#19552)"""
+ """
+ Template comment tags on the same line of other constructs (#19552)
+ """
# Test detection/end user reporting of old, incorrect templates
# translator comments syntax
with warnings.catch_warnings(record=True) as ws:
@@ -656,7 +661,8 @@ class JavaScriptExtractorTests(ExtractorTests):
def test_i18n_catalog_not_ignored_when_not_invoked_for_django(self):
# Create target file so it exists in the filesystem but is NOT ignored.
- # "invoked_for_django" is False when "conf/locale" folder does not exist.
+ # "invoked_for_django" is False when "conf/locale" folder does not
+ # exist.
self.assertIs(os.path.exists(os.path.join("conf", "locale")), False)
i18n_catalog_js = os.path.join("views", "templates", "i18n_catalog.js")
os.makedirs(os.path.dirname(i18n_catalog_js))
@@ -757,9 +763,9 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
def test_translate_and_plural_blocktranslate_collision(self):
"""
- Ensures a correct workaround for the gettext bug when handling a literal
- found inside a {% translate %} tag and also in another file inside a
- {% blocktranslate %} with a plural (#17375).
+ Ensures a correct workaround for the gettext bug when handling a
+ literal found inside a {% translate %} tag and also in another file
+ inside a {% blocktranslate %} with a plural (#17375).
"""
management.call_command(
"makemessages", locale=[LOCALE], extensions=["html", "djtpl"], verbosity=0
@@ -810,7 +816,9 @@ class NoWrapExtractorTests(ExtractorTests):
class LocationCommentsTests(ExtractorTests):
def test_no_location_enabled(self):
- """Behavior is correct if --no-location switch is specified. See #16903."""
+ """
+ Behavior is correct if --no-location switch is specified. See #16903.
+ """
management.call_command(
"makemessages", locale=[LOCALE], verbosity=0, no_location=True
)
@@ -823,7 +831,8 @@ class LocationCommentsTests(ExtractorTests):
"makemessages", locale=[LOCALE], verbosity=0, no_location=False
)
self.assertTrue(os.path.exists(self.PO_FILE))
- # #16903 -- Standard comment with source file relative path should be present
+ # #16903 -- Standard comment with source file relative path should be
+ # present
self.assertLocationCommentPresent(
self.PO_FILE, "Translatable literal #6b", "templates", "test.html"
)
@@ -942,7 +951,8 @@ class ExcludedLocaleExtractionTests(ExtractorTests):
def _set_times_for_all_po_files(self):
"""
- Set access and modification times to the Unix epoch time for all the .po files.
+ Set access and modification times to the Unix epoch time for all the
+ .po files.
"""
for locale in self.LOCALES:
os.utime(self.PO_FILE % locale, (0, 0))
@@ -1010,7 +1020,8 @@ class CustomLayoutExtractionTests(ExtractorTests):
def _test_project_locale_paths(self, locale_path):
"""
- * translations for an app containing a locale folder are stored in that folder
+ * translations for an app containing a locale folder are stored in that
+ folder
* translations outside of that app are in LOCALE_PATHS[0]
"""
with override_settings(LOCALE_PATHS=[locale_path]):
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 1f50ba1112..b4bdf160d6 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -92,7 +92,8 @@ class TranslationTests(SimpleTestCase):
@translation.override("fr")
def test_plural(self):
"""
- Test plurals with ngettext. French differs from English in that 0 is singular.
+ Test plurals with ngettext. French differs from English in that 0 is
+ singular.
"""
self.assertEqual(
ngettext("%(num)d year", "%(num)d years", 0) % {"num": 0},
@@ -119,9 +120,9 @@ class TranslationTests(SimpleTestCase):
@translation.override("fr")
def test_multiple_plurals_per_language(self):
"""
- Normally, French has 2 plurals. As other/locale/fr/LC_MESSAGES/django.po
- has a different plural equation with 3 plurals, this tests if those
- plural are honored.
+ Normally, French has 2 plurals. As
+ other/locale/fr/LC_MESSAGES/django.po has a different plural equation
+ with 3 plurals, this tests if those plural are honored.
"""
self.assertEqual(ngettext("%d singular", "%d plural", 0) % 0, "0 pluriel1")
self.assertEqual(ngettext("%d singular", "%d plural", 1) % 1, "1 singulier")
@@ -415,8 +416,8 @@ class TranslationTests(SimpleTestCase):
@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_safe_status(self):
"""
- Translating a string requiring no auto-escaping with gettext or pgettext
- shouldn't change the "safe" status.
+ Translating a string requiring no auto-escaping with gettext or
+ pgettext shouldn't change the "safe" status.
"""
trans_real._active = Local()
trans_real._translations = {}
@@ -1278,8 +1279,8 @@ class FormattingTests(SimpleTestCase):
self.assertEqual(sanitize_separators(123), 123)
with translation.override("ru", deactivate=True):
- # Russian locale has non-breaking space (\xa0) as thousand separator
- # Usual space is accepted too when sanitizing inputs
+ # Russian locale has non-breaking space (\xa0) as thousand
+ # separator Usual space is accepted too when sanitizing inputs
with self.settings(USE_THOUSAND_SEPARATOR=True):
self.assertEqual(sanitize_separators("1\xa0234\xa0567"), "1234567")
self.assertEqual(sanitize_separators("77\xa0777,777"), "77777.777")
@@ -1347,7 +1348,8 @@ class FormattingTests(SimpleTestCase):
def test_iter_format_modules_stability(self):
"""
Tests the iter_format_modules function always yields format modules in
- a stable and correct order in presence of both base ll and ll_CC formats.
+ a stable and correct order in presence of both base ll and ll_CC
+ formats.
"""
en_format_mod = import_module("django.conf.locale.en.formats")
en_gb_format_mod = import_module("django.conf.locale.en_GB.formats")
@@ -1364,7 +1366,8 @@ class FormattingTests(SimpleTestCase):
def test_localize_templatetag_and_filter(self):
"""
- Test the {% localize %} templatetag and the localize/unlocalize filters.
+ Test the {% localize %} templatetag and the localize/unlocalize
+ filters.
"""
context = Context(
{"int": 1455, "float": 3.14, "date": datetime.date(2016, 12, 31)}
@@ -1618,11 +1621,11 @@ class MiscTests(SimpleTestCase):
)
def test_support_for_deprecated_chinese_language_codes(self):
"""
- Some browsers (Firefox, IE, etc.) use deprecated language codes. As these
- language codes will be removed in Django 1.9, these will be incorrectly
- matched. For example zh-tw (traditional) will be interpreted as zh-hans
- (simplified), which is wrong. So we should also accept these deprecated
- language codes.
+ Some browsers (Firefox, IE, etc.) use deprecated language codes. As
+ these language codes will be removed in Django 1.9, these will be
+ incorrectly matched. For example zh-tw (traditional) will be
+ interpreted as zh-hans (simplified), which is wrong. So we should also
+ accept these deprecated language codes.
refs #18419 -- this is explicitly for browser compatibility
"""
@@ -1915,8 +1918,8 @@ class TestLanguageInfo(SimpleTestCase):
def test_fallback_language_code(self):
"""
- get_language_info return the first fallback language info if the lang_info
- struct does not contain the 'name' key.
+ get_language_info return the first fallback language info if the
+ lang_info struct does not contain the 'name' key.
"""
li = get_language_info("zh-my")
self.assertEqual(li["code"], "zh-hans")
@@ -1963,7 +1966,8 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase):
def test_default_lang_without_prefix(self):
"""
With i18n_patterns(..., prefix_default_language=False), the default
- language (settings.LANGUAGE_CODE) should be accessible without a prefix.
+ language (settings.LANGUAGE_CODE) should be accessible without a
+ prefix.
"""
response = self.client.get("/simple/")
self.assertEqual(response.content, b"Yes")
@@ -1990,8 +1994,8 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase):
def test_no_redirect_on_404(self):
"""
A request for a nonexistent URL shouldn't cause a redirect to
- /<default_language>/<request_url> when prefix_default_language=False and
- /<default_language>/<request_url> has a URL match (#27402).
+ /<default_language>/<request_url> when prefix_default_language=False
+ and /<default_language>/<request_url> has a URL match (#27402).
"""
# A match for /group1/group2/ must exist for this to act as a
# regression test.
diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py
index 0fe9766dc6..eaabc350b4 100644
--- a/tests/inline_formsets/tests.py
+++ b/tests/inline_formsets/tests.py
@@ -57,8 +57,8 @@ class DeletionTests(TestCase):
def test_change_form_deletion_when_invalid(self):
"""
- Make sure that a change form that is filled out, but marked for deletion
- doesn't cause validation errors.
+ Make sure that a change form that is filled out, but marked for
+ deletion doesn't cause validation errors.
"""
PoemFormSet = inlineformset_factory(
Poet, Poem, can_delete=True, fields="__all__"
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 35cabd346f..c554488c10 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -300,7 +300,9 @@ class InspectDBTestCase(TestCase):
)
def test_digits_column_name_introspection(self):
- """Introspection of column names consist/start with digits (#16536/#17676)"""
+ """
+ Introspection of column names consist/start with digits (#16536/#17676)
+ """
char_field_type = connection.features.introspected_field_types["CharField"]
out = StringIO()
call_command("inspectdb", "inspectdb_digitsincolumnname", stdout=out)
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index e89316a270..25336cbee7 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -174,7 +174,8 @@ class LookupTests(TestCase):
)
def test_in_bulk(self):
- # in_bulk() takes a list of IDs and returns a dictionary mapping IDs to objects.
+ # in_bulk() takes a list of IDs and returns a dictionary mapping IDs to
+ # objects.
arts = Article.objects.in_bulk([self.a1.id, self.a2.id])
self.assertEqual(arts[self.a1.id], self.a1)
self.assertEqual(arts[self.a2.id], self.a2)
@@ -375,7 +376,8 @@ class LookupTests(TestCase):
{"headline": "Article 1", "id": self.a1.id},
],
)
- # The values() method works with "extra" fields specified in extra(select).
+ # The values() method works with "extra" fields specified in
+ # extra(select).
self.assertSequenceEqual(
Article.objects.extra(select={"id_plus_one": "id + 1"}).values(
"id", "id_plus_one"
@@ -415,7 +417,8 @@ class LookupTests(TestCase):
}
],
)
- # You can specify fields from forward and reverse relations, just like filter().
+ # You can specify fields from forward and reverse relations, just like
+ # filter().
self.assertSequenceEqual(
Article.objects.values("headline", "author__name"),
[
@@ -660,8 +663,9 @@ class LookupTests(TestCase):
)
def test_escaping(self):
- # Underscores, percent signs and backslashes have special meaning in the
- # underlying SQL code, but Django handles the quoting of them automatically.
+ # Underscores, percent signs and backslashes have special meaning in
+ # the underlying SQL code, but Django handles the quoting of them
+ # automatically.
a8 = Article.objects.create(
headline="Article_ with underscore", pub_date=datetime(2005, 11, 20)
)
diff --git a/tests/m2m_regress/models.py b/tests/m2m_regress/models.py
index 0e6cec3b6a..43addfd23f 100644
--- a/tests/m2m_regress/models.py
+++ b/tests/m2m_regress/models.py
@@ -39,7 +39,8 @@ class Entry(models.Model):
return self.name
-# Two models both inheriting from a base model with a self-referential m2m field
+# Two models both inheriting from a base model with a self-referential m2m
+# field
class SelfReferChild(SelfRefer):
pass
@@ -48,7 +49,8 @@ class SelfReferChildSibling(SelfRefer):
pass
-# Many-to-Many relation between models, where one of the PK's isn't an Autofield
+# Many-to-Many relation between models, where one of the PK's isn't an
+# Autofield
class Line(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/m2m_through/tests.py b/tests/m2m_through/tests.py
index 81a47a2083..d89d89ed8f 100644
--- a/tests/m2m_through/tests.py
+++ b/tests/m2m_through/tests.py
@@ -408,7 +408,8 @@ class M2mThroughReferentialTests(TestCase):
self.assertQuerySetEqual(chris.friends.all(), [])
- # Since this isn't a symmetrical relation, Tony's friend link still exists.
+ # Since this isn't a symmetrical relation, Tony's friend link still
+ # exists.
self.assertQuerySetEqual(tony.friends.all(), ["Chris"], attrgetter("name"))
def test_self_referential_non_symmetrical_both(self):
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index bab1b4be83..2bf3890941 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -167,7 +167,8 @@ class MailTestsMixin:
def assertEndsWith(self, first, second):
if not first.endswith(second):
# Use assertEqual() for failure message with diffs. If first value
- # is much longer than second, truncate start and prepend an ellipsis.
+ # is much longer than second, truncate start and prepend an
+ # ellipsis.
self.longMessage = True
max_len = len(second) + self.START_END_EXTRA_CONTEXT
end_of_first = (
@@ -249,7 +250,8 @@ class MailTests(MailTestsMixin, SimpleTestCase):
@mock.patch("django.core.mail.message.MIMEText.set_payload")
def test_nonascii_as_string_with_ascii_charset(self, mock_set_payload):
- """Line length check should encode the payload supporting `surrogateescape`.
+ """Line length check should encode the payload supporting
+ `surrogateescape`.
Following https://github.com/python/cpython/issues/76511, newer
versions of Python (3.12.3 and 3.13) ensure that a message's
@@ -260,7 +262,8 @@ class MailTests(MailTestsMixin, SimpleTestCase):
Line length checks in SafeMIMEText's set_payload should also use the
same error handling strategy to avoid errors such as:
- UnicodeEncodeError: 'utf-8' codec can't encode <...>: surrogates not allowed
+ UnicodeEncodeError: 'utf-8' codec can't encode <...>: surrogates not
+ allowed
"""
# This test is specific to Python's legacy MIMEText. This can be safely
@@ -965,8 +968,9 @@ class MailTests(MailTestsMixin, SimpleTestCase):
self.assertEqual(email.attachments[0].content, expected_content)
# Check attachments in the generated message.
- # (The actual content is not checked as variations in platform
- # line endings and rfc822 refolding complicate the logic.)
+ # (The actual content is not checked as variations in
+ # platform line endings and rfc822 refolding complicate the
+ # logic.)
attachments = self.get_decoded_attachments(email)
self.assertEqual(len(attachments), 1)
actual = attachments[0]
@@ -979,7 +983,8 @@ class MailTests(MailTestsMixin, SimpleTestCase):
if possible and changes to DEFAULT_ATTACHMENT_MIME_TYPE if not.
"""
email = EmailMessage()
- # Mimetype guessing identifies these as text/plain from the .txt extensions.
+ # Mimetype guessing identifies these as text/plain from the .txt
+ # extensions.
email.attach("utf8.txt", "ütƒ-8\n".encode())
email.attach("not-utf8.txt", b"\x86unknown-encoding\n")
attachments = self.get_decoded_attachments(email)
@@ -1093,8 +1098,9 @@ class MailTests(MailTestsMixin, SimpleTestCase):
def test_attach_rfc822_message(self):
"""
- EmailMessage.attach() docs: "If you specify a mimetype of message/rfc822,
- it will also accept django.core.mail.EmailMessage and email.message.Message."
+ EmailMessage.attach() docs: "If you specify a mimetype of
+ message/rfc822, it will also accept django.core.mail.EmailMessage and
+ email.message.Message."
"""
# django.core.mail.EmailMessage
django_email = EmailMessage("child subject", "child body")
@@ -1124,8 +1130,9 @@ class MailTests(MailTestsMixin, SimpleTestCase):
self.assertIsInstance(email.attachments[0], EmailAttachment)
self.assertEqual(email.attachments[0].mimetype, "message/rfc822")
- # Make sure it is serialized correctly: a message/rfc822 attachment
- # whose "body" content (payload) is the "encapsulated" (child) message.
+ # Make sure it is serialized correctly: a message/rfc822
+ # attachment whose "body" content (payload) is the
+ # "encapsulated" (child) message.
attachments = self.get_raw_attachments(email)
self.assertEqual(len(attachments), 1)
rfc822_attachment = attachments[0]
@@ -1141,9 +1148,9 @@ class MailTests(MailTestsMixin, SimpleTestCase):
cte = rfc822_attachment.get("Content-Transfer-Encoding", "7bit")
self.assertIn(cte, ("7bit", "8bit", "binary"))
- # Any properly declared CTE is allowed for the attached message itself
- # (including quoted-printable or base64). For the plain ASCII content
- # in this test, we'd expect 7bit.
+ # Any properly declared CTE is allowed for the attached message
+ # itself (including quoted-printable or base64). For the plain
+ # ASCII content in this test, we'd expect 7bit.
child_cte = attached_message.get("Content-Transfer-Encoding", "7bit")
self.assertEqual(child_cte, "7bit")
self.assertEqual(attached_message.get_content_type(), "text/plain")
@@ -1302,10 +1309,10 @@ class MailTests(MailTestsMixin, SimpleTestCase):
s = msg.message().as_bytes()
self.assertIn(b"Content-Transfer-Encoding: 8bit", s)
- # Long body lines that require folding should use quoted-printable or base64,
- # whichever is shorter. However, Python's legacy email API avoids re-folding
- # non-ASCII text and just uses CTE 8bit. (The modern API would correctly choose
- # base64 here. Any of these is deliverable.)
+ # Long body lines that require folding should use quoted-printable or
+ # base64, whichever is shorter. However, Python's legacy email API
+ # avoids re-folding non-ASCII text and just uses CTE 8bit. (The modern
+ # API would correctly choose base64 here. Any of these is deliverable.)
msg = EmailMessage(
body=(
"Body with non latin characters: А Б В Г Д Е Ж Ѕ З И І К Л М Н О П.\n"
@@ -1435,7 +1442,8 @@ class MailTests(MailTestsMixin, SimpleTestCase):
# EmailMessage.message() will not catch these cases, as it only calls
# sanitize_address() if an address also includes non-ASCII chars.
# Django detects these cases in the SMTP EmailBackend during sending.
- # See SMTPBackendTests.test_avoids_sending_to_invalid_addresses() below.
+ # See SMTPBackendTests.test_avoids_sending_to_invalid_addresses()
+ # below.
for email_address in (
# Invalid address with two @ signs.
"to@other.com@example.com",
@@ -1562,8 +1570,9 @@ class MailTests(MailTestsMixin, SimpleTestCase):
for header in headers:
for email_address in cases:
with self.subTest(header=header, email_address=email_address):
- # Construct an EmailMessage with header set to email_address.
- # Specific constructor params vary by header.
+ # Construct an EmailMessage with header set to
+ # email_address. Specific constructor params vary by
+ # header.
if header == "From":
email = EmailMessage(from_email=email_address)
elif header in ("To", "Cc", "Bcc", "Reply-To"):
@@ -1740,8 +1749,8 @@ class MailTests(MailTestsMixin, SimpleTestCase):
def test_positional_arguments_order(self):
"""
- EmailMessage class docs: "… is initialized with the following parameters
- (in the given order, if positional arguments are used)."
+ EmailMessage class docs: "… is initialized with the following
+ parameters (in the given order, if positional arguments are used)."
"""
connection = mail.get_connection()
email = EmailMessage(
@@ -2064,10 +2073,10 @@ class BaseEmailBackendTests(MailTestsMixin):
def test_send_long_lines(self):
"""
- Email line length is limited to 998 chars by the RFC 5322 Section 2.1.1.
- A message body containing longer lines is converted to quoted-printable
- or base64 (whichever is shorter), to avoid having to insert newlines
- in a way that alters the intended text.
+ Email line length is limited to 998 chars by the RFC 5322 Section
+ 2.1.1. A message body containing longer lines is converted to
+ quoted-printable or base64 (whichever is shorter), to avoid having to
+ insert newlines in a way that alters the intended text.
"""
# Django with Python's legacy email API uses quoted-printable for both
# cases below. Python's modern API would prefer shorter base64 for the
@@ -2270,8 +2279,9 @@ class BaseEmailBackendTests(MailTestsMixin):
gettext_lazy("test@example.com"),
# RemovedInDjango70Warning: uncomment these cases when support for
# deprecated (name, address) tuples is removed.
- # [("nobody", "nobody@example.com"), ("other", "other@example.com")],
- # [["nobody", "nobody@example.com"], ["other", "other@example.com"]],
+ # [("nobody", "nobody@example.com"), ("other",
+ # "other@example.com")], [["nobody", "nobody@example.com"],
+ # ["other", "other@example.com"]],
[("name", "test", "example.com")],
[("Name <test@example.com",)],
[[]],
@@ -2576,7 +2586,8 @@ class SMTPHandler:
data = envelope.content
mail_from = envelope.mail_from
- # Convert SMTP's CRNL to NL, to simplify content checks in shared test cases.
+ # Convert SMTP's CRNL to NL, to simplify content checks in shared test
+ # cases.
message = message_from_bytes(data.replace(b"\r\n", b"\n"))
try:
header_from = message["from"].addresses[0].addr_spec
@@ -2836,7 +2847,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
self.assertTrue(msg)
msg = msg.decode()
- # The message only contains CRLF and not combinations of CRLF, LF, and CR.
+ # The message only contains CRLF and not combinations of CRLF, LF,
+ # and CR.
msg = msg.replace("\r\n", "")
self.assertNotIn("\r", msg)
self.assertNotIn("\n", msg)
@@ -2873,7 +2885,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
def test_avoids_sending_to_invalid_addresses(self):
"""
Verify invalid addresses can't sneak into SMTP commands through
- EmailMessage.all_recipients() (which is distinct from message header fields).
+ EmailMessage.all_recipients() (which is distinct from message header
+ fields).
"""
backend = smtp.EmailBackend()
backend.connection = mock.Mock()
@@ -2892,7 +2905,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
):
with self.subTest(email_address=email_address):
# Use bcc (which is only processed by SMTP backend) to ensure
- # error is coming from SMTP backend, not EmailMessage.message().
+ # error is coming from SMTP backend, not
+ # EmailMessage.message().
email = EmailMessage(bcc=[email_address])
with self.assertRaisesMessage(ValueError, "Invalid address"):
backend.send_messages([email])
diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py
index 1535ef4105..34b7ffc67d 100644
--- a/tests/many_to_many/tests.py
+++ b/tests/many_to_many/tests.py
@@ -73,7 +73,8 @@ class ManyToManyTests(TestCase):
with transaction.atomic():
a6.publications.add(a5)
- # Add a Publication directly via publications.add by using keyword arguments.
+ # Add a Publication directly via publications.add by using keyword
+ # arguments.
p5 = a6.publications.create(title="Highlights for Adults")
self.assertSequenceEqual(
a6.publications.all(),
@@ -256,8 +257,8 @@ class ManyToManyTests(TestCase):
[self.a1, self.a3, self.a2, self.a4],
)
- # Excluding a related item works as you would expect, too (although the SQL
- # involved is a little complex).
+ # Excluding a related item works as you would expect, too (although the
+ # SQL involved is a little complex).
self.assertSequenceEqual(
Article.objects.exclude(publications=self.p2),
[self.a1],
@@ -324,7 +325,8 @@ class ManyToManyTests(TestCase):
)
def test_bulk_delete(self):
- # Bulk delete some Publications - references to deleted publications should go
+ # Bulk delete some Publications - references to deleted publications
+ # should go
Publication.objects.filter(title__startswith="Science").delete()
self.assertSequenceEqual(
Publication.objects.all(),
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index 5e31ea1760..ac43c0da95 100644
--- a/tests/many_to_one/tests.py
+++ b/tests/many_to_one/tests.py
@@ -98,7 +98,8 @@ class ManyToOneTests(TestCase):
[new_article, new_article2, self.a],
)
- # Add the same article to a different article set - check that it moves.
+ # Add the same article to a different article set - check that it
+ # moves.
self.r2.article_set.add(new_article2)
self.assertEqual(new_article2.reporter.id, self.r2.id)
self.assertSequenceEqual(self.r2.article_set.all(), [new_article2])
@@ -193,7 +194,8 @@ class ManyToOneTests(TestCase):
[new_article, self.a],
)
self.assertSequenceEqual(self.r2.article_set.all(), [new_article2])
- # Reporter cannot be null - there should not be a clear or remove method
+ # Reporter cannot be null - there should not be a clear or remove
+ # method
self.assertFalse(hasattr(self.r2.article_set, "remove"))
self.assertFalse(hasattr(self.r2.article_set, "clear"))
@@ -384,7 +386,8 @@ class ManyToOneTests(TestCase):
john_smith,
)
- # Counting in the opposite direction works in conjunction with distinct()
+ # Counting in the opposite direction works in conjunction with
+ # distinct()
self.assertEqual(
Reporter.objects.filter(article__headline__startswith="T").count(), 2
)
@@ -578,7 +581,8 @@ class ManyToOneTests(TestCase):
)
def test_fk_assignment_and_related_object_cache(self):
- # Tests of ForeignKey assignment and the related-object cache (see #6886).
+ # Tests of ForeignKey assignment and the related-object cache (see
+ # #6886).
p = Parent.objects.create(name="Parent")
c = Child.objects.create(name="Child", parent=p)
@@ -594,7 +598,8 @@ class ManyToOneTests(TestCase):
del c._state.fields_cache["parent"]
self.assertIsNot(c.parent, p)
- # Assigning a new object results in that object getting cached immediately.
+ # Assigning a new object results in that object getting cached
+ # immediately.
p2 = Parent.objects.create(name="Parent 2")
c.parent = p2
self.assertIs(c.parent, p2)
@@ -773,7 +778,8 @@ class ManyToOneTests(TestCase):
private_school = School.objects.create(is_public=False)
private_student = Student.objects.create(school=private_school)
- # Only one school is available via all() due to the custom default manager.
+ # Only one school is available via all() due to the custom default
+ # manager.
self.assertSequenceEqual(School.objects.all(), [public_school])
self.assertEqual(public_student.school, public_school)
diff --git a/tests/many_to_one_null/tests.py b/tests/many_to_one_null/tests.py
index f92d49f0a9..a6c56c9ada 100644
--- a/tests/many_to_one_null/tests.py
+++ b/tests/many_to_one_null/tests.py
@@ -48,7 +48,8 @@ class ManyToOneNullTests(TestCase):
# Accessing an article's 'reporter' attribute returns None
# if the reporter is set to None.
self.assertIsNone(a3.reporter)
- # To retrieve the articles with no reporters set, use "reporter__isnull=True".
+ # To retrieve the articles with no reporters set, use
+ # "reporter__isnull=True".
self.assertSequenceEqual(
Article.objects.filter(reporter__isnull=True), [self.a3]
)
@@ -78,7 +79,8 @@ class ManyToOneNullTests(TestCase):
def test_set(self):
# Use manager.set() to allocate ForeignKey. Null is legal, so existing
- # members of the set that are not in the assignment set are set to null.
+ # members of the set that are not in the assignment set are set to
+ # null.
self.r2.article_set.set([self.a2, self.a3])
self.assertSequenceEqual(self.r2.article_set.all(), [self.a2, self.a3])
# Use manager.set(clear=True)
diff --git a/tests/messages_tests/test_cookie.py b/tests/messages_tests/test_cookie.py
index 8fd6fa3d61..f1b3a20c3b 100644
--- a/tests/messages_tests/test_cookie.py
+++ b/tests/messages_tests/test_cookie.py
@@ -131,8 +131,8 @@ class CookieTests(BaseTests, SimpleTestCase):
# When storing as a cookie, the cookie has constant overhead of approx
# 54 chars, and each message has a constant overhead of about 37 chars
- # and a variable overhead of zero in the best case. We aim for a message
- # size which will fit 4 messages into the cookie, but not 5.
+ # and a variable overhead of zero in the best case. We aim for a
+ # message size which will fit 4 messages into the cookie, but not 5.
# See also FallbackTest.test_session_fallback
msg_size = int((CookieStorage.max_cookie_size - 54) / 4.5 - 37)
first_msg = None
diff --git a/tests/middleware/test_csp.py b/tests/middleware/test_csp.py
index de55f0c6a0..c3321b76a5 100644
--- a/tests/middleware/test_csp.py
+++ b/tests/middleware/test_csp.py
@@ -47,7 +47,8 @@ class CSPMiddlewareTest(SimpleTestCase):
@override_settings(SECURE_CSP={"default-src": [CSP.SELF, CSP.NONCE]})
def test_csp_basic_with_nonce_but_unused(self):
"""
- Test if `request.csp_nonce` is never accessed, it is not added to the header.
+ Test if `request.csp_nonce` is never accessed, it is not added to the
+ header.
"""
response = self.client.get("/csp-base/")
nonce = response.text
diff --git a/tests/middleware/test_security.py b/tests/middleware/test_security.py
index 339b9181c3..142f1311ae 100644
--- a/tests/middleware/test_security.py
+++ b/tests/middleware/test_security.py
@@ -130,9 +130,9 @@ class SecurityMiddlewareTest(SimpleTestCase):
def test_sts_subdomains_and_preload(self):
"""
With SECURE_HSTS_SECONDS non-zero, SECURE_HSTS_INCLUDE_SUBDOMAINS and
- SECURE_HSTS_PRELOAD True, the middleware adds a "Strict-Transport-Security"
- header containing both the "includeSubDomains" and "preload" directives
- to the response.
+ SECURE_HSTS_PRELOAD True, the middleware adds a
+ "Strict-Transport-Security" header containing both the
+ "includeSubDomains" and "preload" directives to the response.
"""
response = self.process_response(secure=True)
self.assertEqual(
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index dae8a7f3ba..c5d630293e 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2080,8 +2080,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_rename_field_preserve_db_column_preserve_constraint(self):
"""
- Renaming a field that already had a db_column attribute and a constraint
- generates two no-op operations: RenameField and AlterConstraint.
+ Renaming a field that already had a db_column attribute and a
+ constraint generates two no-op operations: RenameField and
+ AlterConstraint.
"""
before = [
ModelState(
@@ -2566,7 +2567,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_circular_fk_dependency(self):
"""
Having a circular ForeignKey dependency automatically
- resolves the situation into 2 migrations on one side and 1 on the other.
+ resolves the situation into 2 migrations on one side and 1 on the
+ other.
"""
changes = self.get_changes(
[], [self.author_with_book, self.book, self.publisher_with_book]
@@ -2665,7 +2667,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_alter_db_table_no_changes(self):
"""
- Alter_db_table doesn't generate a migration if no changes have been made.
+ Alter_db_table doesn't generate a migration if no changes have been
+ made.
"""
changes = self.get_changes(
[self.author_with_db_table_options], [self.author_with_db_table_options]
@@ -2675,8 +2678,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_keep_db_table_with_model_change(self):
"""
- Tests when model changes but db_table stays as-is, autodetector must not
- create more than one operation.
+ Tests when model changes but db_table stays as-is, autodetector must
+ not create more than one operation.
"""
changes = self.get_changes(
[self.author_with_db_table_options],
@@ -4089,16 +4092,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_list(self):
"""Nested deconstruction descends into lists."""
- # When lists contain items that deconstruct to identical values, those lists
- # should be considered equal for the purpose of detecting state changes
- # (even if the original items are unequal).
+ # When lists contain items that deconstruct to identical values, those
+ # lists should be considered equal for the purpose of detecting state
+ # changes (even if the original items are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_list_1],
[self.author_name_deconstructible_list_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed lists should be reported
- # as a change
+ # Legitimate differences within the deconstructed lists should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_list_1],
[self.author_name_deconstructible_list_3],
@@ -4107,16 +4110,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_tuple(self):
"""Nested deconstruction descends into tuples."""
- # When tuples contain items that deconstruct to identical values, those tuples
- # should be considered equal for the purpose of detecting state changes
- # (even if the original items are unequal).
+ # When tuples contain items that deconstruct to identical values, those
+ # tuples should be considered equal for the purpose of detecting state
+ # changes (even if the original items are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_tuple_1],
[self.author_name_deconstructible_tuple_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed tuples should be reported
- # as a change
+ # Legitimate differences within the deconstructed tuples should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_tuple_1],
[self.author_name_deconstructible_tuple_3],
@@ -4125,16 +4128,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_dict(self):
"""Nested deconstruction descends into dict values."""
- # When dicts contain items whose values deconstruct to identical values,
- # those dicts should be considered equal for the purpose of detecting
- # state changes (even if the original values are unequal).
+ # When dicts contain items whose values deconstruct to identical
+ # values, those dicts should be considered equal for the purpose of
+ # detecting state changes (even if the original values are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_dict_1],
[self.author_name_deconstructible_dict_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed dicts should be reported
- # as a change
+ # Legitimate differences within the deconstructed dicts should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_dict_1],
[self.author_name_deconstructible_dict_3],
@@ -4146,16 +4149,17 @@ class AutodetectorTests(BaseAutodetectorTests):
Nested deconstruction is applied recursively to the args/kwargs of
deconstructed objects.
"""
- # If the items within a deconstructed object's args/kwargs have the same
- # deconstructed values - whether or not the items themselves are different
- # instances - then the object as a whole is regarded as unchanged.
+ # If the items within a deconstructed object's args/kwargs have the
+ # same deconstructed values - whether or not the items themselves are
+ # different instances - then the object as a whole is regarded as
+ # unchanged.
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_2],
)
self.assertEqual(changes, {})
- # Differences that exist solely within the args list of a deconstructed object
- # should be reported as changes
+ # Differences that exist solely within the args list of a deconstructed
+ # object should be reported as changes
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_changed_arg],
@@ -4167,8 +4171,8 @@ class AutodetectorTests(BaseAutodetectorTests):
[self.author_name_nested_deconstructible_extra_arg],
)
self.assertEqual(len(changes), 1)
- # Differences that exist solely within the kwargs dict of a deconstructed object
- # should be reported as changes
+ # Differences that exist solely within the kwargs dict of a
+ # deconstructed object should be reported as changes
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_changed_kwarg],
@@ -4183,8 +4187,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstruct_type(self):
"""
- #22951 -- Uninstantiated classes with deconstruct are correctly returned
- by deep_deconstruct during serialization.
+ #22951 -- Uninstantiated classes with deconstruct are correctly
+ returned by deep_deconstruct during serialization.
"""
author = ModelState(
"testapp",
@@ -4243,7 +4247,9 @@ class AutodetectorTests(BaseAutodetectorTests):
side_effect=AssertionError("Should not have prompted for not null addition"),
)
def test_add_many_to_many(self, mocked_ask_method):
- """#22435 - Adding a ManyToManyField should not prompt for a default."""
+ """
+ #22435 - Adding a ManyToManyField should not prompt for a default.
+ """
changes = self.get_changes(
[self.author_empty, self.publisher], [self.author_with_m2m, self.publisher]
)
@@ -4362,9 +4368,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_many_to_many_removed_before_through_model_2(self):
"""
- Removing a model that contains a ManyToManyField and the "through" model
- in the same change must remove the field before the model to maintain
- consistency.
+ Removing a model that contains a ManyToManyField and the "through"
+ model in the same change must remove the field before the model to
+ maintain consistency.
"""
changes = self.get_changes(
[
@@ -4459,8 +4465,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_non_circular_foreignkey_dependency_removal(self):
"""
- If two models with a ForeignKey from one to the other are removed at the
- same time, the autodetector should remove them in the correct order.
+ If two models with a ForeignKey from one to the other are removed at
+ the same time, the autodetector should remove them in the correct
+ order.
"""
changes = self.get_changes(
[self.author_with_publisher, self.publisher_with_author], []
diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py
index 41041f51e8..b636d18ec4 100644
--- a/tests/migrations/test_base.py
+++ b/tests/migrations/test_base.py
@@ -21,7 +21,8 @@ from django.utils.module_loading import module_dir
class MigrationTestBase(TransactionTestCase):
"""
- Contains an extended set of asserts for testing migrations and schema operations.
+ Contains an extended set of asserts for testing migrations and schema
+ operations.
"""
available_apps = ["migrations"]
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index cd49a5a8fc..b5817081d2 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -463,7 +463,8 @@ class MigrateTests(MigrationTestBase):
call_command("migrate", "migrations", "0001", verbosity=0)
out = io.StringIO()
- # Giving the explicit app_label tests for selective `show_list` in the command
+ # Giving the explicit app_label tests for selective `show_list` in the
+ # command
call_command(
"showmigrations",
"migrations",
@@ -1696,7 +1697,8 @@ class MakeMigrationsTests(MigrationTestBase):
self.assertEqual(has_table.call_count, 4)
def test_failing_migration(self):
- # If a migration fails to serialize, it shouldn't generate an empty file. #21280
+ # If a migration fails to serialize, it shouldn't generate an empty
+ # file. #21280
apps.register_model("migrations", UnserializableModel)
with self.temporary_migration_module() as migration_dir:
@@ -1754,7 +1756,8 @@ class MakeMigrationsTests(MigrationTestBase):
with open(initial_file, encoding="utf-8") as fp:
content = fp.read()
- # Remove all whitespace to check for empty dependencies and operations
+ # Remove all whitespace to check for empty dependencies and
+ # operations
content = content.replace(" ", "")
self.assertIn(
"dependencies=[]" if HAS_BLACK else "dependencies=[\n]", content
@@ -1778,7 +1781,8 @@ class MakeMigrationsTests(MigrationTestBase):
def test_makemigrations_no_changes_no_apps(self):
"""
- makemigrations exits when there are no changes and no apps are specified.
+ makemigrations exits when there are no changes and no apps are
+ specified.
"""
out = io.StringIO()
call_command("makemigrations", stdout=out)
@@ -2165,7 +2169,8 @@ class MakeMigrationsTests(MigrationTestBase):
def test_makemigrations_handle_merge(self):
"""
- makemigrations properly merges the conflicting migrations with --noinput.
+ makemigrations properly merges the conflicting migrations with
+ --noinput.
"""
out = io.StringIO()
with self.temporary_migration_module(
@@ -2965,8 +2970,9 @@ class SquashMigrationsTests(MigrationTestBase):
with self.temporary_migration_module(
module="migrations.test_migrations_squashed_loop"
):
- # Hits a squash replacement cycle check error, but the actual failure is
- # dependent on the order in which the files are read on disk.
+ # Hits a squash replacement cycle check error, but the actual
+ # failure is dependent on the order in which the files are read on
+ # disk.
with self.assertRaisesRegex(
CommandError,
r"Cyclical squash replacement found, starting at"
@@ -3039,7 +3045,8 @@ class SquashMigrationsTests(MigrationTestBase):
interactive=False,
)
- # Update the 4th migration to depend on the squash(replacement) migration.
+ # Update the 4th migration to depend on the squash(replacement)
+ # migration.
loader = MigrationLoader(connection)
migration = loader.disk_migrations[
("migrations", "0004_remove_mymodel1_field_1_mymodel1_field_3_and_more")
@@ -3219,7 +3226,8 @@ class SquashMigrationsTests(MigrationTestBase):
def test_squashmigrations_invalid_start(self):
"""
- squashmigrations doesn't accept a starting migration after the ending migration.
+ squashmigrations doesn't accept a starting migration after the ending
+ migration.
"""
with self.temporary_migration_module(
module="migrations.test_migrations_no_changes"
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index 571cb3e1a2..dd6793b533 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -78,7 +78,8 @@ class ExecutorTests(MigrationTestBase):
)
def test_run_with_squashed(self):
"""
- Tests running a squashed migration from zero (should ignore what it replaces)
+ Tests running a squashed migration from zero (should ignore what it
+ replaces)
"""
executor = MigrationExecutor(connection)
# Check our leaf node is the squashed one
@@ -351,7 +352,8 @@ class ExecutorTests(MigrationTestBase):
self.assertTableExists("migrations_tribble")
# Make sure that was faked
self.assertIs(state["faked"], True)
- # Finally, migrate forwards; this should fake-apply our initial migration
+ # Finally, migrate forwards; this should fake-apply our initial
+ # migration
executor.loader.build_graph()
self.assertEqual(
executor.migration_plan([("migrations", "0001_initial")]),
@@ -383,8 +385,8 @@ class ExecutorTests(MigrationTestBase):
)
def test_custom_user(self):
"""
- Regression test for #22325 - references to a custom user model defined in the
- same app are not resolved correctly.
+ Regression test for #22325 - references to a custom user model defined
+ in the same app are not resolved correctly.
"""
with isolate_lru_cache(global_apps.get_swappable_settings_name):
executor = MigrationExecutor(connection)
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index 3b30aed100..7cf11f7faa 100644
--- a/tests/migrations/test_loader.py
+++ b/tests/migrations/test_loader.py
@@ -515,7 +515,9 @@ class LoaderTests(TestCase):
}
)
def test_loading_squashed_ref_squashed(self):
- "Tests loading a squashed migration with a new migration referencing it"
+ """
+ Tests loading a squashed migration with a new migration referencing it
+ """
r"""
The sample migrations are structured like this:
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index f86fe16fe0..a893442ce6 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -955,7 +955,8 @@ class OperationTests(OperationTestBase):
operation.state_forwards("test_rmwsc", new_state)
self.assertNotIn(("test_rmwsc", "shetlandpony"), new_state.models)
self.assertIn(("test_rmwsc", "littlehorse"), new_state.models)
- # RenameModel shouldn't repoint the superclass's relations, only local ones
+ # RenameModel shouldn't repoint the superclass's relations, only local
+ # ones
self.assertEqual(
project_state.models["test_rmwsc", "rider"]
.fields["pony"]
@@ -2616,7 +2617,8 @@ class OperationTests(OperationTestBase):
@skipUnlessDBFeature("supports_foreign_keys")
def test_alter_field_pk_fk(self):
"""
- Tests the AlterField operation on primary keys changes any FKs pointing to it.
+ Tests the AlterField operation on primary keys changes any FKs pointing
+ to it.
"""
project_state = self.set_up_test_model("test_alflpkfk", related_model=True)
project_state = self.apply_operations(
@@ -5782,7 +5784,8 @@ class OperationTests(OperationTestBase):
non_atomic_migration.operations = [
migrations.RunPython(inner_method, reverse_code=inner_method, atomic=False)
]
- # If we're a fully-transactional database, both versions should rollback
+ # If we're a fully-transactional database, both versions should
+ # rollback
if connection.features.can_rollback_ddl:
self.assertEqual(
project_state.apps.get_model(
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index d6ecaa1c5d..c31f8b80dd 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -183,11 +183,12 @@ class StateTests(SimpleTestCase):
self.assertTrue(all(isinstance(name, str) for name, mgr in food_state.managers))
self.assertEqual(food_state.managers[0][1].args, ("a", "b", 1, 2))
- # No explicit managers defined. Migrations will fall back to the default
+ # No explicit managers defined. Migrations will fall back to the
+ # default
self.assertEqual(food_no_managers_state.managers, [])
- # food_mgr is used in migration but isn't the default mgr, hence add the
- # default
+ # food_mgr is used in migration but isn't the default mgr, hence add
+ # the default
self.assertEqual(
[name for name, mgr in food_no_default_manager_state.managers],
["food_no_mgr", "food_mgr"],
@@ -1302,7 +1303,8 @@ class StateRelationsTests(SimpleTestCase):
with self.subTest(method=method):
project_state = self.get_base_project_state()
getattr(project_state, method)(*args)
- # ProjectState's `_relations` are populated on `relations` access.
+ # ProjectState's `_relations` are populated on `relations`
+ # access.
self.assertIsNone(project_state._relations)
self.assertEqual(project_state.relations, project_state._relations)
self.assertIsNotNone(project_state._relations)
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 83d801768a..8765f1a6d0 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -52,9 +52,9 @@ class ModelChoiceFieldTests(TestCase):
c4 = Category.objects.create(name="Fourth", url="4th")
self.assertEqual(f.clean(c4.id).name, "Fourth")
- # Delete a Category object *after* the ModelChoiceField has already been
- # instantiated. This proves clean() checks the database during clean()
- # rather than caching it at instantiation time.
+ # Delete a Category object *after* the ModelChoiceField has already
+ # been instantiated. This proves clean() checks the database during
+ # clean() rather than caching it at instantiation time.
Category.objects.get(url="4th").delete()
msg = (
"['Select a valid choice. That choice is not one of the available "
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index e7bdd1ac89..f0334e1e86 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -236,7 +236,8 @@ class ModelFormBaseTest(TestCase):
def test_empty_fields_to_fields_for_model(self):
"""
- An argument of fields=() to fields_for_model should return an empty dictionary
+ An argument of fields=() to fields_for_model should return an empty
+ dictionary
"""
field_dict = fields_for_model(Person, fields=())
self.assertEqual(len(field_dict), 0)
@@ -395,7 +396,8 @@ class ModelFormBaseTest(TestCase):
self.assertEqual(form.instance.slug, empty_value)
self.assertEqual(form.instance.url, empty_value)
- # Save a second form to verify there isn't a unique constraint violation.
+ # Save a second form to verify there isn't a unique constraint
+ # violation.
form = form_class(data=data)
self.assertTrue(form.is_valid())
form.save()
@@ -553,9 +555,9 @@ class ModelFormBaseTest(TestCase):
exclude = "url" # note the missing comma
def test_exclude_and_validation(self):
- # This Price instance generated by this form is not valid because the quantity
- # field is required, but the form is valid because the field is excluded from
- # the form. This is for backwards compatibility.
+ # This Price instance generated by this form is not valid because the
+ # quantity field is required, but the form is valid because the field
+ # is excluded from the form. This is for backwards compatibility.
class PriceFormWithoutQuantity(forms.ModelForm):
class Meta:
model = Price
@@ -568,8 +570,8 @@ class ModelFormBaseTest(TestCase):
with self.assertRaisesMessage(ValidationError, msg):
price.full_clean()
- # The form should not validate fields that it doesn't contain even if they are
- # specified using 'fields', not 'exclude'.
+ # The form should not validate fields that it doesn't contain even if
+ # they are specified using 'fields', not 'exclude'.
class PriceFormWithoutQuantity(forms.ModelForm):
class Meta:
model = Price
@@ -578,8 +580,8 @@ class ModelFormBaseTest(TestCase):
form = PriceFormWithoutQuantity({"price": "6.00"})
self.assertTrue(form.is_valid())
- # The form should still have an instance of a model that is not complete and
- # not saved into a DB yet.
+ # The form should still have an instance of a model that is not
+ # complete and not saved into a DB yet.
self.assertEqual(form.instance.price, Decimal("6.00"))
self.assertIsNone(form.instance.quantity)
self.assertIsNone(form.instance.pk)
@@ -610,8 +612,8 @@ class ModelFormBaseTest(TestCase):
model = Article
fields = "__all__"
- # MixModelForm is now an Article-related thing, because MixModelForm.Meta
- # overrides BaseCategoryForm.Meta.
+ # MixModelForm is now an Article-related thing, because
+ # MixModelForm.Meta overrides BaseCategoryForm.Meta.
self.assertEqual(
list(MixModelForm.base_fields),
@@ -1236,7 +1238,9 @@ class UniqueTest(TestCase):
self.assertFalse(form.is_valid())
def test_explicitpk_unique(self):
- """Ensure keys and blank character strings are tested for uniqueness."""
+ """
+ Ensure keys and blank character strings are tested for uniqueness.
+ """
form = ExplicitPKForm({"key": "key1", "desc": ""})
self.assertTrue(form.is_valid())
form.save()
@@ -1547,8 +1551,8 @@ class ModelFormBasicTests(TestCase):
% (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk),
)
- # When the ModelForm is passed an instance, that instance's current values are
- # inserted as 'initial' data in each Field.
+ # When the ModelForm is passed an instance, that instance's current
+ # values are inserted as 'initial' data in each Field.
f = RoykoForm(auto_id=False, instance=self.w_royko)
self.assertHTMLEqual(
str(f),
@@ -1631,7 +1635,8 @@ class ModelFormBasicTests(TestCase):
kwargs["initial"] = lambda: Category.objects.order_by("name")[:2]
return db_field.formfield(**kwargs)
- # Create a ModelForm, instantiate it, and check that the output is as expected
+ # Create a ModelForm, instantiate it, and check that the output is as
+ # expected
ModelForm = modelform_factory(
Article,
fields=["headline", "categories"],
@@ -1673,9 +1678,9 @@ class ModelFormBasicTests(TestCase):
self.assertEqual(c1.name, "Entertainment")
def test_save_commit_false(self):
- # If you call save() with commit=False, then it will return an object that
- # hasn't yet been saved to the database. In this case, it's up to you to call
- # save() on the resulting model instance.
+ # If you call save() with commit=False, then it will return an object
+ # that hasn't yet been saved to the database. In this case, it's up to
+ # you to call save() on the resulting model instance.
f = BaseCategoryForm(
{"name": "Third test", "slug": "third-test", "url": "third"}
)
@@ -1708,8 +1713,9 @@ class ModelFormBasicTests(TestCase):
def test_multi_fields(self):
self.create_basic_data()
self.maxDiff = None
- # ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any
- # fields with the 'choices' attribute are represented by a ChoiceField.
+ # ManyToManyFields are represented by a MultipleChoiceField,
+ # ForeignKeys and any fields with the 'choices' attribute are
+ # represented by a ChoiceField.
f = ArticleForm(auto_id=False)
self.assertHTMLEqual(
str(f),
@@ -1800,9 +1806,9 @@ class ModelFormBasicTests(TestCase):
# You can restrict a form to a subset of the complete list of fields
# by providing a 'fields' argument. If you try to save a
# model created with such a form, you need to ensure that the fields
- # that are _not_ on the form have default values, or are allowed to have
- # a value of None. If a field isn't specified on a form, the object created
- # from the form can't provide a value for that field!
+ # that are _not_ on the form have default values, or are allowed to
+ # have a value of None. If a field isn't specified on a form, the
+ # object created from the form can't provide a value for that field!
class PartialArticleForm(forms.ModelForm):
class Meta:
model = Article
@@ -1894,8 +1900,9 @@ class ModelFormBasicTests(TestCase):
new_art = Article.objects.get(id=art_id_2)
self.assertSequenceEqual(new_art.categories.all(), [])
- # Create a new article, with categories, via the form, but use commit=False.
- # The m2m data won't be saved until save_m2m() is invoked on the form.
+ # Create a new article, with categories, via the form, but use
+ # commit=False. The m2m data won't be saved until save_m2m() is invoked
+ # on the form.
form_data["categories"] = [str(self.c1.id), str(self.c2.id)]
f = ArticleForm(form_data)
new_art = f.save(commit=False)
@@ -1937,9 +1944,10 @@ class ModelFormBasicTests(TestCase):
def test_runtime_choicefield_populated(self):
self.maxDiff = None
- # Here, we demonstrate that choices for a ForeignKey ChoiceField are determined
- # at runtime, based on the data in the database when the form is displayed, not
- # the data in the database when the form is instantiated.
+ # Here, we demonstrate that choices for a ForeignKey ChoiceField are
+ # determined at runtime, based on the data in the database when the
+ # form is displayed, not the data in the database when the form is
+ # instantiated.
self.create_basic_data()
f = ArticleForm(auto_id=False)
self.assertHTMLEqual(
@@ -2162,18 +2170,18 @@ class ModelMultipleChoiceFieldTests(TestCase):
with self.assertRaises(ValidationError):
f.clean([{"foo": "bar"}])
- # Add a Category object *after* the ModelMultipleChoiceField has already been
- # instantiated. This proves clean() checks the database during clean() rather
- # than caching it at time of instantiation.
- # Note, we are using an id of 1006 here since tests that run before
- # this may create categories with primary keys up to 6. Use
- # a number that will not conflict.
+ # Add a Category object *after* the ModelMultipleChoiceField has
+ # already been instantiated. This proves clean() checks the database
+ # during clean() rather than caching it at time of instantiation. Note,
+ # we are using an id of 1006 here since tests that run before this may
+ # create categories with primary keys up to 6. Use a number that will
+ # not conflict.
c6 = Category.objects.create(id=1006, name="Sixth", url="6th")
self.assertCountEqual(f.clean([c6.id]), [c6])
- # Delete a Category object *after* the ModelMultipleChoiceField has already been
- # instantiated. This proves clean() checks the database during clean() rather
- # than caching it at time of instantiation.
+ # Delete a Category object *after* the ModelMultipleChoiceField has
+ # already been instantiated. This proves clean() checks the database
+ # during clean() rather than caching it at time of instantiation.
Category.objects.get(url="6th").delete()
with self.assertRaises(ValidationError):
f.clean([c6.id])
@@ -2456,8 +2464,8 @@ class ModelOneToOneFieldTests(TestCase):
self.assertTrue(form.is_valid())
self.assertIsNone(form.cleaned_data["publication"])
author = form.save()
- # author object returned from form still retains original publication object
- # that's why we need to retrieve it from database again
+ # author object returned from form still retains original publication
+ # object that's why we need to retrieve it from database again
new_author = Author.objects.get(pk=author.pk)
self.assertIsNone(new_author.publication)
@@ -2607,8 +2615,8 @@ class FileAndImageFieldTests(TestCase):
)
self.assertFalse(f.is_valid())
- # Edit an instance that already has the file defined in the model. This will not
- # save the file again, but leave it exactly as it is.
+ # Edit an instance that already has the file defined in the model. This
+ # will not save the file again, but leave it exactly as it is.
f = TextFileForm({"description": "Assistance"}, instance=instance)
self.assertTrue(f.is_valid())
self.assertEqual(f.cleaned_data["file"].name, "tests/test1.txt")
@@ -2672,8 +2680,9 @@ class FileAndImageFieldTests(TestCase):
model = CustomFF
fields = "__all__"
- # It's enough that the form saves without error -- the custom save routine will
- # generate an AssertionError if it is called more than once during save.
+ # It's enough that the form saves without error -- the custom save
+ # routine will generate an AssertionError if it is called more than
+ # once during save.
form = CFFForm(data={"f": None})
form.save()
@@ -2723,9 +2732,9 @@ class FileAndImageFieldTests(TestCase):
@skipUnless(test_images, "Pillow not installed")
def test_image_field(self):
- # ImageField and FileField are nearly identical, but they differ slightly when
- # it comes to validation. This specifically tests that #6302 is fixed for
- # both file fields and image fields.
+ # ImageField and FileField are nearly identical, but they differ
+ # slightly when it comes to validation. This specifically tests that
+ # #6302 is fixed for both file fields and image fields.
with open(os.path.join(os.path.dirname(__file__), "test.png"), "rb") as fp:
image_data = fp.read()
@@ -2743,8 +2752,8 @@ class FileAndImageFieldTests(TestCase):
self.assertEqual(instance.width, 16)
self.assertEqual(instance.height, 16)
- # Delete the current file since this is not done by Django, but don't save
- # because the dimension fields are not null=True.
+ # Delete the current file since this is not done by Django, but don't
+ # save because the dimension fields are not null=True.
instance.image.delete(save=False)
f = ImageFileForm(
data={"description": "An image"},
@@ -2769,8 +2778,8 @@ class FileAndImageFieldTests(TestCase):
self.assertEqual(instance.height, 16)
self.assertEqual(instance.width, 16)
- # Delete the current file since this is not done by Django, but don't save
- # because the dimension fields are not null=True.
+ # Delete the current file since this is not done by Django, but don't
+ # save because the dimension fields are not null=True.
instance.image.delete(save=False)
# Override the file by uploading a new one.
@@ -2785,8 +2794,8 @@ class FileAndImageFieldTests(TestCase):
self.assertEqual(instance.height, 32)
self.assertEqual(instance.width, 48)
- # Delete the current file since this is not done by Django, but don't save
- # because the dimension fields are not null=True.
+ # Delete the current file since this is not done by Django, but don't
+ # save because the dimension fields are not null=True.
instance.image.delete(save=False)
instance.delete()
@@ -2800,8 +2809,8 @@ class FileAndImageFieldTests(TestCase):
self.assertEqual(instance.height, 32)
self.assertEqual(instance.width, 48)
- # Delete the current file since this is not done by Django, but don't save
- # because the dimension fields are not null=True.
+ # Delete the current file since this is not done by Django, but don't
+ # save because the dimension fields are not null=True.
instance.image.delete(save=False)
instance.delete()
@@ -2975,8 +2984,8 @@ class ModelOtherFieldTests(SimpleTestCase):
class OtherModelFormTests(TestCase):
def test_media_on_modelform(self):
- # Similar to a regular Form class you can define custom media to be used on
- # the ModelForm.
+ # Similar to a regular Form class you can define custom media to be
+ # used on the ModelForm.
f = ModelFormWithMedia()
self.assertHTMLEqual(
str(f.media),
diff --git a/tests/model_formsets/models.py b/tests/model_formsets/models.py
index a2965395d6..397bf9de53 100644
--- a/tests/model_formsets/models.py
+++ b/tests/model_formsets/models.py
@@ -195,7 +195,8 @@ class Player(models.Model):
return self.name
-# Models for testing custom ModelForm save methods in formsets and inline formsets
+# Models for testing custom ModelForm save methods in formsets and inline
+# formsets
class Poet(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py
index 748e5f5018..7722d2b3d6 100644
--- a/tests/model_formsets/tests.py
+++ b/tests/model_formsets/tests.py
@@ -104,8 +104,8 @@ class DeletionTests(TestCase):
def test_change_form_deletion_when_invalid(self):
"""
- Make sure that a change form that is filled out, but marked for deletion
- doesn't cause validation errors.
+ Make sure that a change form that is filled out, but marked for
+ deletion doesn't cause validation errors.
"""
PoetFormSet = modelformset_factory(Poet, fields="__all__", can_delete=True)
poet = Poet.objects.create(name="test")
@@ -1538,8 +1538,8 @@ class ModelFormsetTest(TestCase):
],
)
- # unique_together with inlineformset_factory with overridden form fields
- # Also see #9494
+ # unique_together with inlineformset_factory with overridden form
+ # fields Also see #9494
FormSet = inlineformset_factory(
Repository, Revision, fields=("revision",), extra=1
@@ -1564,9 +1564,10 @@ class ModelFormsetTest(TestCase):
)
formset = FormSet(instance=person)
- # Django will render a hidden field for model fields that have a callable
- # default. This is required to ensure the value is tested for change correctly
- # when determine what extra forms have changed to save.
+ # Django will render a hidden field for model fields that have a
+ # callable default. This is required to ensure the value is tested for
+ # change correctly when determine what extra forms have changed to
+ # save.
self.assertEqual(len(formset.forms), 1) # this formset only has one form
form = formset.forms[0]
@@ -1594,7 +1595,8 @@ class ModelFormsetTest(TestCase):
'id="id_membership_set-0-id"></p>' % person.id,
)
- # test for validation with callable defaults. Validations rely on hidden fields
+ # test for validation with callable defaults. Validations rely on
+ # hidden fields
data = {
"membership_set-TOTAL_FORMS": "1",
@@ -1728,8 +1730,8 @@ class ModelFormsetTest(TestCase):
)
def test_model_formset_with_custom_pk(self):
- # a formset for a Model that has a custom primary key that still needs to be
- # added to the formset automatically
+ # a formset for a Model that has a custom primary key that still needs
+ # to be added to the formset automatically
FormSet = modelformset_factory(
ClassyMexicanRestaurant, fields=["tacos_are_yummy"]
)
diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py
index 0ccc2c0490..794244b6e8 100644
--- a/tests/model_formsets_regress/tests.py
+++ b/tests/model_formsets_regress/tests.py
@@ -407,7 +407,8 @@ class BaseCustomDeleteFormSet(BaseFormSet):
A formset mix-in that lets a form decide if it's to be deleted.
Works for BaseFormSets. Also works for ModelFormSets with #14099 fixed.
- form.should_delete() is called. The formset delete field is also suppressed.
+ form.should_delete() is called. The formset delete field is also
+ suppressed.
"""
def add_fields(self, form, index):
diff --git a/tests/model_inheritance/test_abstract_inheritance.py b/tests/model_inheritance/test_abstract_inheritance.py
index 9b9da437da..2dd183a200 100644
--- a/tests/model_inheritance/test_abstract_inheritance.py
+++ b/tests/model_inheritance/test_abstract_inheritance.py
@@ -61,7 +61,8 @@ class AbstractInheritanceTests(SimpleTestCase):
def test_diamond_shaped_multiple_inheritance_is_depth_first(self):
"""
In contrast to standard Python MRO, resolution of inherited fields is
- strictly depth-first, rather than breadth-first in diamond-shaped cases.
+ strictly depth-first, rather than breadth-first in diamond-shaped
+ cases.
This is because a copy of the parent field descriptor is placed onto
the model class in ModelBase.__new__(), rather than the attribute
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index cc333a9ac2..2b911d4dc5 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -81,7 +81,8 @@ class ModelInheritanceTests(TestCase):
Restaurant.objects.filter(supplier__name="foo")
def test_model_with_distinct_accessors(self):
- # The Post model has distinct accessors for the Comment and Link models.
+ # The Post model has distinct accessors for the Comment and Link
+ # models.
post = Post.objects.create(title="Lorem Ipsum")
post.attached_comment_set.create(content="Save $ on V1agr@", is_spam=True)
post.attached_link_set.create(
@@ -194,7 +195,8 @@ class ModelInheritanceTests(TestCase):
with CaptureQueriesContext(connection) as captured_queries:
Place.objects.filter(pk=supplier.pk).update(name=supplier.name)
expected_sql = captured_queries[0]["sql"]
- # Capture the queries executed when a subclassed model instance is saved.
+ # Capture the queries executed when a subclassed model instance is
+ # saved.
with CaptureQueriesContext(connection) as captured_queries:
supplier.save(update_fields=("name",))
for query in captured_queries:
diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py
index ba31048ac2..3310497de1 100644
--- a/tests/model_inheritance_regress/tests.py
+++ b/tests/model_inheritance_regress/tests.py
@@ -439,7 +439,8 @@ class ModelInheritanceTest(TestCase):
def test_concrete_abstract_concrete_pk(self):
"""
- Primary key set correctly with concrete->abstract->concrete inheritance.
+ Primary key set correctly with concrete->abstract->concrete
+ inheritance.
"""
# Regression test for #13987: Primary key is incorrectly determined
# when more than one model has a concrete->abstract->concrete
diff --git a/tests/model_meta/tests.py b/tests/model_meta/tests.py
index 93883b5cf1..98dd132323 100644
--- a/tests/model_meta/tests.py
+++ b/tests/model_meta/tests.py
@@ -51,8 +51,8 @@ class GetFieldsTests(OptionsBaseTests):
def test_get_fields_is_immutable(self):
msg = IMMUTABLE_WARNING % "get_fields()"
for _ in range(2):
- # Running unit test twice to ensure both non-cached and cached result
- # are immutable.
+ # Running unit test twice to ensure both non-cached and cached
+ # result are immutable.
fields = Person._meta.get_fields()
with self.assertRaisesMessage(AttributeError, msg):
fields += ["errors"]
diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py
index 0592be7b4f..fbd63abfbf 100644
--- a/tests/modeladmin/test_checks.py
+++ b/tests/modeladmin/test_checks.py
@@ -791,7 +791,8 @@ class ListDisplayLinksCheckTests(CheckTestCase):
def test_list_display_links_check_skipped_if_get_list_display_overridden(self):
"""
- list_display_links check is skipped if get_list_display() is overridden.
+ list_display_links check is skipped if get_list_display() is
+ overridden.
"""
class TestModelAdmin(ModelAdmin):
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index ecead78154..4a92514e17 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -73,12 +73,13 @@ class ModelAdminTests(TestCase):
self.assertIsNone(ma.get_exclude(request, self.band))
def test_default_fieldsets(self):
- # fieldsets_add and fieldsets_change should return a special data structure that
- # is used in the templates. They should generate the "right thing" whether we
- # have specified a custom form, the fields argument, or nothing at all.
+ # fieldsets_add and fieldsets_change should return a special data
+ # structure that is used in the templates. They should generate the
+ # "right thing" whether we have specified a custom form, the fields
+ # argument, or nothing at all.
#
- # Here's the default case. There are no custom form_add/form_change methods,
- # no fields argument, and no fieldsets argument.
+ # Here's the default case. There are no custom form_add/form_change
+ # methods, no fields argument, and no fieldsets argument.
ma = ModelAdmin(Band, self.site)
self.assertEqual(
ma.get_fieldsets(request),
@@ -294,7 +295,8 @@ class ModelAdminTests(TestCase):
# Form class to the fields specified. This may cause errors to be
# raised in the db layer if required model fields aren't in fields/
# fieldsets, but that's preferable to ghost errors where a field in the
- # Form class isn't being displayed because it's not in fields/fieldsets.
+ # Form class isn't being displayed because it's not in
+ # fields/fieldsets.
# Using `fields`.
class BandAdmin(ModelAdmin):
@@ -403,7 +405,8 @@ class ModelAdminTests(TestCase):
def test_custom_form_meta_exclude(self):
"""
The custom ModelForm's `Meta.exclude` is overridden if
- `ModelAdmin.exclude` or `InlineModelAdmin.exclude` are defined (#14496).
+ `ModelAdmin.exclude` or `InlineModelAdmin.exclude` are defined
+ (#14496).
"""
# With ModelAdmin
@@ -702,9 +705,10 @@ class ModelAdminTests(TestCase):
def test_default_foreign_key_widget(self):
# First, without any radio_fields specified, the widgets for ForeignKey
# and fields with choices specified ought to be a basic Select widget.
- # ForeignKey widgets in the admin are wrapped with RelatedFieldWidgetWrapper so
- # they need to be handled properly when type checking. For Select fields, all of
- # the choices lists have a first entry of dashes.
+ # ForeignKey widgets in the admin are wrapped with
+ # RelatedFieldWidgetWrapper so they need to be handled properly when
+ # type checking. For Select fields, all of the choices lists have a
+ # first entry of dashes.
cma = ModelAdmin(Concert, self.site)
cmafa = cma.get_form(request)
@@ -732,9 +736,10 @@ class ModelAdminTests(TestCase):
def test_foreign_key_as_radio_field(self):
# Now specify all the fields as radio_fields. Widgets should now be
- # RadioSelect, and the choices list should have a first entry of 'None' if
- # blank=True for the model field. Finally, the widget should have the
- # 'radiolist' attr, and 'inline' as well if the field is specified HORIZONTAL.
+ # RadioSelect, and the choices list should have a first entry of 'None'
+ # if blank=True for the model field. Finally, the widget should have
+ # the 'radiolist' attr, and 'inline' as well if the field is specified
+ # HORIZONTAL.
class ConcertAdmin(ModelAdmin):
radio_fields = {
"main_band": HORIZONTAL,
@@ -937,8 +942,8 @@ class ModelAdminTests(TestCase):
def test_get_deleted_objects_with_custom_has_delete_permission(self):
"""
- ModelAdmin.get_deleted_objects() uses ModelAdmin.has_delete_permission()
- for permissions checking.
+ ModelAdmin.get_deleted_objects() uses
+ ModelAdmin.has_delete_permission() for permissions checking.
"""
mock_request = MockRequest()
mock_request.user = User.objects.create_superuser(
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py
index 9587030a46..85091441aa 100644
--- a/tests/multiple_database/tests.py
+++ b/tests/multiple_database/tests.py
@@ -30,7 +30,9 @@ class QueryTestCase(TestCase):
self.assertEqual(Book.objects.db_manager("other").all().db, "other")
def test_default_creation(self):
- "Objects created on the default database don't leak onto other databases"
+ """
+ Objects created on the default database don't leak onto other databases
+ """
# Create a book on the default database using create()
Book.objects.create(title="Pro Django", published=datetime.date(2008, 12, 16))
@@ -60,7 +62,10 @@ class QueryTestCase(TestCase):
Book.objects.using("other").get(title="Dive into Python")
def test_other_creation(self):
- "Objects created on another database don't leak onto the default database"
+ """
+ Objects created on another database don't leak onto the default
+ database
+ """
# Create a book on the second database
Book.objects.using("other").create(
title="Pro Django", published=datetime.date(2008, 12, 16)
@@ -419,7 +424,10 @@ class QueryTestCase(TestCase):
)
def test_m2m_cross_database_protection(self):
- "Operations that involve sharing M2M objects across databases raise an error"
+ """
+ Operations that involve sharing M2M objects across databases raise an
+ error
+ """
# Create a book and author on the default database
pro = Book.objects.create(
title="Pro Django", published=datetime.date(2008, 12, 16)
@@ -471,7 +479,9 @@ class QueryTestCase(TestCase):
dive.authors.set([mark, marty])
def test_m2m_deletion(self):
- "Cascaded deletions of m2m relations issue queries on the right database"
+ """
+ Cascaded deletions of m2m relations issue queries on the right database
+ """
# Create a book and author on the other database
dive = Book.objects.using("other").create(
title="Dive into Python", published=datetime.date(2009, 5, 4)
@@ -714,7 +724,10 @@ class QueryTestCase(TestCase):
)
def test_foreign_key_cross_database_protection(self):
- "Operations that involve sharing FK objects across databases raise an error"
+ """
+ Operations that involve sharing FK objects across databases raise an
+ error
+ """
# Create a book and author on the default database
pro = Book.objects.create(
title="Pro Django", published=datetime.date(2008, 12, 16)
@@ -854,7 +867,10 @@ class QueryTestCase(TestCase):
self.assertEqual(bob_profile.user.username, "bob")
def test_o2o_cross_database_protection(self):
- "Operations that involve sharing FK objects across databases raise an error"
+ """
+ Operations that involve sharing FK objects across databases raise an
+ error
+ """
# Create a user and profile on the default database
alice = User.objects.db_manager("default").create_user(
"alice", "alice@example.com"
@@ -891,7 +907,8 @@ class QueryTestCase(TestCase):
self.assertIsNone(new_bob_profile._state.db)
self.assertIsNone(charlie._state.db)
- # old object comes from 'other', so the new object is set to use 'other'...
+ # old object comes from 'other', so the new object is set to use
+ # 'other'...
new_bob_profile.user = bob
charlie.userprofile = bob_profile
self.assertEqual(new_bob_profile._state.db, "other")
@@ -1263,9 +1280,9 @@ class QueryTestCase(TestCase):
sub = Person.objects.using("other").filter(name="fff")
qs = Book.objects.filter(editor__in=sub)
- # When you call __str__ on the query object, it doesn't know about using
- # so it falls back to the default. If the subquery explicitly uses a
- # different database, an error should be raised.
+ # When you call __str__ on the query object, it doesn't know about
+ # using so it falls back to the default. If the subquery explicitly
+ # uses a different database, an error should be raised.
msg = (
"Subqueries aren't allowed across different databases. Force the "
"inner query to be evaluated using `list(inner_query)`."
@@ -1517,7 +1534,10 @@ class RouterTestCase(TestCase):
marty.edited.set([dive])
def test_foreign_key_cross_database_protection(self):
- "Foreign keys can cross databases if they two databases have a common source"
+ """
+ Foreign keys can cross databases if they two databases have a common
+ source
+ """
# Create a book and author on the default database
pro = Book.objects.using("default").create(
title="Pro Django", published=datetime.date(2008, 12, 16)
@@ -1548,7 +1568,8 @@ class RouterTestCase(TestCase):
# ...and the source database now has a copy of any object saved
Book.objects.using("default").get(title="Dive into Python").delete()
- # This isn't a real primary/replica database, so restore the original from other
+ # This isn't a real primary/replica database, so restore the original
+ # from other
dive = Book.objects.using("other").get(title="Dive into Python")
self.assertEqual(dive._state.db, "other")
@@ -1565,7 +1586,8 @@ class RouterTestCase(TestCase):
# ...and the source database now has a copy of any object saved
Book.objects.using("default").get(title="Dive into Python").delete()
- # This isn't a real primary/replica database, so restore the original from other
+ # This isn't a real primary/replica database, so restore the original
+ # from other
dive = Book.objects.using("other").get(title="Dive into Python")
self.assertEqual(dive._state.db, "other")
@@ -1582,7 +1604,8 @@ class RouterTestCase(TestCase):
# ...and the source database now has a copy of any object saved
Book.objects.using("default").get(title="Dive into Python").delete()
- # This isn't a real primary/replica database, so restore the original from other
+ # This isn't a real primary/replica database, so restore the original
+ # from other
dive = Book.objects.using("other").get(title="Dive into Python")
# If you assign a FK object when the base object hasn't
@@ -1629,7 +1652,8 @@ class RouterTestCase(TestCase):
)
self.assertEqual(cheesecake._state.db, "default")
- # Same goes for get_or_create, regardless of whether getting or creating
+ # Same goes for get_or_create, regardless of whether getting or
+ # creating
cheesecake, created = mark.edited.get_or_create(
title="Dive into Cheesecake",
published=datetime.date(2010, 3, 15),
@@ -1740,7 +1764,8 @@ class RouterTestCase(TestCase):
alice = dive.authors.create(name="Alice", pk=3)
self.assertEqual(alice._state.db, "default")
- # Same goes for get_or_create, regardless of whether getting or creating
+ # Same goes for get_or_create, regardless of whether getting or
+ # creating
alice, created = dive.authors.get_or_create(name="Alice")
self.assertEqual(alice._state.db, "default")
@@ -1748,7 +1773,10 @@ class RouterTestCase(TestCase):
self.assertEqual(bob._state.db, "default")
def test_o2o_cross_database_protection(self):
- "Operations that involve sharing FK objects across databases raise an error"
+ """
+ Operations that involve sharing FK objects across databases raise an
+ error
+ """
# Create a user and profile on the default database
alice = User.objects.db_manager("default").create_user(
"alice", "alice@example.com"
@@ -1807,11 +1835,13 @@ class RouterTestCase(TestCase):
# ...and the source database now has a copy of any object saved
Book.objects.using("default").get(title="Dive into Python").delete()
- # This isn't a real primary/replica database, so restore the original from other
+ # This isn't a real primary/replica database, so restore the original
+ # from other
dive = Book.objects.using("other").get(title="Dive into Python")
self.assertEqual(dive._state.db, "other")
- # Add to a generic foreign key set with an object from a different database
+ # Add to a generic foreign key set with an object from a different
+ # database
dive.reviews.add(review1)
# Database assignments of original objects haven't changed...
@@ -1834,7 +1864,8 @@ class RouterTestCase(TestCase):
# initially, no db assigned
self.assertIsNone(review3._state.db)
- # Dive comes from 'other', so review3 is set to use the source of 'other'...
+ # Dive comes from 'other', so review3 is set to use the source of
+ # 'other'...
review3.content_object = dive
self.assertEqual(review3._state.db, "default")
@@ -1846,7 +1877,10 @@ class RouterTestCase(TestCase):
self.assertEqual(nyt._state.db, "default")
def test_m2m_managers(self):
- "M2M relations are represented by managers, and can be controlled like managers"
+ """
+ M2M relations are represented by managers, and can be controlled like
+ managers
+ """
pro = Book.objects.using("other").create(
pk=1, title="Pro Django", published=datetime.date(2008, 12, 16)
)
@@ -1908,8 +1942,8 @@ class RouterTestCase(TestCase):
sub = Person.objects.filter(name="Mark Pilgrim")
qs = Book.objects.filter(editor__in=sub)
- # When you call __str__ on the query object, it doesn't know about using
- # so it falls back to the default. Don't let routing instructions
+ # When you call __str__ on the query object, it doesn't know about
+ # using so it falls back to the default. Don't let routing instructions
# force the subquery to an incompatible database.
str(qs.query)
@@ -2010,14 +2044,16 @@ class FixtureTestCase(TestCase):
@override_settings(DATABASE_ROUTERS=[AntiPetRouter()])
def test_fixture_loading(self):
"Multi-db fixtures are loaded correctly"
- # "Pro Django" exists on the default database, but not on other database
+ # "Pro Django" exists on the default database, but not on other
+ # database
Book.objects.get(title="Pro Django")
Book.objects.using("default").get(title="Pro Django")
with self.assertRaises(Book.DoesNotExist):
Book.objects.using("other").get(title="Pro Django")
- # "Dive into Python" exists on the default database, but not on other database
+ # "Dive into Python" exists on the default database, but not on other
+ # database
Book.objects.using("other").get(title="Dive into Python")
with self.assertRaises(Book.DoesNotExist):
diff --git a/tests/nested_foreign_keys/tests.py b/tests/nested_foreign_keys/tests.py
index 840d5f21fa..16823ae9b8 100644
--- a/tests/nested_foreign_keys/tests.py
+++ b/tests/nested_foreign_keys/tests.py
@@ -11,10 +11,10 @@ from .models import (
)
-# These are tests for #16715. The basic scheme is always the same: 3 models with
-# 2 relations. The first relation may be null, while the second is non-nullable.
-# In some cases, Django would pick the wrong join type for the second relation,
-# resulting in missing objects in the queryset.
+# These are tests for #16715. The basic scheme is always the same: 3 models
+# with 2 relations. The first relation may be null, while the second is
+# non-nullable. In some cases, Django would pick the wrong join type for the
+# second relation, resulting in missing objects in the queryset.
#
# Model A
# | (Relation A/B : nullable)
diff --git a/tests/null_fk/tests.py b/tests/null_fk/tests.py
index 9bf5f93f6c..ac7f7a8289 100644
--- a/tests/null_fk/tests.py
+++ b/tests/null_fk/tests.py
@@ -13,10 +13,10 @@ class NullFkTests(TestCase):
c1 = Comment.objects.create(post=p, comment_text="My first comment")
c2 = Comment.objects.create(comment_text="My second comment")
- # Starting from comment, make sure that a .select_related(...) with a specified
- # set of fields will properly LEFT JOIN multiple levels of NULLs (and the things
- # that come after the NULLs, or else data that should exist won't). Regression
- # test for #7369.
+ # Starting from comment, make sure that a .select_related(...) with a
+ # specified set of fields will properly LEFT JOIN multiple levels of
+ # NULLs (and the things that come after the NULLs, or else data that
+ # should exist won't). Regression test for #7369.
c = Comment.objects.select_related().get(id=c1.id)
self.assertEqual(c.post, p)
self.assertIsNone(Comment.objects.select_related().get(id=c2.id).post)
diff --git a/tests/null_fk_ordering/tests.py b/tests/null_fk_ordering/tests.py
index 506c8b4086..bf4c218a8c 100644
--- a/tests/null_fk_ordering/tests.py
+++ b/tests/null_fk_ordering/tests.py
@@ -20,9 +20,9 @@ class NullFkOrderingTests(TestCase):
author=author_2, title="This article written by Bob Smith"
)
- # We can't compare results directly (since different databases sort NULLs to
- # different ends of the ordering), but we can check that all results are
- # returned.
+ # We can't compare results directly (since different databases sort
+ # NULLs to different ends of the ordering), but we can check that all
+ # results are returned.
self.assertEqual(len(list(Article.objects.all())), 3)
s = SystemInfo.objects.create(system_name="System Info")
@@ -36,8 +36,8 @@ class NullFkOrderingTests(TestCase):
Comment.objects.create(comment_text="Another first comment")
Comment.objects.create(post=p2, comment_text="Another second comment")
- # We have to test this carefully. Some databases sort NULL values before
- # everything else, some sort them afterward. So we extract the ordered list
- # and check the length. Before the fix, this list was too short (some values
- # were omitted).
+ # We have to test this carefully. Some databases sort NULL values
+ # before everything else, some sort them afterward. So we extract the
+ # ordered list and check the length. Before the fix, this list was too
+ # short (some values were omitted).
self.assertEqual(len(list(Comment.objects.all())), 4)
diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py
index 451e97c274..d9bcb5d4dc 100644
--- a/tests/one_to_one/tests.py
+++ b/tests/one_to_one/tests.py
@@ -66,7 +66,8 @@ class OneToOneTests(TestCase):
self.assertEqual(repr(r.place), "<Place: Demon Dogs the place>")
def test_manager_all(self):
- # Restaurant.objects.all() just returns the Restaurants, not the Places.
+ # Restaurant.objects.all() just returns the Restaurants, not the
+ # Places.
self.assertSequenceEqual(Restaurant.objects.all(), [self.r1])
# Place.objects.all() returns all Places, regardless of whether they
# have Restaurants.
@@ -265,9 +266,10 @@ class OneToOneTests(TestCase):
del p._state.fields_cache["restaurant"]
self.assertIsNot(p.restaurant, r)
- # Reassigning the Restaurant object results in an immediate cache update
- # We can't use a new Restaurant because that'll violate one-to-one, but
- # with a new *instance* the is test below will fail if #6886 regresses.
+ # Reassigning the Restaurant object results in an immediate cache
+ # update We can't use a new Restaurant because that'll violate
+ # one-to-one, but with a new *instance* the is test below will fail if
+ # #6886 regresses.
r2 = Restaurant.objects.get(pk=r.pk)
p.restaurant = r2
self.assertIs(p.restaurant, r2)
@@ -298,8 +300,8 @@ class OneToOneTests(TestCase):
r = Restaurant(place=p)
self.assertIs(r.place, p)
- # Creation using attname keyword argument and an id will cause the related
- # object to be fetched.
+ # Creation using attname keyword argument and an id will cause the
+ # related object to be fetched.
p = Place.objects.get(name="Demon Dogs")
r = Restaurant(place_id=p.id)
self.assertIsNot(r.place, p)
@@ -483,10 +485,12 @@ class OneToOneTests(TestCase):
private_school = School.objects.create(is_public=False)
private_director = Director.objects.create(school=private_school, is_temp=True)
- # Only one school is available via all() due to the custom default manager.
+ # Only one school is available via all() due to the custom default
+ # manager.
self.assertSequenceEqual(School.objects.all(), [public_school])
- # Only one director is available via all() due to the custom default manager.
+ # Only one director is available via all() due to the custom default
+ # manager.
self.assertSequenceEqual(Director.objects.all(), [public_director])
self.assertEqual(public_director.school, public_school)
@@ -497,9 +501,9 @@ class OneToOneTests(TestCase):
# allow it.
self.assertEqual(private_director.school, private_school)
- # Make sure the base manager is used so that an student can still access
- # its related school even if the default manager doesn't normally
- # allow it.
+ # Make sure the base manager is used so that an student can still
+ # access its related school even if the default manager doesn't
+ # normally allow it.
self.assertEqual(private_school.director, private_director)
School._meta.base_manager_name = "objects"
diff --git a/tests/order_with_respect_to/base_tests.py b/tests/order_with_respect_to/base_tests.py
index 05c614f8fa..ec3793411d 100644
--- a/tests/order_with_respect_to/base_tests.py
+++ b/tests/order_with_respect_to/base_tests.py
@@ -129,7 +129,8 @@ class BaseOrderWithRespectToTests:
def test_bulk_create_with_empty_parent(self):
"""
- bulk_create() should properly set _order when parent has no existing children.
+ bulk_create() should properly set _order when parent has no existing
+ children.
"""
question = self.Question.objects.create(text="Test Question")
answers = [self.Answer(question=question, text=f"Answer {i}") for i in range(3)]
@@ -157,7 +158,8 @@ class BaseOrderWithRespectToTests:
def test_bulk_create_multiple_parents(self):
"""
- bulk_create() should maintain separate _order sequences for different parents.
+ bulk_create() should maintain separate _order sequences for different
+ parents.
"""
question0 = self.Question.objects.create(text="Question 0")
question1 = self.Question.objects.create(text="Question 1")
@@ -251,7 +253,8 @@ class BaseOrderWithRespectToTests:
# Existing answer to set initial _order=0.
self.Answer.objects.create(question=question, text="Existing Answer")
- # Two manually set _order=1 and one auto (which may also be assigned 1).
+ # Two manually set _order=1 and one auto (which may also be assigned
+ # 1).
answers = [
self.Answer(question=question, text="Manual Order 1", _order=1),
self.Answer(question=question, text="Auto Order 1"),
@@ -265,7 +268,8 @@ class BaseOrderWithRespectToTests:
# Manual values are as assigned, even if duplicated.
self.assertEqual(manual_1._order, 1)
self.assertEqual(manual_2._order, 1)
- # Auto-assigned orders may also use 1 or any value, depending on implementation.
- # If no collision logic, they may overlap with manual values.
+ # Auto-assigned orders may also use 1 or any value, depending on
+ # implementation. If no collision logic, they may overlap with manual
+ # values.
self.assertEqual(auto_1._order, 1)
self.assertEqual(auto_2._order, 2)
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index ce39c63288..267e1a5d84 100644
--- a/tests/pagination/tests.py
+++ b/tests/pagination/tests.py
@@ -170,7 +170,8 @@ class PaginationTests(SimpleTestCase):
for paginator_class in [Paginator, AsyncPaginator]:
for orphans in [2, 3]:
with self.subTest(paginator_class=paginator_class, msg=msg):
- # RemovedInDjango70Warning: When the deprecation ends, replace with:
+ # RemovedInDjango70Warning: When the deprecation ends,
+ # replace with:
# with self.assertRaisesMessage(ValueError, msg):
with self.assertWarnsMessage(RemovedInDjango70Warning, msg):
paginator_class([1, 2, 3], 2, orphans)
@@ -511,8 +512,8 @@ class PaginationTests(SimpleTestCase):
self,
):
"""
- AsyncPaginator.aget_page() raises EmptyPage if allow_empty_first_page=False
- and object_list is empty.
+ AsyncPaginator.aget_page() raises EmptyPage if
+ allow_empty_first_page=False and object_list is empty.
"""
paginator = AsyncPaginator([], 2, allow_empty_first_page=False)
with self.assertRaises(EmptyPage):
@@ -856,7 +857,8 @@ class ModelPaginationTests(TestCase):
self.assertIsNone(p.object_list._result_cache)
self.assertNotIsInstance(p.object_list, list)
- # Make sure slicing the Page object with numbers and slice objects work.
+ # Make sure slicing the Page object with numbers and slice objects
+ # work.
self.assertEqual(p[0], self.articles[0])
self.assertSequenceEqual(p[slice(2)], self.articles[:2])
# After __getitem__ is called, object_list is a list
@@ -899,7 +901,8 @@ class ModelPaginationTests(TestCase):
with self.assertWarnsMessage(UnorderedObjectListWarning, msg) as cm:
AsyncPaginator(Article.objects.all(), 5)
# The warning points at the BasePaginator caller.
- # The reason is that the UnorderedObjectListWarning occurs in BasePaginator.
+ # The reason is that the UnorderedObjectListWarning occurs in
+ # BasePaginator.
base_paginator_path = pathlib.Path(inspect.getfile(BasePaginator))
self.assertIn(
cm.filename,
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 745ae6090a..392b8f946c 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -973,7 +973,8 @@ class TestMigrations(TransactionTestCase):
)
def test_adding_arrayfield_with_index(self):
"""
- ArrayField shouldn't have varchar_patterns_ops or text_patterns_ops indexes.
+ ArrayField shouldn't have varchar_patterns_ops or text_patterns_ops
+ indexes.
"""
table_name = "postgres_tests_chartextarrayindexmodel"
call_command("migrate", "postgres_tests", verbosity=0)
diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py
index 472dca6c7b..a7118e7c79 100644
--- a/tests/postgres_tests/test_search.py
+++ b/tests/postgres_tests/test_search.py
@@ -602,8 +602,8 @@ class TestRankingAndWeights(GrailTestData, PostgreSQLTestCase):
rank=SearchRank(
SearchVector("dialogue"),
SearchQuery("brave sir robin"),
- # Divide the rank by the document length and by the number of
- # unique words in document.
+ # Divide the rank by the document length and by the number
+ # of unique words in document.
normalization=Value(2).bitor(Value(8)),
),
)
diff --git a/tests/prefetch_related/test_uuid.py b/tests/prefetch_related/test_uuid.py
index f22b2158a5..a1593ea2a7 100644
--- a/tests/prefetch_related/test_uuid.py
+++ b/tests/prefetch_related/test_uuid.py
@@ -77,7 +77,8 @@ class UUIDPrefetchRelatedLookups(TestCase):
def test_from_uuid_pk_lookup_integer_pk2_uuid_pk2(self):
# From uuid-pk model, prefetch
- # <integer-pk model>.<integer-pk model>.<uuid-pk model>.<uuid-pk model>:
+ # <integer-pk model>.<integer-pk model>.<uuid-pk model>.<uuid-pk
+ # model>:
with self.assertNumQueries(5):
spooky = Pet.objects.prefetch_related("people__houses__rooms__fleas").get(
name="Spooky"
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py
index 1955809aec..5db383c746 100644
--- a/tests/prefetch_related/tests.py
+++ b/tests/prefetch_related/tests.py
@@ -486,9 +486,10 @@ class CustomPrefetchTests(TestCase):
@classmethod
def traverse_qs(cls, obj_iter, path):
"""
- Helper method that returns a list containing a list of the objects in the
- obj_iter. Then for each object in the obj_iter, the path will be
- recursively travelled and the found objects are added to the return value.
+ Helper method that returns a list containing a list of the objects in
+ the obj_iter. Then for each object in the obj_iter, the path will be
+ recursively travelled and the found objects are added to the return
+ value.
"""
ret_val = []
@@ -1064,7 +1065,8 @@ class CustomPrefetchTests(TestCase):
Prefetch("houses", House.objects.values("pk"))
with self.assertRaisesMessage(ValueError, msg):
Prefetch("houses", House.objects.values_list("pk"))
- # That error doesn't affect managers with custom ModelIterable subclasses
+ # That error doesn't affect managers with custom ModelIterable
+ # subclasses
self.assertIs(
Teacher.objects_custom.all()._iterable_class, ModelIterableSubclass
)
@@ -1134,8 +1136,8 @@ class DefaultManagerTests(TestCase):
def test_m2m_then_m2m(self):
with self.assertNumQueries(3):
# When we prefetch the teachers, and force the query, we don't want
- # the default manager on teachers to immediately get all the related
- # qualifications, since this will do one query per teacher.
+ # the default manager on teachers to immediately get all the
+ # related qualifications, since this will do one query per teacher.
qs = Department.objects.prefetch_related("teachers")
depts = "".join(
"%s department: %s\n"
@@ -1396,9 +1398,9 @@ class MultiTableInheritanceTest(TestCase):
for a in Author.objects.prefetch_related("authorwithage")
]
- # Regression for #18090: the prefetching query must include an IN clause.
- # Note that on Oracle the table name is upper case in the generated SQL,
- # thus the .lower() call.
+ # Regression for #18090: the prefetching query must include an IN
+ # clause. Note that on Oracle the table name is upper case in the
+ # generated SQL, thus the .lower() call.
self.assertIn("authorwithage", connection.queries[-1]["sql"].lower())
self.assertIn(" IN ", connection.queries[-1]["sql"])
@@ -1492,8 +1494,9 @@ class LookupOrderingTest(TestCase):
def test_order(self):
with self.assertNumQueries(4):
- # The following two queries must be done in the same order as written,
- # otherwise 'primary_house' will cause non-prefetched lookups
+ # The following two queries must be done in the same order as
+ # written, otherwise 'primary_house' will cause non-prefetched
+ # lookups
qs = Person.objects.prefetch_related(
"houses__rooms", "primary_house__occupants"
)
@@ -1509,7 +1512,8 @@ class NullableTest(TestCase):
def test_traverse_nullable(self):
# Because we use select_related() for 'boss', it doesn't need to be
- # prefetched, but we can still traverse it although it contains some nulls
+ # prefetched, but we can still traverse it although it contains some
+ # nulls
with self.assertNumQueries(2):
qs = Employee.objects.select_related("boss").prefetch_related("boss__serfs")
co_serfs = [
@@ -1816,8 +1820,8 @@ class DirectPrefetchedObjectCacheReuseTests(TestCase):
def test_detect_is_fetched(self):
"""
- Nested prefetch_related() shouldn't trigger duplicate queries for the same
- lookup.
+ Nested prefetch_related() shouldn't trigger duplicate queries for the
+ same lookup.
"""
with self.assertNumQueries(3):
books = Book.objects.filter(title__in=["book1", "book2"]).prefetch_related(
diff --git a/tests/proxy_model_inheritance/tests.py b/tests/proxy_model_inheritance/tests.py
index fc1826e9e9..2e2d186c3c 100644
--- a/tests/proxy_model_inheritance/tests.py
+++ b/tests/proxy_model_inheritance/tests.py
@@ -14,9 +14,10 @@ from .models import (
class ProxyModelInheritanceTests(TransactionTestCase):
"""
- Proxy model inheritance across apps can result in migrate not creating the table
- for the proxied model (as described in #12286). This test creates two dummy
- apps and calls migrate, then verifies that the table has been created.
+ Proxy model inheritance across apps can result in migrate not creating the
+ table for the proxied model (as described in #12286). This test creates two
+ dummy apps and calls migrate, then verifies that the table has been
+ created.
"""
available_apps = []
diff --git a/tests/proxy_models/models.py b/tests/proxy_models/models.py
index c0277e093f..ac6444fbef 100644
--- a/tests/proxy_models/models.py
+++ b/tests/proxy_models/models.py
@@ -130,7 +130,8 @@ class MultiUserProxy(UserProxy, AnotherUserProxy):
proxy = True
-# We can still use `select_related()` to include related models in our querysets.
+# We can still use `select_related()` to include related models in our
+# querysets.
class Country(models.Model):
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 38b0a5ddfa..4158a9a596 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -136,8 +136,8 @@ class Queries1Tests(TestCase):
ann2 = Annotation.objects.create(name="a2", tag=cls.t4)
ann2.notes.add(cls.n2, cls.n3)
- # Create these out of order so that sorting by 'id' will be different to sorting
- # by 'info'. Helps detect some problems later.
+ # Create these out of order so that sorting by 'id' will be different
+ # to sorting by 'info'. Helps detect some problems later.
cls.e2 = ExtraInfo.objects.create(
info="e2", note=cls.n2, value=41, filterable=False
)
@@ -176,8 +176,8 @@ class Queries1Tests(TestCase):
cls.r2 = Report.objects.create(name="r2", creator=cls.a3)
cls.r3 = Report.objects.create(name="r3")
- # Ordering by 'rank' gives us rank2, rank1, rank3. Ordering by the Meta.ordering
- # will be rank3, rank2, rank1.
+ # Ordering by 'rank' gives us rank2, rank1, rank3. Ordering by the
+ # Meta.ordering will be rank3, rank2, rank1.
cls.rank1 = Ranking.objects.create(rank=2, author=cls.a2)
cls.c1 = Cover.objects.create(title="first", item=cls.i4)
@@ -240,9 +240,9 @@ class Queries1Tests(TestCase):
[self.i1],
)
- # Each filter call is processed "at once" against a single table, so this is
- # different from the previous example as it tries to find tags that are two
- # things at once (rather than two tags).
+ # Each filter call is processed "at once" against a single table, so
+ # this is different from the previous example as it tries to find tags
+ # that are two things at once (rather than two tags).
self.assertSequenceEqual(
Item.objects.filter(Q(tags=self.t1) & Q(tags=self.t2)), []
)
@@ -306,16 +306,17 @@ class Queries1Tests(TestCase):
)
def test_ticket6074(self):
- # Merging two empty result sets shouldn't leave a queryset with no constraints
- # (which would match everything).
+ # Merging two empty result sets shouldn't leave a queryset with no
+ # constraints (which would match everything).
self.assertSequenceEqual(Author.objects.filter(Q(id__in=[])), [])
self.assertSequenceEqual(Author.objects.filter(Q(id__in=[]) | Q(id__in=[])), [])
def test_tickets_1878_2939(self):
self.assertEqual(Item.objects.values("creator").distinct().count(), 3)
- # Create something with a duplicate 'name' so that we can test multi-column
- # cases (which require some tricky SQL transformations under the covers).
+ # Create something with a duplicate 'name' so that we can test
+ # multi-column cases (which require some tricky SQL transformations
+ # under the covers).
xx = Item(name="four", created=self.time1, creator=self.a2, note=self.n1)
xx.save()
self.assertEqual(
@@ -491,7 +492,8 @@ class Queries1Tests(TestCase):
[self.i3],
)
- # Excluding from a relation that cannot be NULL should not use outer joins.
+ # Excluding from a relation that cannot be NULL should not use outer
+ # joins.
query = Item.objects.exclude(creator__in=[self.a1, self.a2]).query
self.assertNotIn(LOUTER, [x.join_type for x in query.alias_map.values()])
@@ -586,8 +588,8 @@ class Queries1Tests(TestCase):
)
def test_heterogeneous_qs_combination(self):
- # Combining querysets built on different models should behave in a well-defined
- # fashion. We raise an error.
+ # Combining querysets built on different models should behave in a
+ # well-defined fashion. We raise an error.
msg = "Cannot combine queries on two different base models."
with self.assertRaisesMessage(TypeError, msg):
Author.objects.all() & Tag.objects.all()
@@ -641,8 +643,8 @@ class Queries1Tests(TestCase):
# case, Cover is ordered by Item's default, which uses Note's default).
self.assertSequenceEqual(Cover.objects.all(), [self.c1, self.c2])
- # If the remote model does not have a default ordering, we order by its 'id'
- # field.
+ # If the remote model does not have a default ordering, we order by its
+ # 'id' field.
self.assertSequenceEqual(
Item.objects.order_by("creator", "name"),
[self.i1, self.i3, self.i2, self.i4],
@@ -1139,7 +1141,8 @@ class Queries1Tests(TestCase):
self.assertEqual(str(q.query).count("LEFT OUTER JOIN"), 0)
self.assertEqual(str(q.query).count("INNER JOIN"), 1)
- # Querying without isnull should not convert anything to left outer join.
+ # Querying without isnull should not convert anything to left outer
+ # join.
q = Tag.objects.filter(parent__parent=self.t1)
self.assertSequenceEqual(q, [self.t4, self.t5])
self.assertEqual(str(q.query).count("LEFT OUTER JOIN"), 0)
@@ -1173,7 +1176,8 @@ class Queries1Tests(TestCase):
self.assertNotIn("INNER JOIN", str(q.query))
def test_ticket_10790_5(self):
- # Querying with isnull=False across m2m field should not create outer joins
+ # Querying with isnull=False across m2m field should not create outer
+ # joins
q = Author.objects.filter(item__tags__isnull=False)
self.assertSequenceEqual(q, [self.a1, self.a1, self.a2, self.a2, self.a4])
self.assertEqual(str(q.query).count("LEFT OUTER JOIN"), 0)
@@ -1190,8 +1194,8 @@ class Queries1Tests(TestCase):
self.assertEqual(str(q.query).count("INNER JOIN"), 4)
def test_ticket_10790_6(self):
- # Querying with isnull=True across m2m field should not create inner joins
- # and strip last outer join
+ # Querying with isnull=True across m2m field should not create inner
+ # joins and strip last outer join
q = Author.objects.filter(item__tags__parent__parent__isnull=True)
self.assertSequenceEqual(
q,
@@ -1218,7 +1222,8 @@ class Queries1Tests(TestCase):
self.assertEqual(str(q.query).count("INNER JOIN"), 1)
def test_ticket_10790_8(self):
- # Querying with combined q-objects should also strip the left outer join
+ # Querying with combined q-objects should also strip the left outer
+ # join
q = Tag.objects.filter(Q(parent__isnull=True) | Q(parent=self.t1))
self.assertSequenceEqual(q, [self.t1, self.t2, self.t3])
self.assertEqual(str(q.query).count("LEFT OUTER JOIN"), 0)
@@ -1656,14 +1661,15 @@ class Queries4Tests(TestCase):
self.assertEqual(obj.person.details.data, "d2")
def test_order_by_resetting(self):
- # Calling order_by() with no parameters removes any existing ordering on the
- # model. But it should still be possible to add new ordering after that.
+ # Calling order_by() with no parameters removes any existing ordering
+ # on the model. But it should still be possible to add new ordering
+ # after that.
qs = Author.objects.order_by().order_by("name")
self.assertIn("ORDER BY", qs.query.get_compiler(qs.db).as_sql()[0])
def test_order_by_reverse_fk(self):
- # It is possible to order by reverse of foreign key, although that can lead
- # to duplicate results.
+ # It is possible to order by reverse of foreign key, although that can
+ # lead to duplicate results.
c1 = SimpleCategory.objects.create(name="category1")
c2 = SimpleCategory.objects.create(name="category2")
CategoryItem.objects.create(category=c1)
@@ -2051,8 +2057,8 @@ class DisjunctiveFilterTests(TestCase):
def test_ticket7872(self):
# Another variation on the disjunctive filtering theme.
- # For the purposes of this regression test, it's important that there is no
- # Join object related to the LeafA we create.
+ # For the purposes of this regression test, it's important that there
+ # is no Join object related to the LeafA we create.
l1 = LeafA.objects.create(data="first")
self.assertSequenceEqual(LeafA.objects.all(), [l1])
self.assertSequenceEqual(
@@ -2108,8 +2114,9 @@ class Queries6Tests(TestCase):
self.assertFalse(qs)
def test_nested_queries_sql(self):
- # Nested queries should not evaluate the inner query as part of constructing the
- # SQL (so we should see a nested query here, indicated by two "SELECT" calls).
+ # Nested queries should not evaluate the inner query as part of
+ # constructing the SQL (so we should see a nested query here, indicated
+ # by two "SELECT" calls).
qs = Annotation.objects.filter(notes__in=Note.objects.filter(note="xyzzy"))
self.assertEqual(qs.query.get_compiler(qs.db).as_sql()[0].count("SELECT"), 2)
@@ -2130,8 +2137,9 @@ class Queries6Tests(TestCase):
[self.t1, self.t3],
)
- # This example is tricky because the parent could be NULL, so only checking
- # parents with annotations omits some results (tag t1, in this case).
+ # This example is tricky because the parent could be NULL, so only
+ # checking parents with annotations omits some results (tag t1, in this
+ # case).
self.assertSequenceEqual(
Tag.objects.exclude(parent__annotation__name="a1"),
[self.t1, self.t4, self.t5],
@@ -2215,7 +2223,8 @@ class RawQueriesTests(TestCase):
Note.objects.create(note="n1", misc="foo", id=1)
def test_ticket14729(self):
- # Test representation of raw query with one or few parameters passed as list
+ # Test representation of raw query with one or few parameters passed as
+ # list
query = "SELECT * FROM queries_note WHERE note = %s"
params = ["n1"]
qs = Note.objects.raw(query, params=params)
@@ -2579,7 +2588,8 @@ class QuerySetBitwiseOperationTests(TestCase):
class CloneTests(TestCase):
def test_evaluated_queryset_as_argument(self):
"""
- If a queryset is already evaluated, it can still be used as a query arg.
+ If a queryset is already evaluated, it can still be used as a query
+ arg.
"""
n = Note(note="Test1", misc="misc")
n.save()
@@ -3124,8 +3134,8 @@ class ConditionalTests(TestCase):
# recursive).
self.assertSequenceEqual(LoopX.objects.order_by("y__x__y__x__id"), [])
- # When grouping without specifying ordering, we add an explicit "ORDER BY NULL"
- # portion in MySQL to prevent unnecessary sorting.
+ # When grouping without specifying ordering, we add an explicit "ORDER BY
+ # NULL" portion in MySQL to prevent unnecessary sorting.
@skipUnlessDBFeature("requires_explicit_null_ordering_when_grouping")
def test_null_ordering_added(self):
query = Tag.objects.values_list("parent_id", flat=True).order_by().query
diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py
index 337c5193ce..acdb582a0a 100644
--- a/tests/queryset_pickle/tests.py
+++ b/tests/queryset_pickle/tests.py
@@ -181,8 +181,8 @@ class PickleabilityTestCase(TestCase):
def test_pickle_prefetch_related_with_m2m_and_objects_deletion(self):
"""
- #24831 -- Cached properties on ManyToOneRel created in QuerySet.delete()
- caused subsequent QuerySet pickling to fail.
+ #24831 -- Cached properties on ManyToOneRel created in
+ QuerySet.delete() caused subsequent QuerySet pickling to fail.
"""
g = Group.objects.create(name="foo")
m2m = M2MModel.objects.create()
diff --git a/tests/requests_tests/test_accept_header.py b/tests/requests_tests/test_accept_header.py
index f6febc937a..2699e7a390 100644
--- a/tests/requests_tests/test_accept_header.py
+++ b/tests/requests_tests/test_accept_header.py
@@ -346,7 +346,8 @@ class AcceptHeaderTests(TestCase):
def test_quality_for_media_type_rfc9110(self):
"""
- Taken from https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.1-18.
+ Taken from
+ https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.1-18.
"""
request = HttpRequest()
request.META["HTTP_ACCEPT"] = (
diff --git a/tests/requests_tests/tests.py b/tests/requests_tests/tests.py
index e4540de6ee..7e615617d7 100644
--- a/tests/requests_tests/tests.py
+++ b/tests/requests_tests/tests.py
@@ -424,9 +424,9 @@ class RequestsTests(SimpleTestCase):
"""
Reading body after parsing multipart/form-data is not allowed
"""
- # Because multipart is used for large amounts of data i.e. file uploads,
- # we don't want the data held in memory twice, and we don't want to
- # silence the error by setting body = '' either.
+ # Because multipart is used for large amounts of data i.e. file
+ # uploads, we don't want the data held in memory twice, and we don't
+ # want to silence the error by setting body = '' either.
payload = FakePayload(
"\r\n".join(
[
@@ -881,7 +881,8 @@ class RequestsTests(SimpleTestCase):
def test_POST_after_body_read_and_stream_read_multipart(self):
"""
POST should be populated even if body is read first, and then
- the stream is read second. Using multipart/form-data instead of urlencoded.
+ the stream is read second. Using multipart/form-data instead of
+ urlencoded.
"""
payload = FakePayload(
"\r\n".join(
diff --git a/tests/runtests.py b/tests/runtests.py
index ceb88853b7..679f5269ca 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -715,7 +715,8 @@ if __name__ == "__main__":
if options.screenshots and options.tags:
parser.error("--screenshots and --tag are mutually exclusive.")
- # Allow including a trailing slash on app_labels for tab completion convenience
+ # Allow including a trailing slash on app_labels for tab completion
+ # convenience
options.modules = [os.path.normpath(labels) for labels in options.modules]
mutually_exclusive_options = [
diff --git a/tests/schema/fields.py b/tests/schema/fields.py
index 24a26b2c2c..10b6451cbd 100644
--- a/tests/schema/fields.py
+++ b/tests/schema/fields.py
@@ -84,7 +84,8 @@ class CustomManyToManyField(RelatedField):
def get_internal_type(self):
return "ManyToManyField"
- # Copy those methods from ManyToManyField because they don't call super() internally
+ # Copy those methods from ManyToManyField because they don't call super()
+ # internally
contribute_to_related_class = models.ManyToManyField.__dict__[
"contribute_to_related_class"
]
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index dbed4b709d..a06553e680 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -677,7 +677,8 @@ class SchemaTests(TransactionTestCase):
def test_add_field_remove_field(self):
"""
- Adding a field and removing it removes all deferred sql referring to it.
+ Adding a field and removing it removes all deferred sql referring to
+ it.
"""
with connection.schema_editor() as editor:
# Create a table with a unique constraint on the slug field.
@@ -762,7 +763,8 @@ class SchemaTests(TransactionTestCase):
# Add some rows of data
Author.objects.create(name="Andrew", height=30)
Author.objects.create(name="Andrea")
- # Add the field with a default it needs to cast (to string in this case)
+ # Add the field with a default it needs to cast (to string in this
+ # case)
new_field = TestTransformField(default={1: 2})
new_field.set_attributes_from_name("thing")
with connection.schema_editor() as editor:
@@ -1317,7 +1319,8 @@ class SchemaTests(TransactionTestCase):
def test_alter_null_to_not_null(self):
"""
- #23609 - Tests handling of default values when altering from NULL to NOT NULL.
+ #23609 - Tests handling of default values when altering from NULL to
+ NOT NULL.
"""
# Create the table
with connection.schema_editor() as editor:
@@ -3642,8 +3645,8 @@ class SchemaTests(TransactionTestCase):
@skipIfDBFeature("supports_expression_indexes")
def test_func_unique_constraint_unsupported(self):
- # UniqueConstraint is ignored on databases that don't support indexes on
- # expressions.
+ # UniqueConstraint is ignored on databases that don't support indexes
+ # on expressions.
with connection.schema_editor() as editor:
editor.create_model(Author)
constraint = UniqueConstraint(F("name"), name="func_name_uq")
@@ -4530,7 +4533,8 @@ class SchemaTests(TransactionTestCase):
def test_remove_constraints_capital_letters(self):
"""
- #23065 - Constraint names must be quoted if they contain capital letters.
+ #23065 - Constraint names must be quoted if they contain capital
+ letters.
"""
def get_field(*args, field_class=IntegerField, **kwargs):
@@ -4622,7 +4626,8 @@ class SchemaTests(TransactionTestCase):
self.assertNotIn("surname", columns)
# Create a row
Author.objects.create(name="Anonymous1")
- # Add new CharField to ensure default will be used from effective_default
+ # Add new CharField to ensure default will be used from
+ # effective_default
new_field = CharField(max_length=15, blank=True)
new_field.set_attributes_from_name("surname")
with connection.schema_editor() as editor:
@@ -5175,7 +5180,8 @@ class SchemaTests(TransactionTestCase):
self.get_constraints_for_column(BookWithoutAuthor, "title"),
["schema_book_title_2dfb2dff_like", "schema_book_title_2dfb2dff_uniq"],
)
- # Alter to remove both unique=True and db_index=True (should drop all indexes)
+ # Alter to remove both unique=True and db_index=True (should drop all
+ # indexes)
new_field2 = CharField(max_length=100)
new_field2.set_attributes_from_name("title")
with connection.schema_editor() as editor:
@@ -5193,7 +5199,8 @@ class SchemaTests(TransactionTestCase):
self.get_constraints_for_column(BookWithoutAuthor, "title"),
["schema_book_title_2dfb2dff", "schema_book_title_2dfb2dff_like"],
)
- # Alter to set unique=True and remove db_index=True (should replace the index)
+ # Alter to set unique=True and remove db_index=True (should replace the
+ # index)
old_field = BookWithoutAuthor._meta.get_field("title")
new_field = CharField(max_length=100, unique=True)
new_field.set_attributes_from_name("title")
@@ -5203,7 +5210,8 @@ class SchemaTests(TransactionTestCase):
self.get_constraints_for_column(BookWithoutAuthor, "title"),
["schema_book_title_2dfb2dff_like", "schema_book_title_2dfb2dff_uniq"],
)
- # Alter to set db_index=True and remove unique=True (should restore index)
+ # Alter to set db_index=True and remove unique=True (should restore
+ # index)
new_field2 = CharField(max_length=100, db_index=True)
new_field2.set_attributes_from_name("title")
with connection.schema_editor() as editor:
diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py
index 1bc87113ba..460e279770 100644
--- a/tests/select_for_update/tests.py
+++ b/tests/select_for_update/tests.py
@@ -602,8 +602,8 @@ class SelectForUpdateTests(TransactionTestCase):
# find that it has updated the person's name.
self.assertFalse(thread.is_alive())
- # We must commit the transaction to ensure that MySQL gets a fresh read,
- # since by default it runs in REPEATABLE READ mode
+ # We must commit the transaction to ensure that MySQL gets a fresh
+ # read, since by default it runs in REPEATABLE READ mode
transaction.commit()
p = Person.objects.get(pk=self.person.pk)
diff --git a/tests/select_related_regress/tests.py b/tests/select_related_regress/tests.py
index 94a15bde24..b271c5b48c 100644
--- a/tests/select_related_regress/tests.py
+++ b/tests/select_related_regress/tests.py
@@ -32,12 +32,12 @@ class SelectRelatedRegressTests(TestCase):
Regression test for bug #7110.
When using select_related(), we must query the
- Device and Building tables using two different aliases (each) in order to
- differentiate the start and end Connection fields. The net result is that
- both the "connections = ..." queries here should give the same results
- without pulling in more than the absolute minimum number of tables
- (history has shown that it's easy to make a mistake in the implementation
- and include some unnecessary bonus joins).
+ Device and Building tables using two different aliases (each) in order
+ to differentiate the start and end Connection fields. The net result is
+ that both the "connections = ..." queries here should give the same
+ results without pulling in more than the absolute minimum number of
+ tables (history has shown that it's easy to make a mistake in the
+ implementation and include some unnecessary bonus joins).
"""
b = Building.objects.create(name="101")
@@ -70,8 +70,9 @@ class SelectRelatedRegressTests(TestCase):
[(c1.id, "router/4", "switch/7"), (c2.id, "switch/7", "server/1")],
)
- # This final query should only have seven tables (port, device and building
- # twice each, plus connection once). Thus, 6 joins plus the FROM table.
+ # This final query should only have seven tables (port, device and
+ # building twice each, plus connection once). Thus, 6 joins plus the
+ # FROM table.
self.assertEqual(str(connections.query).count(" JOIN "), 6)
def test_regression_8106(self):
@@ -102,8 +103,8 @@ class SelectRelatedRegressTests(TestCase):
the first related model in the tests below
("state") is empty and we try to select the more remotely related
- state__country. The regression here was not skipping the empty column results
- for country before getting status.
+ state__country. The regression here was not skipping the empty column
+ results for country before getting status.
"""
Country.objects.create(name="Australia")
diff --git a/tests/serializers/test_data.py b/tests/serializers/test_data.py
index 6a6de18033..c626f2550a 100644
--- a/tests/serializers/test_data.py
+++ b/tests/serializers/test_data.py
@@ -241,8 +241,8 @@ def inherited_compare(testcase, pk, klass, data):
testcase.assertEqual(value, getattr(instance, key))
-# Define some test helpers. Each has a pair of functions: one to create objects and one
-# to make assertions against objects of a particular type.
+# Define some test helpers. Each has a pair of functions: one to create objects
+# and one to make assertions against objects of a particular type.
TestHelper = namedtuple("TestHelper", ["create_object", "compare_object"])
data_obj = TestHelper(data_create, data_compare)
generic_obj = TestHelper(generic_create, generic_compare)
diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py
index 65d521faac..2c8ad5708e 100644
--- a/tests/serializers/test_json.py
+++ b/tests/serializers/test_json.py
@@ -188,7 +188,8 @@ class JsonSerializerTestCase(SerializersTestBase, TestCase):
def test_helpful_error_message_for_many2many_natural1(self):
"""
Invalid many-to-many keys should throw a helpful error message.
- This tests the code path where one of a list of natural keys is invalid.
+ This tests the code path where one of a list of natural keys is
+ invalid.
"""
test_string = """[{
"pk": 1,
diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
index 04d6b4e9ee..4638cd93aa 100644
--- a/tests/serializers/tests.py
+++ b/tests/serializers/tests.py
@@ -391,7 +391,9 @@ class SerializersTestBase:
self.assertEqual(Category.objects.count(), 5)
def test_deterministic_mapping_ordering(self):
- """Mapping such as fields should be deterministically ordered. (#24558)"""
+ """
+ Mapping such as fields should be deterministically ordered. (#24558)
+ """
output = serializers.serialize(self.serializer_name, [self.a1], indent=2)
categories = self.a1.categories.values_list("pk", flat=True)
self.assertEqual(
@@ -406,7 +408,9 @@ class SerializersTestBase:
)
def test_deserialize_force_insert(self):
- """Deserialized content can be saved with force_insert as a parameter."""
+ """
+ Deserialized content can be saved with force_insert as a parameter.
+ """
serial_str = serializers.serialize(self.serializer_name, [self.a1])
deserial_obj = list(serializers.deserialize(self.serializer_name, serial_str))[
0
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 05898009d5..0ddf55df6f 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -198,8 +198,9 @@ class LiveServerViews(LiveServerBase):
development server is rather simple we support it only in cases where
we can detect a content length from the response. This should be doable
for all simple views and streaming responses where an iterable with
- length of one is passed. The latter follows as result of `set_content_length`
- from https://github.com/python/cpython/blob/main/Lib/wsgiref/handlers.py.
+ length of one is passed. The latter follows as result of
+ `set_content_length` from
+ https://github.com/python/cpython/blob/main/Lib/wsgiref/handlers.py.
If we cannot detect a content length we explicitly set the `Connection`
header to `close` to notify the client that we do not actually support
diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py
index 9eabb933a8..81c2e7a5de 100644
--- a/tests/sessions_tests/tests.py
+++ b/tests/sessions_tests/tests.py
@@ -41,9 +41,9 @@ from .models import SessionStore as CustomDatabaseSession
class SessionTestsMixin:
- # This does not inherit from TestCase to avoid any tests being run with this
- # class, which wouldn't work, and to allow different TestCase subclasses to
- # be used.
+ # This does not inherit from TestCase to avoid any tests being run with
+ # this class, which wouldn't work, and to allow different TestCase
+ # subclasses to be used.
backend = None # subclasses must specify
@@ -326,8 +326,8 @@ class SessionTestsMixin:
self.assertEqual(await self.session.aget("a"), "b")
def test_invalid_key(self):
- # Submitting an invalid session key (either by guessing, or if the db has
- # removed the key) results in a new key being generated.
+ # Submitting an invalid session key (either by guessing, or if the db
+ # has removed the key) results in a new key being generated.
try:
session = self.backend("1")
session.save()
@@ -340,8 +340,8 @@ class SessionTestsMixin:
session.delete("1")
async def test_invalid_key_async(self):
- # Submitting an invalid session key (either by guessing, or if the db has
- # removed the key) results in a new key being generated.
+ # Submitting an invalid session key (either by guessing, or if the db
+ # has removed the key) results in a new key being generated.
try:
session = self.backend("1")
await session.asave()
@@ -490,8 +490,8 @@ class SessionTestsMixin:
)
def test_get_expire_at_browser_close(self):
- # Tests get_expire_at_browser_close with different settings and different
- # set_expiry calls
+ # Tests get_expire_at_browser_close with different settings and
+ # different set_expiry calls
with override_settings(SESSION_EXPIRE_AT_BROWSER_CLOSE=False):
self.session.set_expiry(10)
self.assertIs(self.session.get_expire_at_browser_close(), False)
@@ -513,8 +513,8 @@ class SessionTestsMixin:
self.assertIs(self.session.get_expire_at_browser_close(), True)
async def test_get_expire_at_browser_close_async(self):
- # Tests get_expire_at_browser_close with different settings and different
- # set_expiry calls
+ # Tests get_expire_at_browser_close with different settings and
+ # different set_expiry calls
with override_settings(SESSION_EXPIRE_AT_BROWSER_CLOSE=False):
await self.session.aset_expiry(10)
self.assertIs(await self.session.aget_expire_at_browser_close(), False)
@@ -868,7 +868,8 @@ class FileSessionTests(SessionTestsMixin, SimpleTestCase):
backend = FileSession
def setUp(self):
- # Do file session tests in an isolated directory, and kill it after we're done.
+ # Do file session tests in an isolated directory, and kill it after
+ # we're done.
self.original_session_file_path = settings.SESSION_FILE_PATH
self.temp_session_store = settings.SESSION_FILE_PATH = self.mkdtemp()
self.addCleanup(shutil.rmtree, self.temp_session_store)
@@ -1247,7 +1248,8 @@ class CookieSessionTests(SessionTestsMixin, SimpleTestCase):
@unittest.expectedFailure
def test_actual_expiry(self):
- # The cookie backend doesn't handle non-default expiry dates, see #19201
+ # The cookie backend doesn't handle non-default expiry dates, see
+ # #19201
super().test_actual_expiry()
async def test_actual_expiry_async(self):
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index c1fe2d042d..7794aeef9a 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -205,7 +205,8 @@ class SettingsTests(SimpleTestCase):
getattr(settings, "TEST")
def test_class_decorator(self):
- # SimpleTestCase can be decorated by override_settings, but not ut.TestCase
+ # SimpleTestCase can be decorated by override_settings, but not
+ # ut.TestCase
class SimpleTestCaseSubclass(SimpleTestCase):
pass
@@ -467,7 +468,8 @@ class IsOverriddenTest(SimpleTestCase):
class TestListSettings(SimpleTestCase):
"""
Make sure settings that should be lists or tuples throw
- ImproperlyConfigured if they are set to a string instead of a list or tuple.
+ ImproperlyConfigured if they are set to a string instead of a list or
+ tuple.
"""
list_or_tuple_settings = (
diff --git a/tests/signals/tests.py b/tests/signals/tests.py
index 6c90c6aa52..7cb64f6e05 100644
--- a/tests/signals/tests.py
+++ b/tests/signals/tests.py
@@ -16,7 +16,8 @@ from .models import Author, Book, Car, Page, Person
class BaseSignalSetup:
def setUp(self):
# Save up the number of connected signals so that we can check at the
- # end that all the signals we register get properly unregistered (#9989)
+ # end that all the signals we register get properly unregistered
+ # (#9989)
self.pre_signals = (
len(signals.pre_save.receivers),
len(signals.post_save.receivers),
@@ -88,7 +89,8 @@ class SignalTests(BaseSignalSetup, TestCase):
)
data[:] = []
- # Calling an internal method purely so that we can trigger a "raw" save.
+ # Calling an internal method purely so that we can trigger a "raw"
+ # save.
p1.save_base(raw=True)
self.assertEqual(
data,
@@ -341,7 +343,8 @@ class SignalTests(BaseSignalSetup, TestCase):
)
data[:] = []
- # Assigning and removing to/from m2m shouldn't generate an m2m signal.
+ # Assigning and removing to/from m2m shouldn't generate an m2m
+ # signal.
b1.authors.set([a1])
self.assertEqual(data, [])
b1.authors.set([])
diff --git a/tests/sites_tests/tests.py b/tests/sites_tests/tests.py
index 4f5b07ee8f..79183f7aca 100644
--- a/tests/sites_tests/tests.py
+++ b/tests/sites_tests/tests.py
@@ -38,8 +38,8 @@ class SitesFrameworkTests(TestCase):
Site.objects.get_current()
def test_site_cache(self):
- # After updating a Site object (e.g. via the admin), we shouldn't return a
- # bogus value from the SITE_CACHE.
+ # After updating a Site object (e.g. via the admin), we shouldn't
+ # return a bogus value from the SITE_CACHE.
site = Site.objects.get_current()
self.assertEqual("example.com", site.name)
s2 = Site.objects.get(id=settings.SITE_ID)
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index a3226f5aa1..e8873915e6 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -439,8 +439,8 @@ class TestCollectionDryRunManifestStaticFilesStorage(TestCollectionDryRun):
class TestCollectionFilesOverride(CollectionTestCase):
"""
Test overriding duplicated files by ``collectstatic`` management command.
- Check for proper handling of apps order in installed apps even if file modification
- dates are in different order:
+ Check for proper handling of apps order in installed apps even if file
+ modification dates are in different order:
'staticfiles_test_app',
'staticfiles_tests.apps.no_label',
"""
@@ -457,9 +457,9 @@ class TestCollectionFilesOverride(CollectionTestCase):
self.orig_atime = os.path.getatime(self.orig_path)
# prepare duplicate of file2.txt from a temporary app
- # this file will have modification time older than no_label/static/file2.txt
- # anyway it should be taken to STATIC_ROOT because the temporary app is before
- # 'no_label' app in installed apps
+ # this file will have modification time older than
+ # no_label/static/file2.txt anyway it should be taken to STATIC_ROOT
+ # because the temporary app is before 'no_label' app in installed apps
self.temp_app_path = os.path.join(self.temp_dir, "staticfiles_test_app")
self.testfile_path = os.path.join(self.temp_app_path, "static", "file2.txt")
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 9ef49491ff..e09f9eda1c 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -131,7 +131,8 @@ class TestHashedFiles:
def test_template_tag_absolute_root(self):
"""
- Like test_template_tag_absolute, but for a file in STATIC_ROOT (#26249).
+ Like test_template_tag_absolute, but for a file in STATIC_ROOT
+ (#26249).
"""
relpath = self.hashed_file_path("absolute_root.css")
self.assertEqual(relpath, "absolute_root.f821df1b64f7.css")
@@ -198,8 +199,8 @@ class TestHashedFiles:
Files that are alterable should always be post-processed; files that
aren't should be skipped.
- collectstatic has already been called once in setUp() for this testcase,
- therefore we check by verifying behavior on a second run.
+ collectstatic has already been called once in setUp() for this
+ testcase, therefore we check by verifying behavior on a second run.
"""
collectstatic_args = {
"interactive": False,
diff --git a/tests/string_lookup/tests.py b/tests/string_lookup/tests.py
index cc7d36061a..4a0c6c32fc 100644
--- a/tests/string_lookup/tests.py
+++ b/tests/string_lookup/tests.py
@@ -72,7 +72,8 @@ class StringLookupTests(TestCase):
"""
Regression test for #708
- "like" queries on IP address fields require casting with HOST() (on PostgreSQL).
+ "like" queries on IP address fields require casting with HOST() (on
+ PostgreSQL).
"""
a = Article(name="IP test", text="The body", submitted_from="192.0.2.100")
a.save()
diff --git a/tests/syndication_tests/tests.py b/tests/syndication_tests/tests.py
index 6403f7461a..17a408a686 100644
--- a/tests/syndication_tests/tests.py
+++ b/tests/syndication_tests/tests.py
@@ -292,7 +292,8 @@ class SyndicationFeedTest(FeedTestCase):
def test_rss091_feed(self):
"""
- Test the structure and content of feeds generated by RssUserland091Feed.
+ Test the structure and content of feeds generated by
+ RssUserland091Feed.
"""
response = self.client.get("/syndication/rss091/")
doc = minidom.parseString(response.content)
diff --git a/tests/template_tests/filter_tests/test_urlize.py b/tests/template_tests/filter_tests/test_urlize.py
index 043029c8dc..ca9f8fb7e1 100644
--- a/tests/template_tests/filter_tests/test_urlize.py
+++ b/tests/template_tests/filter_tests/test_urlize.py
@@ -296,7 +296,8 @@ class FunctionTests(SimpleTestCase):
def test_trailing_period(self):
"""
- #18644 - Check urlize trims trailing period when followed by parenthesis
+ #18644 - Check urlize trims trailing period when followed by
+ parenthesis
"""
self.assertEqual(
urlize("(Go to http://www.example.com/foo.)"),
diff --git a/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py b/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py
index 1425406960..479d1374f9 100644
--- a/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py
+++ b/tests/template_tests/syntax_tests/i18n/test_blocktranslate.py
@@ -563,7 +563,9 @@ class TranslationBlockTranslateTagTests(SimpleTestCase):
@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_template_tags_pgettext(self):
- """{% blocktranslate %} takes message contexts into account (#14806)."""
+ """
+ {% blocktranslate %} takes message contexts into account (#14806).
+ """
trans_real._active = Local()
trans_real._translations = {}
with translation.override("de"):
@@ -733,8 +735,8 @@ class TranslationBlockTranslateTagTests(SimpleTestCase):
def test_bad_placeholder_2(self):
"""
Error in translation file should not crash template rendering (#18393).
- (%(person) misses a 's' in fr.po, causing the string formatting to fail)
- .
+ (%(person) misses a 's' in fr.po, causing the string formatting to
+ fail) .
"""
with translation.override("fr"):
t = Template(
diff --git a/tests/template_tests/syntax_tests/test_if_changed.py b/tests/template_tests/syntax_tests/test_if_changed.py
index fb0a693460..6e5d04c225 100644
--- a/tests/template_tests/syntax_tests/test_if_changed.py
+++ b/tests/template_tests/syntax_tests/test_if_changed.py
@@ -284,8 +284,9 @@ class IfChangedTests(SimpleTestCase):
)
# Using generator to mimic concurrency.
- # The generator is not passed to the 'for' loop, because it does a list(values)
- # instead, call gen.next() in the template to control the generator.
+ # The generator is not passed to the 'for' loop, because it does a
+ # list(values) instead, call gen.next() in the template to control the
+ # generator.
def gen():
yield 1
yield 2
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py
index 2c0a1b7f3f..bf201e74e9 100644
--- a/tests/template_tests/templatetags/custom.py
+++ b/tests/template_tests/templatetags/custom.py
@@ -32,9 +32,9 @@ def div_custom_end(content):
@register.filter
def noop(value, param=None):
- """A noop filter that always return its first argument and does nothing with
- its second (optional) one.
- Useful for testing out whitespace in filter arguments (see #19882)."""
+ """A noop filter that always return its first argument and does nothing
+ with its second (optional) one. Useful for testing out whitespace in filter
+ arguments (see #19882)."""
return value
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 652563d269..d1d329aff9 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -331,7 +331,9 @@ class ClientTest(TestCase):
self.assertEqual(response.request["PATH_INFO"], "/accounts/login/")
def test_follow_relative_redirect_no_trailing_slash(self):
- "A URL with a relative redirect with no trailing slash can be followed."
+ """
+ A URL with a relative redirect with no trailing slash can be followed.
+ """
response = self.client.get("/accounts/no_trailing_slash", follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request["PATH_INFO"], "/accounts/login/")
@@ -681,7 +683,9 @@ class ClientTest(TestCase):
]
)
def test_view_with_inactive_force_login(self):
- "Request a page that is protected with @login, but use an inactive login"
+ """
+ Request a page that is protected with @login, but use an inactive login
+ """
# Get the page without logging in. Should result in 302.
response = self.client.get("/login_protected_view/")
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index 325ad17cdb..966eefa71b 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -50,10 +50,10 @@ class ExtraAssertMixin:
:param method: The assertion method to test.
:param method_args: Positional arguments to pass to the method.
- :param expected_msg: The expected base error message (required keyword-only).
- :param msg_prefix: Optional prefix to be added to the message in the second
- subTest.
- :param method_kwargs: Keyword arguments to pass to the method.
+ :param expected_msg: The expected base error message (required
+ keyword-only). :param msg_prefix: Optional prefix to be added to the
+ message in the second subTest. :param method_kwargs: Keyword arguments
+ to pass to the method.
Used internally for testing Django's assertions.
"""
@@ -236,7 +236,10 @@ class AssertContainsTests(ExtraAssertMixin, SimpleTestCase):
self.assertContains(r, b"\xe5\xb3\xa0".decode())
def test_unicode_not_contains(self):
- "Unicode characters can be searched for, and not found in template context"
+ """
+ Unicode characters can be searched for, and not found in template
+ context
+ """
# Regression test for #10183
r = self.client.get("/check_unicode/")
self.assertNotContains(r, "はたけ")
@@ -280,7 +283,8 @@ class AssertContainsTests(ExtraAssertMixin, SimpleTestCase):
def test_assert_not_contains_renders_template_response(self):
"""
- An unrendered SimpleTemplateResponse may be used in assertNotContains().
+ An unrendered SimpleTemplateResponse may be used in
+ assertNotContains().
"""
template = engines["django"].from_string("Hello")
response = SimpleTemplateResponse(template)
@@ -378,7 +382,9 @@ class AssertTemplateUsedTests(TestDataMixin, TestCase):
self.assertTemplateUsed(response, "base.html", count=2)
def test_template_rendered_multiple_times(self):
- """Template assertions work when a template is rendered multiple times."""
+ """
+ Template assertions work when a template is rendered multiple times.
+ """
response = self.client.get("/render_template_multiple_times/")
self.assertTemplateUsed(response, "base.html", count=2)
@@ -387,7 +393,10 @@ class AssertTemplateUsedTests(TestDataMixin, TestCase):
@override_settings(ROOT_URLCONF="test_client_regress.urls")
class AssertRedirectsTests(ExtraAssertMixin, SimpleTestCase):
def test_redirect_page(self):
- "An assertion is raised if the original page couldn't be retrieved as expected"
+ """
+ An assertion is raised if the original page couldn't be retrieved as
+ expected
+ """
# This page will redirect with code 301, not 302
response = self.client.get("/permanent_redirect_view/")
try:
@@ -554,7 +563,8 @@ class AssertRedirectsTests(ExtraAssertMixin, SimpleTestCase):
with self.assertRaises(RedirectCycleError) as context:
self.client.get("/circular_redirect_1/", {}, follow=True)
response = context.exception.last_response
- # The chain of redirects will get back to the starting point, but stop there.
+ # The chain of redirects will get back to the starting point, but stop
+ # there.
self.assertRedirects(
response, "/circular_redirect_2/", status_code=302, target_status_code=302
)
@@ -640,7 +650,10 @@ class AssertRedirectsTests(ExtraAssertMixin, SimpleTestCase):
)
def test_redirect_on_non_redirect_page(self):
- "An assertion is raised if the original page couldn't be retrieved as expected"
+ """
+ An assertion is raised if the original page couldn't be retrieved as
+ expected
+ """
# This page will redirect with code 301, not 302
response = self.client.get("/get_view/")
try:
@@ -800,7 +813,8 @@ class ExceptionTests(TestDataMixin, TestCase):
# At this point, an exception has been raised, and should be cleared.
- # This next operation should be successful; if it isn't we have a problem.
+ # This next operation should be successful; if it isn't we have a
+ # problem.
login = self.client.login(username="staff", password="password")
self.assertTrue(login, "Could not log in")
self.client.get("/staff_only/")
@@ -822,9 +836,10 @@ class TemplateExceptionTests(SimpleTestCase):
self.client.get("/no_such_view/")
-# We need two different tests to check URLconf substitution - one to check
-# it was changed, and another one (without self.urls) to check it was reverted on
-# teardown. This pair of tests relies upon the alphabetical ordering of test execution.
+# We need two different tests to check URLconf substitution - one to check it
+# was changed, and another one (without self.urls) to check it was reverted on
+# teardown. This pair of tests relies upon the alphabetical ordering of test
+# execution.
@override_settings(ROOT_URLCONF="test_client_regress.urls")
class UrlconfSubstitutionTests(SimpleTestCase):
def test_urlconf_was_changed(self):
@@ -837,7 +852,8 @@ class UrlconfSubstitutionTests(SimpleTestCase):
# name is to ensure alphabetical ordering.
class zzUrlconfSubstitutionTests(SimpleTestCase):
def test_urlconf_was_reverted(self):
- """URLconf is reverted to original value after modification in a TestCase
+ """URLconf is reverted to original value after modification in a
+ TestCase
This will not find a match as the default ROOT_URLCONF is empty.
"""
@@ -984,7 +1000,9 @@ class SessionTests(TestDataMixin, TestCase):
@override_settings(AUTH_USER_MODEL="test_client_regress.CustomUser")
def test_logout_with_custom_user(self):
- """Logout should send user_logged_out signal if custom user was logged in."""
+ """
+ Logout should send user_logged_out signal if custom user was logged in.
+ """
def listener(*args, **kwargs):
self.assertEqual(kwargs["sender"], CustomUser)
@@ -1151,7 +1169,9 @@ class RequestMethodStringDataTests(SimpleTestCase):
self.assertEqual(response.content, b"request method: PATCH")
def test_empty_string_data(self):
- "Request a view with empty string data via request method GET/POST/HEAD"
+ """
+ Request a view with empty string data via request method GET/POST/HEAD
+ """
# Regression test for #21740
response = self.client.get("/body/", data="", content_type="application/json")
self.assertEqual(response.content, b"")
diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py
index 91b8bdfefc..24091ea945 100644
--- a/tests/test_client_regress/views.py
+++ b/tests/test_client_regress/views.py
@@ -21,7 +21,10 @@ def no_template_view(request):
def staff_only_view(request):
- "A view that can only be visited by staff. Non staff members get an exception"
+ """
+ A view that can only be visited by staff. Non staff members get an
+ exception
+ """
if request.user.is_staff:
return HttpResponse()
else:
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 4c4a22397b..3c68a83595 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -364,7 +364,8 @@ class DiscoverRunnerTests(SimpleTestCase):
def test_duplicates_ignored(self):
"""
- Tests shouldn't be discovered twice when discovering on overlapping paths.
+ Tests shouldn't be discovered twice when discovering on overlapping
+ paths.
"""
base_app = "forms_tests"
sub_app = "forms_tests.field_tests"
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index a9fadc872b..2c1fc3ad68 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -907,7 +907,8 @@ class SetupDatabasesTests(unittest.TestCase):
},
}
)
- # Using the real current name as old_name to not mess with the test suite.
+ # Using the real current name as old_name to not mess with the test
+ # suite.
old_name = settings.DATABASES[db.DEFAULT_DB_ALIAS]["NAME"]
with mock.patch("django.db.connections", new=tested_connections):
tested_connections["default"].creation.destroy_test_db(
@@ -969,8 +970,9 @@ class AutoIncrementResetTest(TransactionTestCase):
class EmptyDefaultDatabaseTest(unittest.TestCase):
def test_empty_default_database(self):
"""
- An empty default database in settings does not raise an ImproperlyConfigured
- error when running a unit test that does not use a database.
+ An empty default database in settings does not raise an
+ ImproperlyConfigured error when running a unit test that does not use a
+ database.
"""
tested_connections = db.ConnectionHandler({"default": {}})
with mock.patch("django.db.connections", new=tested_connections):
diff --git a/tests/test_runner_apps/sample/tests_sample.py b/tests/test_runner_apps/sample/tests_sample.py
index 6e876ebd41..46d1c07e84 100644
--- a/tests/test_runner_apps/sample/tests_sample.py
+++ b/tests/test_runner_apps/sample/tests_sample.py
@@ -18,7 +18,8 @@ class TestDjangoTestCase(DjangoTestCase):
class TestZimpleTestCase(SimpleTestCase):
- # Z is used to trick this test case to appear after Vanilla in default suite
+ # Z is used to trick this test case to appear after Vanilla in default
+ # suite
def test_sample(self):
self.assertEqual(1, 1)
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index fd8b49fdef..6c6cbebe17 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -75,7 +75,8 @@ def override_database_connection_timezone(timezone):
try:
orig_timezone = connection.settings_dict["TIME_ZONE"]
connection.settings_dict["TIME_ZONE"] = timezone
- # Clear cached properties, after first accessing them to ensure they exist.
+ # Clear cached properties, after first accessing them to ensure they
+ # exist.
connection.timezone
del connection.timezone
connection.timezone_name
@@ -83,7 +84,8 @@ def override_database_connection_timezone(timezone):
yield
finally:
connection.settings_dict["TIME_ZONE"] = orig_timezone
- # Clear cached properties, after first accessing them to ensure they exist.
+ # Clear cached properties, after first accessing them to ensure they
+ # exist.
connection.timezone
del connection.timezone
connection.timezone_name
@@ -450,8 +452,8 @@ class NewDatabaseTests(TestCase):
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT))
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0, tzinfo=EAT))
with timezone.override(UTC):
- # These two dates fall in the same day in EAT, but in different days,
- # years and months in UTC.
+ # These two dates fall in the same day in EAT, but in different
+ # days, years and months in UTC.
self.assertEqual(Event.objects.filter(dt__year=2011).count(), 1)
self.assertEqual(Event.objects.filter(dt__month=1).count(), 1)
self.assertEqual(Event.objects.filter(dt__day=1).count(), 1)
@@ -1169,7 +1171,8 @@ class TemplateTests(SimpleTestCase):
@skipIf(sys.platform == "win32", "Windows uses non-standard time zone names")
def test_tz_template_context_processor(self):
"""
- Test the django.template.context_processors.tz template context processor.
+ Test the django.template.context_processors.tz template context
+ processor.
"""
tpl = Template("{{ TIME_ZONE }}")
context = Context()
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 9fe8c58593..a3cd4cafee 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -244,7 +244,9 @@ class AtomicTests(TransactionTestCase):
class AtomicInsideTransactionTests(AtomicTests):
- """All basic tests for atomic should also pass within an existing transaction."""
+ """
+ All basic tests for atomic should also pass within an existing transaction.
+ """
def setUp(self):
self.atomic = transaction.atomic()
@@ -255,7 +257,9 @@ class AtomicInsideTransactionTests(AtomicTests):
class AtomicWithoutAutocommitTests(AtomicTests):
- """All basic tests for atomic should also pass when autocommit is turned off."""
+ """
+ All basic tests for atomic should also pass when autocommit is turned off.
+ """
def setUp(self):
transaction.set_autocommit(False)
@@ -393,7 +397,9 @@ class AtomicMySQLTests(TransactionTestCase):
@skipIf(threading is None, "Test requires threading")
def test_implicit_savepoint_rollback(self):
- """MySQL implicitly rolls back savepoints when it deadlocks (#22291)."""
+ """
+ MySQL implicitly rolls back savepoints when it deadlocks (#22291).
+ """
Reporter.objects.create(id=1)
Reporter.objects.create(id=2)
@@ -457,7 +463,8 @@ class AtomicMiscTests(TransactionTestCase):
sid = connection.savepoint_ids[-1]
raise Exception("Oops")
- # This is expected to fail because the savepoint no longer exists.
+ # This is expected to fail because the savepoint no longer
+ # exists.
connection.savepoint_rollback(sid)
def test_mark_for_rollback_on_error_in_transaction(self):
@@ -497,8 +504,8 @@ class AtomicMiscTests(TransactionTestCase):
raise Exception("Oops")
- # Ensure that `mark_for_rollback_on_error` did not mark the transaction
- # as broken, since we are in autocommit mode …
+ # Ensure that `mark_for_rollback_on_error` did not mark the
+ # transaction as broken, since we are in autocommit mode …
self.assertFalse(transaction.get_connection().needs_rollback)
# … and further queries work nicely.
@@ -526,7 +533,9 @@ class NonAutocommitTests(TransactionTestCase):
Reporter.objects.last()
def test_orm_query_without_autocommit(self):
- """#24921 -- ORM queries must be possible after set_autocommit(False)."""
+ """
+ #24921 -- ORM queries must be possible after set_autocommit(False).
+ """
Reporter.objects.create(first_name="Tintin")
diff --git a/tests/unmanaged_models/tests.py b/tests/unmanaged_models/tests.py
index dc75bdc993..81c19a83e5 100644
--- a/tests/unmanaged_models/tests.py
+++ b/tests/unmanaged_models/tests.py
@@ -42,7 +42,8 @@ class SimpleTests(TestCase):
class ManyToManyUnmanagedTests(TestCase):
def test_many_to_many_between_unmanaged(self):
"""
- The intermediary table between two unmanaged models should not be created.
+ The intermediary table between two unmanaged models should not be
+ created.
"""
table = Unmanaged2._meta.get_field("mm").m2m_db_table()
tables = connection.introspection.table_names()
diff --git a/tests/update/tests.py b/tests/update/tests.py
index bb83440008..bbff0e4ff4 100644
--- a/tests/update/tests.py
+++ b/tests/update/tests.py
@@ -196,7 +196,8 @@ class AdvancedTests(TestCase):
def test_update_annotated_multi_table_queryset(self):
"""
- Update of a queryset that's been annotated and involves multiple tables.
+ Update of a queryset that's been annotated and involves multiple
+ tables.
"""
# Trivial annotated update
qs = DataPoint.objects.annotate(related_count=Count("relatedpoint"))
diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
index c396e24934..58cd2601db 100644
--- a/tests/urlpatterns_reverse/tests.py
+++ b/tests/urlpatterns_reverse/tests.py
@@ -117,7 +117,8 @@ resolve_test_data = (
(),
{"arg2": "37"},
),
- # Unnamed views should have None as the url_name. Regression data for #21157.
+ # Unnamed views should have None as the url_name. Regression data for
+ # #21157.
(
"/unnamed/normal/42/37/",
None,
@@ -445,7 +446,8 @@ class URLPatternReverse(SimpleTestCase):
self.assertEqual(got, expected)
def test_reverse_none(self):
- # Reversing None should raise an error, not return the last un-named view.
+ # Reversing None should raise an error, not return the last un-named
+ # view.
with self.assertRaises(NoReverseMatch):
reverse(None)
@@ -661,7 +663,8 @@ class ResolverTests(SimpleTestCase):
("name-conflict", (), {"first": "arg"}, "conflict-first/arg/"),
("name-conflict", (), {"middle": "arg"}, "conflict-middle/arg/"),
("name-conflict", (), {"last": "arg"}, "conflict-last/arg/"),
- # The number and order of the arguments don't interfere with reversing.
+ # The number and order of the arguments don't interfere with
+ # reversing.
("name-conflict", ("arg", "arg"), {}, "conflict/arg/arg/"),
]
for name, args, kwargs, expected in test_urls:
@@ -851,8 +854,9 @@ class ReverseShortcutTests(SimpleTestCase):
# Assert that we can redirect using UTF-8 strings
res = redirect("/æøå/abc/")
self.assertEqual(res.url, "/%C3%A6%C3%B8%C3%A5/abc/")
- # Assert that no imports are attempted when dealing with a relative path
- # (previously, the below would resolve in a UnicodeEncodeError from __import__ )
+ # Assert that no imports are attempted when dealing with a relative
+ # path (previously, the below would resolve in a UnicodeEncodeError
+ # from __import__ )
res = redirect("/æøå.abc/")
self.assertEqual(res.url, "/%C3%A6%C3%B8%C3%A5.abc/")
res = redirect("os.path")
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index 4b03f54564..e282bd4bc9 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -488,8 +488,8 @@ class CommandRunTests(AdminScriptTestCase):
"settings.py",
apps=["django.contrib.staticfiles", "user_commands"],
sdict={
- # (staticfiles.E001) The STATICFILES_DIRS setting is not a tuple or
- # list.
+ # (staticfiles.E001) The STATICFILES_DIRS setting is not a
+ # tuple or list.
"STATICFILES_DIRS": '"foo"',
},
)
diff --git a/tests/utils_tests/test_csp.py b/tests/utils_tests/test_csp.py
index 96c66538d0..86682544e2 100644
--- a/tests/utils_tests/test_csp.py
+++ b/tests/utils_tests/test_csp.py
@@ -67,8 +67,9 @@ class CSPBuildPolicyTest(SimpleTestCase):
"""
Test that a set can be passed as a value.
- Sets are often used in Django settings to ensure uniqueness, however, sets are
- unordered. The middleware ensures consistency via sorting if a set is passed.
+ Sets are often used in Django settings to ensure uniqueness, however,
+ sets are unordered. The middleware ensures consistency via sorting if a
+ set is passed.
"""
policy = {"default-src": {CSP.SELF, "foo.com", "bar.com"}}
self.assertPolicyEqual(
@@ -147,7 +148,8 @@ class LazyNonceTests(SimpleTestCase):
return result
with patch("django.utils.csp.secrets.token_urlsafe", memento_token_urlsafe):
- # Force usage, similar to template rendering, to generate the nonce.
+ # Force usage, similar to template rendering, to generate the
+ # nonce.
val = str(nonce)
self.assertTrue(nonce)
diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py
index 9604b0cef4..3f0498bd46 100644
--- a/tests/utils_tests/test_dateformat.py
+++ b/tests/utils_tests/test_dateformat.py
@@ -48,7 +48,8 @@ class DateFormatTests(SimpleTestCase):
dt = make_aware(datetime(2009, 5, 16, 5, 30, 30), ltz)
self.assertEqual(datetime.fromtimestamp(int(format(dt, "U")), tz), dt)
self.assertEqual(datetime.fromtimestamp(int(format(dt, "U")), ltz), dt)
- # astimezone() is safe here because the target timezone doesn't have DST
+ # astimezone() is safe here because the target timezone doesn't have
+ # DST
self.assertEqual(
datetime.fromtimestamp(int(format(dt, "U"))),
dt.astimezone(ltz).replace(tzinfo=None),
diff --git a/tests/utils_tests/test_decorators.py b/tests/utils_tests/test_decorators.py
index 8c0244e819..8e14b53cb7 100644
--- a/tests/utils_tests/test_decorators.py
+++ b/tests/utils_tests/test_decorators.py
@@ -69,7 +69,8 @@ class DecoratorFromMiddlewareTests(SimpleTestCase):
def test_callable_process_view_middleware(self):
"""
- Test a middleware that implements process_view, operating on a callable class.
+ Test a middleware that implements process_view, operating on a callable
+ class.
"""
class_process_view(self.rf.get("/"))
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py
index 8b5c330bcf..e0a1a76471 100644
--- a/tests/utils_tests/test_functional.py
+++ b/tests/utils_tests/test_functional.py
@@ -127,7 +127,9 @@ class FunctionalTests(SimpleTestCase):
self.assertCachedPropertyWorks(attr, Class)
def test_cached_property_reuse_different_names(self):
- """Disallow this case because the decorated function wouldn't be cached."""
+ """
+ Disallow this case because the decorated function wouldn't be cached.
+ """
type_msg = (
"Cannot assign the same cached_property to two different names ('a' and "
"'b')."
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index 4ce552e79a..284f33aedc 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -170,7 +170,8 @@ class TestUtilsHtml(SimpleTestCase):
strip_tags(value)
def test_strip_tags_files(self):
- # Test with more lengthy content (also catching performance regressions)
+ # Test with more lengthy content (also catching performance
+ # regressions)
for filename in ("strip_tags1.html", "strip_tags2.txt"):
with self.subTest(filename=filename):
path = os.path.join(os.path.dirname(__file__), "files", filename)
diff --git a/tests/utils_tests/test_lorem_ipsum.py b/tests/utils_tests/test_lorem_ipsum.py
index deda09c717..3471053778 100644
--- a/tests/utils_tests/test_lorem_ipsum.py
+++ b/tests/utils_tests/test_lorem_ipsum.py
@@ -18,7 +18,9 @@ class LoremIpsumTests(unittest.TestCase):
self.assertEqual(words(7), "lorem ipsum dolor sit amet consectetur adipisicing")
def test_common_words_in_string(self):
- """words(n) starts with the 19 standard lorem ipsum words for n > 19."""
+ """
+ words(n) starts with the 19 standard lorem ipsum words for n > 19.
+ """
self.assertTrue(
words(25).startswith(
"lorem ipsum dolor sit amet consectetur adipisicing elit sed "
diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py
index fdcfa4b281..8305a801fc 100644
--- a/tests/utils_tests/test_timesince.py
+++ b/tests/utils_tests/test_timesince.py
@@ -138,7 +138,9 @@ class TimesinceTests(TestCase):
self.assertEqual(timeuntil(now_tz, now_tz_i), "0\xa0minutes")
def test_date_objects(self):
- """Both timesince and timeuntil should work on date objects (#17937)."""
+ """
+ Both timesince and timeuntil should work on date objects (#17937).
+ """
today = datetime.date.today()
self.assertEqual(timesince(today + self.oneday), "0\xa0minutes")
self.assertEqual(timeuntil(today - self.oneday), "0\xa0minutes")
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index f5cb82cd2d..8e36ab7eb1 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -396,7 +396,8 @@ class DebugViewTests(SimpleTestCase):
def test_no_template_source_loaders(self):
"""
- Make sure if you don't specify a template, the debug view doesn't blow up.
+ Make sure if you don't specify a template, the debug view doesn't blow
+ up.
"""
with self.assertLogs("django.request", "ERROR"):
with self.assertRaises(TemplateDoesNotExist):
@@ -493,7 +494,8 @@ class DebugViewQueriesAllowedTests(SimpleTestCase):
def test_handle_db_exception(self):
"""
Ensure the debug view works when a database exception is raised by
- performing an invalid query and passing the exception to the debug view.
+ performing an invalid query and passing the exception to the debug
+ view.
"""
with connection.cursor() as cursor:
try:
@@ -614,7 +616,9 @@ class ExceptionReporterTests(SimpleTestCase):
)
def test_eol_support(self):
- """The ExceptionReporter supports Unix, Windows and Macintosh EOL markers"""
+ """
+ The ExceptionReporter supports Unix, Windows and Macintosh EOL markers
+ """
LINES = ["print %d" % i for i in range(1, 6)]
reporter = ExceptionReporter(None, None, None, None)
@@ -1040,7 +1044,10 @@ class ExceptionReporterTests(SimpleTestCase):
self.assertIn("<p>Request data not supplied</p>", html)
def test_non_utf8_values_handling(self):
- "Non-UTF-8 exceptions/values should not make the output generation choke."
+ """
+ Non-UTF-8 exceptions/values should not make the output generation
+ choke.
+ """
try:
class NonUtf8Output(Exception):
@@ -1446,7 +1453,8 @@ class ExceptionReportTestMixin:
self, view, check_for_vars=True, check_for_POST_params=True
):
"""
- Asserts that no variables or POST parameters are displayed in the response.
+ Asserts that no variables or POST parameters are displayed in the
+ response.
"""
request = self.rf.post("/some_url/", self.breakfast_data)
response = view(request)
@@ -1465,7 +1473,8 @@ class ExceptionReportTestMixin:
def verify_unsafe_email(self, view, check_for_POST_params=True):
"""
- Asserts that potentially sensitive info are displayed in the email report.
+ Asserts that potentially sensitive info are displayed in the email
+ report.
"""
with self.settings(ADMINS=["admin@example.com"]):
mail.outbox = [] # Empty outbox
@@ -1501,7 +1510,8 @@ class ExceptionReportTestMixin:
def verify_safe_email(self, view, check_for_POST_params=True):
"""
- Asserts that certain sensitive info are not displayed in the email report.
+ Asserts that certain sensitive info are not displayed in the email
+ report.
"""
with self.settings(ADMINS=["admin@example.com"]):
mail.outbox = [] # Empty outbox
@@ -1544,7 +1554,8 @@ class ExceptionReportTestMixin:
def verify_paranoid_email(self, view):
"""
- Asserts that no variables or POST parameters are displayed in the email report.
+ Asserts that no variables or POST parameters are displayed in the email
+ report.
"""
with self.settings(ADMINS=["admin@example.com"]):
mail.outbox = [] # Empty outbox
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py
index 229ce68bfc..f4ba5249a2 100644
--- a/tests/view_tests/tests/test_i18n.py
+++ b/tests/view_tests/tests/test_i18n.py
@@ -272,8 +272,9 @@ class I18NViewTests(SimpleTestCase):
response.headers["Content-Type"], 'text/javascript; charset="utf-8"'
)
# response content must include a line like:
- # "this is to be translated": <value of trans_txt Python variable>
- # json.dumps() is used to be able to check Unicode strings.
+ # "this is to be translated": <value of trans_txt Python
+ # variable> json.dumps() is used to be able to check Unicode
+ # strings.
self.assertContains(response, json.dumps(trans_txt), 1)
if lang_code == "fr":
# Message with context (msgctxt)
@@ -417,8 +418,9 @@ class I18NViewTests(SimpleTestCase):
def test_non_english_default_english_userpref(self):
"""
Same as above with the difference that there IS an 'en' translation
- available. The JavaScript i18n view must return a NON empty language catalog
- with the proper English translations. See #13726 for more details.
+ available. The JavaScript i18n view must return a NON empty language
+ catalog with the proper English translations. See #13726 for more
+ details.
"""
with self.settings(LANGUAGE_CODE="fr"), override("en-us"):
response = self.client.get("/jsi18n_english_translation/")
diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py
index f60ca88cd2..ca1b5f1638 100644
--- a/tests/view_tests/tests/test_static.py
+++ b/tests/view_tests/tests/test_static.py
@@ -39,7 +39,10 @@ class StaticTests(SimpleTestCase):
)
def test_chunked(self):
- "The static view should stream files in chunks to avoid large memory usage"
+ """
+ The static view should stream files in chunks to avoid large memory
+ usage
+ """
response = self.client.get("/%s/%s" % (self.prefix, "long-line.txt"))
response_iterator = iter(response)
first_chunk = next(response_iterator)
diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py
index 9eb7a352d6..1986341177 100644
--- a/tests/view_tests/views.py
+++ b/tests/view_tests/views.py
@@ -125,10 +125,10 @@ def render_no_template(request):
def send_log(request, exc_info):
logger = logging.getLogger("django")
- # The default logging config has a logging filter to ensure admin emails are
- # only sent with DEBUG=False, but since someone might choose to remove that
- # filter, we still want to be able to test the behavior of error emails
- # with DEBUG=True. So we need to remove the filter temporarily.
+ # The default logging config has a logging filter to ensure admin emails
+ # are only sent with DEBUG=False, but since someone might choose to remove
+ # that filter, we still want to be able to test the behavior of error
+ # emails with DEBUG=True. So we need to remove the filter temporarily.
admin_email_handler = [
h for h in logger.handlers if h.__class__.__name__ == "AdminEmailHandler"
][0]
@@ -417,7 +417,8 @@ def json_response_view(request):
{
"a": [1, 2, 3],
"foo": {"bar": "baz"},
- # Make sure datetime and Decimal objects would be serialized properly
+ # Make sure datetime and Decimal objects would be serialized
+ # properly
"timestamp": datetime.datetime(2013, 5, 19, 20),
"value": decimal.Decimal("3.14"),
}