From fdbd272971b45ccb6fe9a06003b76f316e738f20 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sun, 27 Mar 2011 15:18:04 -0400 Subject: [PATCH] tests for enum & internals --- csdl/tests/__init__.py | 0 csdl/tests/test_enum.py | 23 +++++++++++++++++++++++ csdl/tests/test_internals.py | 24 ++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 csdl/tests/__init__.py create mode 100644 csdl/tests/test_enum.py create mode 100644 csdl/tests/test_internals.py diff --git a/csdl/tests/__init__.py b/csdl/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/csdl/tests/test_enum.py b/csdl/tests/test_enum.py new file mode 100644 index 0000000..bcfae58 --- /dev/null +++ b/csdl/tests/test_enum.py @@ -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) == '' + assert repr(TestEnum.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' diff --git a/csdl/tests/test_internals.py b/csdl/tests/test_internals.py new file mode 100644 index 0000000..7584bf2 --- /dev/null +++ b/csdl/tests/test_internals.py @@ -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