mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-04-18 10:20:59 +00:00
Add __len__() method to Choices
This commit is contained in:
parent
f85e59c5d0
commit
9ea6605226
2 changed files with 6 additions and 0 deletions
|
|
@ -118,6 +118,9 @@ class Choices(object):
|
|||
else:
|
||||
yield (choice, choice, choice)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._choices)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._choices)
|
||||
|
||||
|
|
|
|||
|
|
@ -193,6 +193,9 @@ class ChoicesTests(TestCase):
|
|||
def test_wrong_length_tuple(self):
|
||||
self.assertRaises(ValueError, Choices, ('a',))
|
||||
|
||||
def test_len(self):
|
||||
self.assertEquals(len(self.STATUS), len(self.STATUS._choices))
|
||||
|
||||
|
||||
|
||||
class LabelChoicesTests(ChoicesTests):
|
||||
|
|
|
|||
Loading…
Reference in a new issue