mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #35766 -- Handled slices in BaseChoiceIterator.
This commit is contained in:
parent
9ca1f6eff6
commit
ae1ee24178
2 changed files with 30 additions and 2 deletions
|
@ -183,6 +183,33 @@ class ChoicesTests(SimpleTestCase):
|
|||
self.choices_from_callable.choices.func(), [(0, "0"), (1, "1"), (2, "2")]
|
||||
)
|
||||
|
||||
def test_choices_slice(self):
|
||||
for choices, expected_slice in [
|
||||
(self.empty_choices.choices, []),
|
||||
(self.empty_choices_bool.choices, []),
|
||||
(self.empty_choices_text.choices, []),
|
||||
(self.with_choices.choices, [(1, "A")]),
|
||||
(self.with_choices_dict.choices, [(1, "A")]),
|
||||
(self.with_choices_nested_dict.choices, [("Thing", [(1, "A")])]),
|
||||
(self.choices_from_iterator.choices, [(0, "0"), (1, "1")]),
|
||||
(self.choices_from_callable.choices.func(), [(0, "0"), (1, "1")]),
|
||||
(self.choices_from_callable.choices, [(0, "0"), (1, "1")]),
|
||||
]:
|
||||
with self.subTest(choices=choices):
|
||||
self.assertEqual(choices[:2], expected_slice)
|
||||
|
||||
def test_choices_negative_index(self):
|
||||
for choices, expected_choice in [
|
||||
(self.with_choices.choices, (1, "A")),
|
||||
(self.with_choices_dict.choices, (1, "A")),
|
||||
(self.with_choices_nested_dict.choices, ("Thing", [(1, "A")])),
|
||||
(self.choices_from_iterator.choices, (2, "2")),
|
||||
(self.choices_from_callable.choices.func(), (2, "2")),
|
||||
(self.choices_from_callable.choices, (2, "2")),
|
||||
]:
|
||||
with self.subTest(choices=choices):
|
||||
self.assertEqual(choices[-1], expected_choice)
|
||||
|
||||
def test_flatchoices(self):
|
||||
self.assertEqual(self.no_choices.flatchoices, [])
|
||||
self.assertEqual(self.empty_choices.flatchoices, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue