diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/example_module.cpp | 2 | ||||
-rw-r--r-- | tests/example_module.py | 16 | ||||
-rw-r--r-- | tests/module_loader_test.py | 8 |
4 files changed, 28 insertions, 3 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5c76dbe..3c82320 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,10 @@ include(GrTest) +#define these blank so they dont interfere with tests +list(APPEND GR_TEST_ENVIRONS "GRAS_ROOT=") +list(APPEND GR_TEST_ENVIRONS "GRAS_PATH=") + ######################################################################## # unit test suite ######################################################################## @@ -64,4 +68,5 @@ file(TO_NATIVE_PATH "${example_module_location}" example_module_location) message(STATUS "example_module_location: ${example_module_location}") list(APPEND GR_TEST_ENVIRONS "GRAS_MODULE_PATH=${example_module_location}") +list(APPEND GR_TEST_ENVIRONS "GRAS_PYTHON_PATH=${CMAKE_CURRENT_SOURCE_DIR}/example_module.py") GR_ADD_TEST(module_loader_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/module_loader_test.py) diff --git a/tests/example_module.cpp b/tests/example_module.cpp index 2191650..d0316f8 100644 --- a/tests/example_module.cpp +++ b/tests/example_module.cpp @@ -31,4 +31,4 @@ gras::Block *make_my_block(void) return new MyBlock(); } -GRAS_REGISTER_FACTORY("/tests/my_block", make_my_block) +GRAS_REGISTER_FACTORY("/tests/my_block0", make_my_block) diff --git a/tests/example_module.py b/tests/example_module.py new file mode 100644 index 0000000..6c29435 --- /dev/null +++ b/tests/example_module.py @@ -0,0 +1,16 @@ +# Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +import gras + +class MyBlock(gras.Block): + def __init__(self): + gras.Block.__init__(self, "MyBlock") + self.foo = 0 + self.register_call("get_num", self.get_num) + + def work(self, *args): pass + + def get_num(self): + return 42 + +gras.Factory.register_make("/tests/my_block1", MyBlock) diff --git a/tests/module_loader_test.py b/tests/module_loader_test.py index 8b7a0c9..4a8d64f 100644 --- a/tests/module_loader_test.py +++ b/tests/module_loader_test.py @@ -5,8 +5,12 @@ import gras class ModuleLoaderTest(unittest.TestCase): - def test_load_module(self): - my_block = gras.Factory.make("/tests/my_block") + def test_load_module_cpp(self): + my_block = gras.Factory.make("/tests/my_block0") + self.assertEqual(my_block.get_num(), 42) + + def test_load_module_py(self): + my_block = gras.Factory.make("/tests/my_block1") self.assertEqual(my_block.get_num(), 42) if __name__ == '__main__': |