2011-03-27 19:18:04 +00:00
|
|
|
from csdl.enum import CEnum, CEnumSymbol
|
2011-03-28 04:22:31 +00:00
|
|
|
import nose.tools
|
2011-03-27 19:18:04 +00:00
|
|
|
|
|
|
|
class TestEnum(CEnum):
|
|
|
|
FIRST = 0
|
|
|
|
SPECIAL = 2, 'a special case'
|
|
|
|
BIG = 9001
|
|
|
|
|
|
|
|
def test_enumsymbol():
|
|
|
|
assert isinstance(TestEnum.FIRST, int)
|
|
|
|
assert TestEnum.FIRST == 0
|
|
|
|
assert TestEnum.SPECIAL == 2
|
|
|
|
assert TestEnum.FIRST.name == 'FIRST'
|
|
|
|
assert TestEnum.SPECIAL.name == 'SPECIAL'
|
|
|
|
assert TestEnum.FIRST.description == 'FIRST'
|
|
|
|
assert TestEnum.SPECIAL.description == 'a special case'
|
|
|
|
assert repr(TestEnum.FIRST) == '<FIRST>'
|
|
|
|
assert repr(TestEnum.SPECIAL) == '<SPECIAL>'
|
|
|
|
|
|
|
|
def test_cenum():
|
|
|
|
assert len(TestEnum.values()) == 3
|
2011-03-28 04:22:31 +00:00
|
|
|
assert len(list(iter(TestEnum))) == 3
|
|
|
|
|
|
|
|
def test_cenum_from_int():
|
2011-03-27 19:18:04 +00:00
|
|
|
big_hopefully = TestEnum.from_int(9001)
|
|
|
|
assert isinstance(big_hopefully, CEnumSymbol)
|
|
|
|
assert big_hopefully.name == 'BIG'
|
2011-03-28 04:22:31 +00:00
|
|
|
nose.tools.assert_raises(ValueError, TestEnum.from_int, 50)
|