Commits

Carl Meyer committed 9560187 Merge

Merge pull request #16 from ryankask/choices-len

__len__ method for Choices

  • Participants
  • Parent commits 0a64d04, f43cefa

Comments (0)

Files changed (3)

 Jannis Leidel <jannis@leidel.info>
 Jeff Elmore <jeffelmore.org>
 Paul McLanahan <paul@mclanahan.net>
-Ryan Kaskel
+Ryan Kaskel <dev@ryankaskel.com>
 sayane
 zyegfryed

model_utils/__init__.py

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

model_utils/tests/tests.py

         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("
         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("
         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("