Skip to content

Commit

Permalink
Basic tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigjason committed Feb 24, 2011
1 parent bca896b commit 34264d0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dist/
*egg-info
*.pyc
.project
.pydevproject

14 changes: 11 additions & 3 deletions djchoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ class ChoiceItem(object):
normally be left blank. Set a label if you need characters that are illegal
in a python identifier name (ie: "DVD/Movie").
"""
def __init__(self, value, order=0, label=None):
order = 0
def __init__(self, value, label=None, order=None):
self.value = value
self.order = order
if order:
self.order = order
else:
ChoiceItem.order += 1
self.order = ChoiceItem.order
self.label = label

# Shorter convenience alias.
C = ChoiceItem

class DjangoChoicesMeta(type):
"""
Expand Down Expand Up @@ -52,7 +60,7 @@ def __get__(self, obj, objtype):

return super(DjangoChoicesMeta, cls).__new__(cls, name, bases, attrs)

class ChoicesBase(object):
class DjangoChoices(object):
order = 0
choices = ()
__metaclass__ = DjangoChoicesMeta
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
url="https://github.com/bigjason/django-choices",
author="Jason Webb",
author_email="bigjasonwebb@gmail.com",
py_modules=["djchoices"],
py_modules=["djchoices", "test_djchoices"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
Expand Down
27 changes: 27 additions & 0 deletions test_djchoices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from djchoices import DjangoChoices, C, ChoiceItem

class NumericTestClass(DjangoChoices):
Item_1 = C(1)
Item_2 = C(2)
Item_3 = C(3)

class DjangoChoices(unittest.TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test_numeric_class_values(self):
self.assertEqual(NumericTestClass.Item_1, 1)
self.assertEqual(NumericTestClass.Item_2, 2)
self.assertEqual(NumericTestClass.Item_3, 3)

def test_numeric_class_order(self):
choices = NumericTestClass.choices
self.assertEqual(choices[0][0], 1)
self.assertEqual(choices[1][0], 2)
self.assertEqual(choices[2][0], 3)

0 comments on commit 34264d0

Please sign in to comment.