Add __len__() method to Choices

This commit is contained in:
James Oakley 2012-10-30 11:01:57 -07:00
parent f85e59c5d0
commit 9ea6605226
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):