Fixed warnings per flake8 5.0.0.

This commit is contained in:
Mariusz Felisiak 2022-07-31 07:48:52 +02:00
parent 1e5bbbb2a8
commit c18861804f
7 changed files with 149 additions and 125 deletions

View File

@ -9,7 +9,7 @@ repos:
hooks: hooks:
- id: isort - id: isort
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8
rev: 4.0.1 rev: 5.0.0
hooks: hooks:
- id: flake8 - id: flake8
- repo: https://github.com/pre-commit/mirrors-eslint - repo: https://github.com/pre-commit/mirrors-eslint

View File

@ -72,18 +72,18 @@ class Command(BaseCommand):
) )
content_type_display = "\n".join(ct_info) content_type_display = "\n".join(ct_info)
self.stdout.write( self.stdout.write(
"""Some content types in your database are stale and can be deleted. "Some content types in your database are stale and can be "
Any objects that depend on these content types will also be deleted. "deleted.\n"
The content types and dependent objects that would be deleted are: "Any objects that depend on these content types will also be "
"deleted.\n"
%s "The content types and dependent objects that would be deleted "
"are:\n\n"
This list doesn't include any cascade deletions to data outside of Django's f"{content_type_display}\n\n"
models (uncommon). "This list doesn't include any cascade deletions to data "
"outside of Django's\n"
Are you sure you want to delete these content types? "models (uncommon).\n\n"
If you're unsure, answer 'no'.""" "Are you sure you want to delete these content types?\n"
% content_type_display "If you're unsure, answer 'no'."
) )
ok_to_delete = input("Type 'yes' to continue, or 'no' to cancel: ") ok_to_delete = input("Type 'yes' to continue, or 'no' to cancel: ")
else: else:

View File

@ -803,8 +803,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
self.assertIs(response.context["cl"].has_related_field_in_list_display(), False) self.assertIs(response.context["cl"].has_related_field_in_list_display(), False)
def test_limited_filter(self): 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")) response = self.client.get(reverse("admin:admin_views_thing_changelist"))
self.assertContains( self.assertContains(

View File

@ -130,9 +130,12 @@ class FormsTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form_output), "\n".join(form_output),
"""<input type="text" name="first_name" value="John" id="id_first_name" required> '<input type="text" name="first_name" value="John" id="id_first_name" '
<input type="text" name="last_name" value="Lennon" id="id_last_name" required> "required>"
<input type="text" name="birthday" value="1940-10-9" id="id_birthday" required>""", '<input type="text" name="last_name" value="Lennon" id="id_last_name" '
"required>"
'<input type="text" name="birthday" value="1940-10-9" id="id_birthday" '
"required>",
) )
form_output = [] form_output = []
@ -893,10 +896,12 @@ class FormsTestCase(SimpleTestCase):
f = BeatleForm(auto_id=False) f = BeatleForm(auto_id=False)
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(str(bf) for bf in f["name"]), "\n".join(str(bf) for bf in f["name"]),
"""<label><input type="radio" name="name" value="john" required> John</label> '<label><input type="radio" name="name" value="john" required> John</label>'
<label><input type="radio" name="name" value="paul" required> Paul</label> '<label><input type="radio" name="name" value="paul" required> Paul</label>'
<label><input type="radio" name="name" value="george" required> George</label> '<label><input type="radio" name="name" value="george" required> George'
<label><input type="radio" name="name" value="ringo" required> Ringo</label>""", "</label>"
'<label><input type="radio" name="name" value="ringo" required> Ringo'
"</label>",
) )
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join("<div>%s</div>" % bf for bf in f["name"]), "\n".join("<div>%s</div>" % bf for bf in f["name"]),
@ -2229,8 +2234,10 @@ class FormsTestCase(SimpleTestCase):
p = UserRegistration(auto_id=False) p = UserRegistration(auto_id=False)
self.assertHTMLEqual( self.assertHTMLEqual(
p.as_ul(), p.as_ul(),
"""<li>Username: <input type="text" name="username" maxlength="10" required></li> '<li>Username: <input type="text" name="username" maxlength="10" required>'
<li>Password: <input type="password" name="password" maxlength="10" required></li>""", "</li>"
'<li>Password: <input type="password" name="password" maxlength="10" '
"required></li>",
) )
def test_specifying_labels(self): def test_specifying_labels(self):
@ -2320,8 +2327,9 @@ class FormsTestCase(SimpleTestCase):
p = UserRegistration(auto_id=False) p = UserRegistration(auto_id=False)
self.assertHTMLEqual( self.assertHTMLEqual(
p.as_ul(), p.as_ul(),
"""<li>Username: <input type="text" name="username" maxlength="10" required></li> '<li>Username: <input type="text" name="username" maxlength="10" required>'
<li>Password: <input type="password" name="password" required></li>""", "</li>"
'<li>Password: <input type="password" name="password" required></li>',
) )
p = UserRegistration(auto_id="id_%s") p = UserRegistration(auto_id="id_%s")
self.assertHTMLEqual( self.assertHTMLEqual(
@ -2945,11 +2953,12 @@ Options: <select multiple name="options" required>
p = UserRegistration({"username": "foo"}, auto_id=False) p = UserRegistration({"username": "foo"}, auto_id=False)
self.assertHTMLEqual( self.assertHTMLEqual(
p.as_ul(), p.as_ul(),
"""<li>Username: <input type="text" name="username" value="foo" maxlength="10" required> '<li>Username: <input type="text" name="username" value="foo" '
<span class="helptext">e.g., user@example.com</span></li> 'maxlength="10" required>'
<li><ul class="errorlist"><li>This field is required.</li></ul> '<span class="helptext">e.g., user@example.com</span></li>'
Password: <input type="password" name="password" required> '<li><ul class="errorlist"><li>This field is required.</li></ul>'
<span class="helptext">Wählen Sie mit Bedacht.</span></li>""", 'Password: <input type="password" name="password" 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 # help_text is not displayed for hidden fields. It can be used for documentation

View File

@ -245,10 +245,11 @@ class FormsFormsetTestCase(SimpleTestCase):
) )
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form.as_ul() for form in formset.forms), "\n".join(form.as_ul() for form in formset.forms),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li> '<li>Choice: <input type="text" name="choices-0-choice" value="Calexico">'
<li>Votes: <input type="number" name="choices-0-votes" value="100"></li> "</li>"
<li>Choice: <input type="text" name="choices-1-choice"></li> '<li>Votes: <input type="number" name="choices-0-votes" value="100"></li>'
<li>Votes: <input type="number" name="choices-1-votes"></li>""", '<li>Choice: <input type="text" name="choices-1-choice"></li>'
'<li>Votes: <input type="number" name="choices-1-votes"></li>',
) )
def test_blank_form_unfilled(self): def test_blank_form_unfilled(self):
@ -564,14 +565,15 @@ class FormsFormsetTestCase(SimpleTestCase):
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form.as_ul() for form in formset.forms), "\n".join(form.as_ul() for form in formset.forms),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li> '<li>Choice: <input type="text" name="choices-0-choice" value="Calexico">'
<li>Votes: <input type="number" name="choices-0-votes" value="100"></li> "</li>"
<li>Choice: <input type="text" name="choices-1-choice"></li> '<li>Votes: <input type="number" name="choices-0-votes" value="100"></li>'
<li>Votes: <input type="number" name="choices-1-votes"></li> '<li>Choice: <input type="text" name="choices-1-choice"></li>'
<li>Choice: <input type="text" name="choices-2-choice"></li> '<li>Votes: <input type="number" name="choices-1-votes"></li>'
<li>Votes: <input type="number" name="choices-2-votes"></li> '<li>Choice: <input type="text" name="choices-2-choice"></li>'
<li>Choice: <input type="text" name="choices-3-choice"></li> '<li>Votes: <input type="number" name="choices-2-votes"></li>'
<li>Votes: <input type="number" name="choices-3-votes"></li>""", '<li>Choice: <input type="text" name="choices-3-choice"></li>'
'<li>Votes: <input type="number" name="choices-3-votes"></li>',
) )
# Retrieving an empty form works. Tt shows up in the form list. # Retrieving an empty form works. Tt shows up in the form list.
self.assertTrue(formset.empty_form.empty_permitted) self.assertTrue(formset.empty_form.empty_permitted)
@ -595,15 +597,17 @@ class FormsFormsetTestCase(SimpleTestCase):
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form.as_ul() for form in formset.forms), "\n".join(form.as_ul() for form in formset.forms),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li> '<li>Choice: <input type="text" name="choices-0-choice" value="Calexico">'
<li>Votes: <input type="number" name="choices-0-votes" value="100"></li> "</li>"
<li>Delete: <input type="checkbox" name="choices-0-DELETE"></li> '<li>Votes: <input type="number" name="choices-0-votes" value="100"></li>'
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li> '<li>Delete: <input type="checkbox" name="choices-0-DELETE"></li>'
<li>Votes: <input type="number" name="choices-1-votes" value="900"></li> '<li>Choice: <input type="text" name="choices-1-choice" value="Fergie">'
<li>Delete: <input type="checkbox" name="choices-1-DELETE"></li> "</li>"
<li>Choice: <input type="text" name="choices-2-choice"></li> '<li>Votes: <input type="number" name="choices-1-votes" value="900"></li>'
<li>Votes: <input type="number" name="choices-2-votes"></li> '<li>Delete: <input type="checkbox" name="choices-1-DELETE"></li>'
<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>""", '<li>Choice: <input type="text" name="choices-2-choice"></li>'
'<li>Votes: <input type="number" name="choices-2-votes"></li>'
'<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>',
) )
# To delete something, set that form's special delete field to 'on'. # To delete something, set that form's special delete field to 'on'.
# Let's go ahead and delete Fergie. # Let's go ahead and delete Fergie.
@ -738,15 +742,17 @@ class FormsFormsetTestCase(SimpleTestCase):
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form.as_ul() for form in formset.forms), "\n".join(form.as_ul() for form in formset.forms),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li> '<li>Choice: <input type="text" name="choices-0-choice" value="Calexico">'
<li>Votes: <input type="number" name="choices-0-votes" value="100"></li> "</li>"
<li>Order: <input type="number" name="choices-0-ORDER" value="1"></li> '<li>Votes: <input type="number" name="choices-0-votes" value="100"></li>'
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li> '<li>Order: <input type="number" name="choices-0-ORDER" value="1"></li>'
<li>Votes: <input type="number" name="choices-1-votes" value="900"></li> '<li>Choice: <input type="text" name="choices-1-choice" value="Fergie">'
<li>Order: <input type="number" name="choices-1-ORDER" value="2"></li> "</li>"
<li>Choice: <input type="text" name="choices-2-choice"></li> '<li>Votes: <input type="number" name="choices-1-votes" value="900"></li>'
<li>Votes: <input type="number" name="choices-2-votes"></li> '<li>Order: <input type="number" name="choices-1-ORDER" value="2"></li>'
<li>Order: <input type="number" name="choices-2-ORDER"></li>""", '<li>Choice: <input type="text" name="choices-2-choice"></li>'
'<li>Votes: <input type="number" name="choices-2-votes"></li>'
'<li>Order: <input type="number" name="choices-2-ORDER"></li>',
) )
data = { data = {
"choices-TOTAL_FORMS": "3", # the number of forms rendered "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") formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
self.assertHTMLEqual( self.assertHTMLEqual(
"\n".join(form.as_ul() for form in formset.forms), "\n".join(form.as_ul() for form in formset.forms),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li> '<li>Choice: <input type="text" name="choices-0-choice" value="Calexico">'
<li>Votes: <input type="number" name="choices-0-votes" value="100"></li> "</li>"
<li>Order: <input type="number" name="choices-0-ORDER" value="1"></li> '<li>Votes: <input type="number" name="choices-0-votes" value="100"></li>'
<li>Delete: <input type="checkbox" name="choices-0-DELETE"></li> '<li>Order: <input type="number" name="choices-0-ORDER" value="1"></li>'
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li> '<li>Delete: <input type="checkbox" name="choices-0-DELETE"></li>'
<li>Votes: <input type="number" name="choices-1-votes" value="900"></li> '<li>Choice: <input type="text" name="choices-1-choice" value="Fergie">'
<li>Order: <input type="number" name="choices-1-ORDER" value="2"></li> "</li>"
<li>Delete: <input type="checkbox" name="choices-1-DELETE"></li> '<li>Votes: <input type="number" name="choices-1-votes" value="900"></li>'
<li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists"></li> '<li>Order: <input type="number" name="choices-1-ORDER" value="2"></li>'
<li>Votes: <input type="number" name="choices-2-votes" value="500"></li> '<li>Delete: <input type="checkbox" name="choices-1-DELETE"></li>'
<li>Order: <input type="number" name="choices-2-ORDER" value="3"></li> '<li>Choice: <input type="text" name="choices-2-choice" '
<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li> 'value="The Decemberists"></li>'
<li>Choice: <input type="text" name="choices-3-choice"></li> '<li>Votes: <input type="number" name="choices-2-votes" value="500"></li>'
<li>Votes: <input type="number" name="choices-3-votes"></li> '<li>Order: <input type="number" name="choices-2-ORDER" value="3"></li>'
<li>Order: <input type="number" name="choices-3-ORDER"></li> '<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>'
<li>Delete: <input type="checkbox" name="choices-3-DELETE"></li>""", '<li>Choice: <input type="text" name="choices-3-choice"></li>'
'<li>Votes: <input type="number" name="choices-3-votes"></li>'
'<li>Order: <input type="number" name="choices-3-ORDER"></li>'
'<li>Delete: <input type="checkbox" name="choices-3-DELETE"></li>',
) )
# Let's delete Fergie, and put The Decemberists ahead of Calexico. # Let's delete Fergie, and put The Decemberists ahead of Calexico.
data = { data = {

View File

@ -1929,26 +1929,28 @@ class ModelFormBasicTests(TestCase):
f = ArticleForm(auto_id=False) f = ArticleForm(auto_id=False)
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_ul(), f.as_ul(),
"""<li>Headline: <input type="text" name="headline" maxlength="50" required></li> '<li>Headline: <input type="text" name="headline" maxlength="50" required>'
<li>Slug: <input type="text" name="slug" maxlength="50" required></li> "</li>"
<li>Pub date: <input type="text" name="pub_date" required></li> '<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
<li>Writer: <select name="writer" required> '<li>Pub date: <input type="text" name="pub_date" required></li>'
<option value="" selected>---------</option> '<li>Writer: <select name="writer" required>'
<option value="%s">Bob Woodward</option> '<option value="" selected>---------</option>'
<option value="%s">Mike Royko</option> '<option value="%s">Bob Woodward</option>'
</select></li> '<option value="%s">Mike Royko</option>'
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li> "</select></li>"
<li>Categories: <select multiple name="categories"> '<li>Article: <textarea rows="10" cols="40" name="article" required>'
<option value="%s">Entertainment</option> "</textarea></li>"
<option value="%s">It&#x27;s a test</option> '<li>Categories: <select multiple name="categories">'
<option value="%s">Third test</option> '<option value="%s">Entertainment</option>'
</select> </li> '<option value="%s">It&#x27;s a test</option>'
<li>Status: <select name="status"> '<option value="%s">Third test</option>'
<option value="" selected>---------</option> "</select> </li>"
<option value="1">Draft</option> '<li>Status: <select name="status">'
<option value="2">Pending</option> '<option value="" selected>---------</option>'
<option value="3">Live</option> '<option value="1">Draft</option>'
</select></li>""" '<option value="2">Pending</option>'
'<option value="3">Live</option>'
"</select></li>"
% (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk), % (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") w_bernstein = Writer.objects.create(name="Carl Bernstein")
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_ul(), f.as_ul(),
"""<li>Headline: <input type="text" name="headline" maxlength="50" required></li> '<li>Headline: <input type="text" name="headline" maxlength="50" required>'
<li>Slug: <input type="text" name="slug" maxlength="50" required></li> "</li>"
<li>Pub date: <input type="text" name="pub_date" required></li> '<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
<li>Writer: <select name="writer" required> '<li>Pub date: <input type="text" name="pub_date" required></li>'
<option value="" selected>---------</option> '<li>Writer: <select name="writer" required>'
<option value="%s">Bob Woodward</option> '<option value="" selected>---------</option>'
<option value="%s">Carl Bernstein</option> '<option value="%s">Bob Woodward</option>'
<option value="%s">Mike Royko</option> '<option value="%s">Carl Bernstein</option>'
</select></li> '<option value="%s">Mike Royko</option>'
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li> "</select></li>"
<li>Categories: <select multiple name="categories"> '<li>Article: <textarea rows="10" cols="40" name="article" required>'
<option value="%s">Entertainment</option> "</textarea></li>"
<option value="%s">It&#x27;s a test</option> '<li>Categories: <select multiple name="categories">'
<option value="%s">Third test</option> '<option value="%s">Entertainment</option>'
<option value="%s">Fourth</option> '<option value="%s">It&#x27;s a test</option>'
</select></li> '<option value="%s">Third test</option>'
<li>Status: <select name="status"> '<option value="%s">Fourth</option>'
<option value="" selected>---------</option> "</select></li>"
<option value="1">Draft</option> '<li>Status: <select name="status">'
<option value="2">Pending</option> '<option value="" selected>---------</option>'
<option value="3">Live</option> '<option value="1">Draft</option>'
</select></li>""" '<option value="2">Pending</option>'
'<option value="3">Live</option>'
"</select></li>"
% ( % (
self.w_woodward.pk, self.w_woodward.pk,
w_bernstein.pk, w_bernstein.pk,

View File

@ -29,10 +29,11 @@ class StaticFilesFormsMediaTestCase(SimpleTestCase):
) )
self.assertEqual( self.assertEqual(
str(m), str(m),
"""<link href="https://example.com/assets/path/to/css1" media="all" rel="stylesheet"> '<link href="https://example.com/assets/path/to/css1" media="all" '
<link href="/path/to/css2" media="all" rel="stylesheet"> 'rel="stylesheet">\n'
<script src="/path/to/js1"></script> '<link href="/path/to/css2" media="all" rel="stylesheet">\n'
<script src="http://media.other.com/path/to/js2"></script> '<script src="/path/to/js1"></script>\n'
<script src="https://secure.other.com/path/to/js3"></script> '<script src="http://media.other.com/path/to/js2"></script>\n'
<script src="https://example.com/assets/relative/path/to/js4"></script>""", '<script src="https://secure.other.com/path/to/js3"></script>\n'
'<script src="https://example.com/assets/relative/path/to/js4"></script>',
) )