Merged in jfunk/django-model-utils (pull request #9)

Add __len__() method to Choices
This commit is contained in:
Carl Meyer 2013-01-26 15:52:47 -08:00
commit 6935f73233
2 changed files with 6 additions and 0 deletions

View file

@ -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)

View file

@ -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):