diff --git a/csdl/__init__.py b/csdl/__init__.py index 99cbd9e..348c2de 100644 --- a/csdl/__init__.py +++ b/csdl/__init__.py @@ -36,7 +36,7 @@ def quit_sub_system(flags): errcheck(_SDL.SDL_QuitSubSystem(flags)) def was_init(flags=0): - errcheck(_SDL.SDL_WasInit(flags)) + return errcheck(_SDL.SDL_WasInit(flags)) def quit(): _SDL.SDL_Quit() diff --git a/csdl/tests/test_basics.py b/csdl/tests/test_basics.py new file mode 100644 index 0000000..20c20eb --- /dev/null +++ b/csdl/tests/test_basics.py @@ -0,0 +1,52 @@ +import csdl +from nose.tools import with_setup + +def test_error_handling(): + # blank by default + assert csdl.get_error() == "" + + # check set + csdl.set_error("test!") + assert csdl.get_error() == "test!" + + # check again, shouldn't clear + assert csdl.get_error() == "test!" + + # clear again + csdl.clear_error() + assert csdl.get_error() == "" + +@with_setup(csdl.quit) +def test_init(): + csdl.init(csdl.InitFlags.EVERYTHING) + # everything should include these + assert csdl.was_init(csdl.InitFlags.TIMER|csdl.InitFlags.AUDIO| + csdl.InitFlags.VIDEO|csdl.InitFlags.JOYSTICK| + csdl.InitFlags.HAPTIC) + +@with_setup(csdl.quit) +def test_quit(): + csdl.init(csdl.InitFlags.EVERYTHING) + csdl.quit() + assert csdl.was_init(0) == 0 + +@with_setup(csdl.quit) +def test_init_sub_system(): + csdl.init_sub_system(csdl.InitFlags.TIMER) + assert csdl.was_init(csdl.InitFlags.TIMER) + +@with_setup(csdl.quit) +def test_quit_sub_system(): + csdl.init_sub_system(csdl.InitFlags.TIMER) + assert csdl.was_init(csdl.InitFlags.TIMER) + csdl.quit_sub_system(csdl.InitFlags.TIMER) + assert not csdl.was_init(csdl.InitFlags.TIMER) + +def test_version(): + v = csdl.get_version() + assert repr(v).startswith('Version') + assert str(v).startswith('1.3') + assert v.major == 1 and v.minor == 3 + +def test_revision(): + assert csdl.get_revision().startswith('hg') diff --git a/csdl/tests/test_enum.py b/csdl/tests/test_enum.py index bcfae58..aeaf323 100644 --- a/csdl/tests/test_enum.py +++ b/csdl/tests/test_enum.py @@ -1,4 +1,5 @@ from csdl.enum import CEnum, CEnumSymbol +import nose.tools class TestEnum(CEnum): FIRST = 0 @@ -18,6 +19,10 @@ def test_enumsymbol(): def test_cenum(): assert len(TestEnum.values()) == 3 + assert len(list(iter(TestEnum))) == 3 + +def test_cenum_from_int(): big_hopefully = TestEnum.from_int(9001) assert isinstance(big_hopefully, CEnumSymbol) assert big_hopefully.name == 'BIG' + nose.tools.assert_raises(ValueError, TestEnum.from_int, 50) diff --git a/csdl/tests/test_sysinfo.py b/csdl/tests/test_sysinfo.py new file mode 100644 index 0000000..c431455 --- /dev/null +++ b/csdl/tests/test_sysinfo.py @@ -0,0 +1,15 @@ +from csdl import sysinfo + +def test_get_platform(): + assert isinstance(sysinfo.get_platform(), str) + +def test_cpu_info(): + assert sysinfo.get_cpu_cache_line_size() > 0 + assert sysinfo.get_cpu_count() > 0 + +def test_power_info(): + state, seconds, percent = sysinfo.get_power_info() + assert state in ('UNKNOWN', 'ON_BATTERY', 'NO_BATTERY', 'CHARGING', + 'CHARGED') + assert isinstance(seconds, int) + assert isinstance(percent, int)