From c18861804feb6a97afbeabb51be748dd60a04458 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 31 Jul 2022 07:48:52 +0200 Subject: [PATCH] Fixed warnings per flake8 5.0.0. --- .pre-commit-config.yaml | 2 +- .../commands/remove_stale_contenttypes.py | 24 ++--- tests/admin_views/tests.py | 5 +- tests/forms_tests/tests/test_forms.py | 41 ++++--- tests/forms_tests/tests/test_formsets.py | 101 ++++++++++-------- tests/model_forms/tests.py | 88 +++++++-------- tests/staticfiles_tests/test_forms.py | 13 +-- 7 files changed, 149 insertions(+), 125 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd2366d560..b9ef3dd693 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 5.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-eslint diff --git a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py index 3002ceaf53..eccd3aa2c9 100644 --- a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py +++ b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py @@ -72,18 +72,18 @@ class Command(BaseCommand): ) content_type_display = "\n".join(ct_info) self.stdout.write( - """Some content types in your database are stale and can be deleted. -Any objects that depend on these content types will also be deleted. -The content types and dependent objects that would be deleted are: - -%s - -This list doesn't include any cascade deletions to data outside of Django's -models (uncommon). - -Are you sure you want to delete these content types? -If you're unsure, answer 'no'.""" - % content_type_display + "Some content types in your database are stale and can be " + "deleted.\n" + "Any objects that depend on these content types will also be " + "deleted.\n" + "The content types and dependent objects that would be deleted " + "are:\n\n" + f"{content_type_display}\n\n" + "This list doesn't include any cascade deletions to data " + "outside of Django's\n" + "models (uncommon).\n\n" + "Are you sure you want to delete these content types?\n" + "If you're unsure, answer 'no'." ) ok_to_delete = input("Type 'yes' to continue, or 'no' to cancel: ") else: diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 11b8aff346..88468e883c 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -803,8 +803,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase): self.assertIs(response.context["cl"].has_related_field_in_list_display(), False) def test_limited_filter(self): - """Ensure admin changelist filters do not contain objects excluded via limit_choices_to. - This also tests relation-spanning filters (e.g. 'color__value'). + """ + Admin changelist filters do not contain objects excluded via + limit_choices_to. """ response = self.client.get(reverse("admin:admin_views_thing_changelist")) self.assertContains( diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index ec911ee961..6005472194 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -130,9 +130,12 @@ class FormsTestCase(SimpleTestCase): self.assertHTMLEqual( "\n".join(form_output), - """ - -""", + '" + '" + '", ) form_output = [] @@ -893,10 +896,12 @@ class FormsTestCase(SimpleTestCase): f = BeatleForm(auto_id=False) self.assertHTMLEqual( "\n".join(str(bf) for bf in f["name"]), - """ - - -""", + '' + '' + '" + '", ) self.assertHTMLEqual( "\n".join("
%s
" % bf for bf in f["name"]), @@ -2229,8 +2234,10 @@ class FormsTestCase(SimpleTestCase): p = UserRegistration(auto_id=False) self.assertHTMLEqual( p.as_ul(), - """
  • Username:
  • -
  • Password:
  • """, + '
  • Username: ' + "
  • " + '
  • Password:
  • ", ) def test_specifying_labels(self): @@ -2320,8 +2327,9 @@ class FormsTestCase(SimpleTestCase): p = UserRegistration(auto_id=False) self.assertHTMLEqual( p.as_ul(), - """
  • Username:
  • -
  • Password:
  • """, + '
  • Username: ' + "
  • " + '
  • Password:
  • ', ) p = UserRegistration(auto_id="id_%s") self.assertHTMLEqual( @@ -2945,11 +2953,12 @@ Options: -e.g., user@example.com -
  • -Password: -Wählen Sie mit Bedacht.
  • """, + '
  • Username: ' + 'e.g., user@example.com
  • ' + '
  • ' + 'Password: ' + 'Wählen Sie mit Bedacht.
  • ', ) # help_text is not displayed for hidden fields. It can be used for documentation diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index d159409afa..96a2189d70 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -245,10 +245,11 @@ class FormsFormsetTestCase(SimpleTestCase): ) self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ', ) def test_blank_form_unfilled(self): @@ -564,14 +565,15 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ', ) # Retrieving an empty form works. Tt shows up in the form list. self.assertTrue(formset.empty_form.empty_permitted) @@ -595,15 +597,17 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Delete:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Delete:
  • ', ) # To delete something, set that form's special delete field to 'on'. # Let's go ahead and delete Fergie. @@ -738,15 +742,17 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ', ) data = { "choices-TOTAL_FORMS": "3", # the number of forms rendered @@ -864,22 +870,25 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ', ) # Let's delete Fergie, and put The Decemberists ahead of Calexico. data = { diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index eb9c2484dc..d2ce3348c5 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1929,26 +1929,28 @@ class ModelFormBasicTests(TestCase): f = ArticleForm(auto_id=False) self.assertHTMLEqual( f.as_ul(), - """
  • Headline:
  • -
  • Slug:
  • -
  • Pub date:
  • -
  • Writer:
  • -
  • Article:
  • -
  • Categories:
  • -
  • Status:
  • """ + '
  • Headline: ' + "
  • " + '
  • Slug:
  • ' + '
  • Pub date:
  • ' + '
  • Writer:
  • " + '
  • Article:
  • " + '
  • Categories:
  • " + '
  • Status:
  • " % (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk), ) @@ -1956,28 +1958,30 @@ class ModelFormBasicTests(TestCase): w_bernstein = Writer.objects.create(name="Carl Bernstein") self.assertHTMLEqual( f.as_ul(), - """
  • Headline:
  • -
  • Slug:
  • -
  • Pub date:
  • -
  • Writer:
  • -
  • Article:
  • -
  • Categories:
  • -
  • Status:
  • """ + '
  • Headline: ' + "
  • " + '
  • Slug:
  • ' + '
  • Pub date:
  • ' + '
  • Writer:
  • " + '
  • Article:
  • " + '
  • Categories:
  • " + '
  • Status:
  • " % ( self.w_woodward.pk, w_bernstein.pk, diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py index d95fed43cc..ad662d7321 100644 --- a/tests/staticfiles_tests/test_forms.py +++ b/tests/staticfiles_tests/test_forms.py @@ -29,10 +29,11 @@ class StaticFilesFormsMediaTestCase(SimpleTestCase): ) self.assertEqual( str(m), - """ - - - - -""", + '\n' + '\n' + '\n' + '\n' + '\n' + '', )