mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-17 04:10:24 +00:00
len support for Choices.
This commit is contained in:
parent
ea4f98d91f
commit
7cbfbdb453
2 changed files with 15 additions and 0 deletions
|
|
@ -130,6 +130,9 @@ class Choices(object):
|
|||
def __getitem__(self, index):
|
||||
return self._choices[index]
|
||||
|
||||
def __len__(self):
|
||||
return len(self._choices)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (self.__class__.__name__,
|
||||
', '.join(("%s" % str(i) for i in self._full)))
|
||||
|
|
|
|||
|
|
@ -183,6 +183,10 @@ class ChoicesTests(TestCase):
|
|||
self.assertEquals(tuple(self.STATUS), (('DRAFT', 'DRAFT'), ('PUBLISHED', 'PUBLISHED')))
|
||||
|
||||
|
||||
def test_len(self):
|
||||
self.assertEqual(len(self.STATUS), 2)
|
||||
|
||||
|
||||
def test_repr(self):
|
||||
self.assertEquals(repr(self.STATUS),
|
||||
"Choices("
|
||||
|
|
@ -224,6 +228,10 @@ class LabelChoicesTests(ChoicesTests):
|
|||
self.assertEquals(self.STATUS.DRAFT, 'DRAFT')
|
||||
|
||||
|
||||
def test_len(self):
|
||||
self.assertEqual(len(self.STATUS), 3)
|
||||
|
||||
|
||||
def test_repr(self):
|
||||
self.assertEquals(repr(self.STATUS),
|
||||
"Choices("
|
||||
|
|
@ -256,6 +264,10 @@ class IdentifierChoicesTests(ChoicesTests):
|
|||
self.assertEquals(self.STATUS.DRAFT, 0)
|
||||
|
||||
|
||||
def test_len(self):
|
||||
self.assertEqual(len(self.STATUS), 3)
|
||||
|
||||
|
||||
def test_repr(self):
|
||||
self.assertEquals(repr(self.STATUS),
|
||||
"Choices("
|
||||
|
|
|
|||
Loading…
Reference in a new issue