diff options
Diffstat (limited to 'tests/query_test.py')
-rw-r--r-- | tests/query_test.py | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/tests/query_test.py b/tests/query_test.py index e93b5d6..ec8fade 100644 --- a/tests/query_test.py +++ b/tests/query_test.py @@ -4,7 +4,27 @@ import unittest import gras import numpy from demo_blocks import * -import json + +class MyBlock(gras.Block): + def __init__(self): + gras.Block.__init__(self, "MyBlock", out_sig=[numpy.uint32], in_sig=[numpy.uint32]) + self.foo = 0 + self.register_getter("foo", self.get_foo) + self.register_setter("foo", self.set_foo) + + def work(self, ins, outs): + n = min(len(ins[0]), len(outs[0])) + outs[0][:n] = ins[0][:n] + self.foo + self.consume(n) + self.produce(n) + + def get_foo(self): + return self.foo + + def set_foo(self, new_foo): + print "new_foo", new_foo + new_foo + 0 #throws if its not a number + self.foo = new_foo class QueryTest(unittest.TestCase): @@ -23,13 +43,34 @@ class QueryTest(unittest.TestCase): self.assertEqual(vec_sink.get_vector(), (0, 9, 8, 7, 6)) - blocks_json = self.tb.query("<args><path>/blocks.json</path></args>") - print blocks_json - json.loads(blocks_json) + #query the block list + blocks_result = self.tb.query(dict(path="/blocks.json")) + self.assertEqual(len(blocks_result['blocks']), 2) + + #pick a block to query below: + block_id = blocks_result['blocks'].keys()[0] + + #query the stats + stats_result = self.tb.query(dict( + path="/stats.json", + blocks=[block_id], + )) + self.assertTrue('tps' in stats_result) + self.assertTrue('now' in stats_result) + + #found the block we asked for + self.assertTrue(block_id in stats_result['blocks']) + + def test_props(self): + vec_source = VectorSource(numpy.uint32, [0, 9, 8, 7, 6]) + vec_sink = VectorSink(numpy.uint32) + block = MyBlock() + self.tb.connect(vec_source, block, vec_sink) + self.tb.run() - stats_json = self.tb.query("<args><path>/stats.json</path></args>") - print stats_json - json.loads(stats_json) + #query the block list + blocks_result = self.tb.query(dict(path="/blocks.json")) + self.assertEqual(len(blocks_result['blocks']), 3) if __name__ == '__main__': unittest.main() |