tests for enum & internals

This commit is contained in:
James Turk 2011-03-27 15:18:04 -04:00
parent 4388b17f78
commit fdbd272971
3 changed files with 47 additions and 0 deletions

0
csdl/tests/__init__.py Normal file
View File

23
csdl/tests/test_enum.py Normal file
View File

@ -0,0 +1,23 @@
from csdl.enum import CEnum, CEnumSymbol
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
big_hopefully = TestEnum.from_int(9001)
assert isinstance(big_hopefully, CEnumSymbol)
assert big_hopefully.name == 'BIG'

View File

@ -0,0 +1,24 @@
from nose.tools import with_setup, raises
from ..internal import _SDL, errcheck, Version, SDLError
def setup_func():
_SDL.SDL_ClearError()
@with_setup(setup_func)
def test_errcheck_noerr():
# set an error to ensure that errors aren't cleared
_SDL.SDL_SetError("test")
assert errcheck(2) == 2 # positive values should pass through
assert errcheck(0) == 0 # as should zero
assert _SDL.SDL_GetError() == "test"
@raises(SDLError)
@with_setup(setup_func)
def test_errcheck_err():
_SDL.SDL_SetError("err!")
try:
errcheck(-1) # negative values should trigger the SDLError
except SDLError as e:
assert str(e) == "err!"
raise # reraise error