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/block_props_test.py | |
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/block_props_test.py')
-rw-r--r-- | tests/block_props_test.py | 53 |
1 files changed, 53 insertions, 0 deletions
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() |