diff options
author | Josh Blum | 2013-03-17 17:38:40 -0700 |
---|---|---|
committer | Josh Blum | 2013-03-17 17:38:40 -0700 |
commit | 468d53f7797c63cda2ef9ba765f1066550d19ce4 (patch) | |
tree | 4008d74ee3138114799e9bf8434f8356e8ad804f /tests | |
parent | 420f118ed61c52ae00b765b57be83bae910e0a60 (diff) | |
download | sandhi-468d53f7797c63cda2ef9ba765f1066550d19ce4.tar.gz sandhi-468d53f7797c63cda2ef9ba765f1066550d19ce4.tar.bz2 sandhi-468d53f7797c63cda2ef9ba765f1066550d19ce4.zip |
gras: work on python hooks for props interface
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/block_props_test.py | 53 |
2 files changed, 60 insertions, 6 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 23a834e..bfc193e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,7 +30,7 @@ foreach(test_source ${test_sources}) add_executable(${test_name} ${test_source}) target_link_libraries(${test_name} ${Boost_LIBRARIES} ${GRAS_LIBRARIES}) set(GR_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) - GR_ADD_TEST(${test_name} ${test_name}) + GR_ADD_TEST(${test_name}_cpp ${test_name}) endforeach(test_source) ######################################################################## @@ -39,8 +39,9 @@ endforeach(test_source) include(GrPython) set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}) -GR_ADD_TEST(block_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_test.py) -GR_ADD_TEST(hier_block_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/hier_block_test.py) -GR_ADD_TEST(thread_pool_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/thread_pool_test.py) -GR_ADD_TEST(sbuffer_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/sbuffer_test.py) -GR_ADD_TEST(stats_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/stats_test.py) +GR_ADD_TEST(block_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_test.py) +GR_ADD_TEST(hier_block_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/hier_block_test.py) +GR_ADD_TEST(thread_pool_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/thread_pool_test.py) +GR_ADD_TEST(sbuffer_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/sbuffer_test.py) +GR_ADD_TEST(stats_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/stats_test.py) +GR_ADD_TEST(block_props_py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_props_test.py) diff --git a/tests/block_props_test.py b/tests/block_props_test.py new file mode 100644 index 0000000..6c502a3 --- /dev/null +++ b/tests/block_props_test.py @@ -0,0 +1,53 @@ +# Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +import unittest +import gras +import numpy + +class MyBlock(gras.Block): + def __init__(self): + gras.Block.__init__(self, "MyBlock") + self.foo = 0 + self.register_property("foo", self.get_foo, self.set_foo) + + def work(self, *args): pass + + def get_foo(self): + return self.foo + + def set_foo(self, new_foo): + self.foo = new_foo + +class BlockPropsTest(unittest.TestCase): + + def test_property_set_get(self): + my_block = MyBlock() + self.assertEqual(my_block.foo, 0) + + my_block.set("foo", 42) + self.assertEqual(my_block.foo, 42) + + my_foo = my_block.get("foo") + self.assertEqual(my_foo, 42) + + def test_property_errors(self): + my_block = MyBlock() + + #property does not exist + threw = False + try: my_block.get("bar") + except Exception as ex: + print ex + threw = True + self.assertFalse(threw) + + #wrong type for property + threw = False + try: my_block.set("foo", float(42)) + except Exception as ex: + print ex + threw = True + self.assertFalse(threw) + +if __name__ == '__main__': + unittest.main() |