diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-08 12:09:55 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-08 12:15:38 +0100 |
| commit | 6a682b38e75d4c975b4c4493565a59f1bc14397c (patch) | |
| tree | 0bd9cda550bea26238656d9f120d769e8b41bb9e /tests/forms_tests/widget_tests/test_selectmultiple.py | |
| parent | e73ce08888e6f34d3f050377cfd2fbb733be94a9 (diff) | |
[4.0.x] Refs #33476 -- Reformatted code with Black.
Backport of 9c19aff7c7561e3a82978a272ecdaad40dda5c00 from main.
Diffstat (limited to 'tests/forms_tests/widget_tests/test_selectmultiple.py')
| -rw-r--r-- | tests/forms_tests/widget_tests/test_selectmultiple.py | 134 |
1 files changed, 94 insertions, 40 deletions
diff --git a/tests/forms_tests/widget_tests/test_selectmultiple.py b/tests/forms_tests/widget_tests/test_selectmultiple.py index eb144ba4b3..99b53521e7 100644 --- a/tests/forms_tests/widget_tests/test_selectmultiple.py +++ b/tests/forms_tests/widget_tests/test_selectmultiple.py @@ -5,134 +5,188 @@ from .base import WidgetTest class SelectMultipleTest(WidgetTest): widget = SelectMultiple - numeric_choices = (('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('0', 'extra')) + numeric_choices = (("0", "0"), ("1", "1"), ("2", "2"), ("3", "3"), ("0", "extra")) def test_format_value(self): widget = self.widget(choices=self.numeric_choices) self.assertEqual(widget.format_value(None), []) - self.assertEqual(widget.format_value(''), ['']) - self.assertEqual(widget.format_value([3, 0, 1]), ['3', '0', '1']) + self.assertEqual(widget.format_value(""), [""]) + self.assertEqual(widget.format_value([3, 0, 1]), ["3", "0", "1"]) def test_render_selected(self): - self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=( - """<select multiple name="beatles"> + self.check_html( + self.widget(choices=self.beatles), + "beatles", + ["J"], + html=( + """<select multiple name="beatles"> <option value="J" selected>John</option> <option value="P">Paul</option> <option value="G">George</option> <option value="R">Ringo</option> </select>""" - )) + ), + ) def test_render_multiple_selected(self): - self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=( - """<select multiple name="beatles"> + self.check_html( + self.widget(choices=self.beatles), + "beatles", + ["J", "P"], + html=( + """<select multiple name="beatles"> <option value="J" selected>John</option> <option value="P" selected>Paul</option> <option value="G">George</option> <option value="R">Ringo</option> </select>""" - )) + ), + ) def test_render_none(self): """ If the value is None, none of the options are selected, even if the choices have an empty option. """ - self.check_html(self.widget(choices=(('', 'Unknown'),) + self.beatles), 'beatles', None, html=( - """<select multiple name="beatles"> + self.check_html( + self.widget(choices=(("", "Unknown"),) + self.beatles), + "beatles", + None, + html=( + """<select multiple name="beatles"> <option value="">Unknown</option> <option value="J">John</option> <option value="P">Paul</option> <option value="G">George</option> <option value="R">Ringo</option> </select>""" - )) + ), + ) def test_render_value_label(self): """ If the value corresponds to a label (but not to an option value), none of the options are selected. """ - self.check_html(self.widget(choices=self.beatles), 'beatles', ['John'], html=( - """<select multiple name="beatles"> + self.check_html( + self.widget(choices=self.beatles), + "beatles", + ["John"], + html=( + """<select multiple name="beatles"> <option value="J">John</option> <option value="P">Paul</option> <option value="G">George</option> <option value="R">Ringo</option> </select>""" - )) + ), + ) def test_multiple_options_same_value(self): """ Multiple options with the same value can be selected (#8103). """ - self.check_html(self.widget(choices=self.numeric_choices), 'choices', ['0'], html=( - """<select multiple name="choices"> + self.check_html( + self.widget(choices=self.numeric_choices), + "choices", + ["0"], + html=( + """<select multiple name="choices"> <option value="0" selected>0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="0" selected>extra</option> </select>""" - )) + ), + ) def test_multiple_values_invalid(self): """ If multiple values are given, but some of them are not valid, the valid ones are selected. """ - self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'G', 'foo'], html=( - """<select multiple name="beatles"> + self.check_html( + self.widget(choices=self.beatles), + "beatles", + ["J", "G", "foo"], + html=( + """<select multiple name="beatles"> <option value="J" selected>John</option> <option value="P">Paul</option> <option value="G" selected>George</option> <option value="R">Ringo</option> </select>""" - )) + ), + ) def test_compare_string(self): - choices = [('1', '1'), ('2', '2'), ('3', '3')] + choices = [("1", "1"), ("2", "2"), ("3", "3")] - self.check_html(self.widget(choices=choices), 'nums', [2], html=( - """<select multiple name="nums"> + self.check_html( + self.widget(choices=choices), + "nums", + [2], + html=( + """<select multiple name="nums"> <option value="1">1</option> <option value="2" selected>2</option> <option value="3">3</option> </select>""" - )) + ), + ) - self.check_html(self.widget(choices=choices), 'nums', ['2'], html=( - """<select multiple name="nums"> + self.check_html( + self.widget(choices=choices), + "nums", + ["2"], + html=( + """<select multiple name="nums"> <option value="1">1</option> <option value="2" selected>2</option> <option value="3">3</option> </select>""" - )) + ), + ) - self.check_html(self.widget(choices=choices), 'nums', [2], html=( - """<select multiple name="nums"> + self.check_html( + self.widget(choices=choices), + "nums", + [2], + html=( + """<select multiple name="nums"> <option value="1">1</option> <option value="2" selected>2</option> <option value="3">3</option> </select>""" - )) + ), + ) def test_optgroup_select_multiple(self): - widget = SelectMultiple(choices=( - ('outer1', 'Outer 1'), - ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))), - )) - self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=( - """<select multiple name="nestchoice"> + widget = SelectMultiple( + choices=( + ("outer1", "Outer 1"), + ('Group "1"', (("inner1", "Inner 1"), ("inner2", "Inner 2"))), + ) + ) + self.check_html( + widget, + "nestchoice", + ["outer1", "inner2"], + html=( + """<select multiple name="nestchoice"> <option value="outer1" selected>Outer 1</option> <optgroup label="Group "1""> <option value="inner1">Inner 1</option> <option value="inner2" selected>Inner 2</option> </optgroup> </select>""" - )) + ), + ) def test_value_omitted_from_data(self): widget = self.widget(choices=self.beatles) - self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), False) - self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False) + self.assertIs(widget.value_omitted_from_data({}, {}, "field"), False) + self.assertIs( + widget.value_omitted_from_data({"field": "value"}, {}, "field"), False + ) |
