def test_element_tree_paths(self): my_block = MyBlock() tb = gras.TopBlock() hb = gras.HierBlock() tb.adopt_element("my_hier", hb) hb.adopt_element("my_block", my_block) my_block.set_foo(42) self.assertEqual(my_block.get_foo(), 42) my_block0 = tb.locate_element('/my_hier/my_block') self.assertEqual(my_block0.get_foo(), 42) my_block1 = hb.locate_element('my_block') self.assertEqual(my_block1.get_foo(), 42) my_block2 = hb.locate_element('./../my_hier/my_block') self.assertEqual(my_block2.get_foo(), 42) threw = False try: hb.locate_element('../../my_hier/my_block') except: threw = True self.assertTrue(threw) threw = False try: hb.locate_element('../../my_hier/my_block0') except: threw = True self.assertTrue(threw) threw = False try: hb.locate_element('../../my_hier/my_block/test') except: threw = True self.assertTrue(threw)
def test_migrate_to_thread_pool(self): tb = gras.TopBlock() vec_source = TestUtils.VectorSource(numpy.uint32, [0, 9, 8, 7, 6]) vec_sink = TestUtils.VectorSink(numpy.uint32) c = gras.ThreadPoolConfig() tp = gras.ThreadPool(c) vec_source.global_config().thread_pool = tp vec_source.commit_config() tb.connect(vec_source, vec_sink) tb.run() self.assertEqual(vec_sink.data(), (0, 9, 8, 7, 6))
def test_delay_simple(self): for delay in (0, 100, 1000, 10000): src_data = [1, 2, 3, 4, 5, 6, 7, 8] expected_result = tuple([0] * delay + src_data) src = TestUtils.VectorSource(numpy.float32, src_data) op = gras.make('/grex/delay', numpy.dtype(numpy.float32).itemsize) op.set_delay(delay) dst = TestUtils.VectorSink(numpy.float32) tb = gras.TopBlock() tb.connect(src, op, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_stream_selector_simple(self): ss = gras.make('/grex/stream_selector', numpy.dtype(numpy.float32).itemsize) ss.set_paths([1, 0]) #in[0] -> out[1], in[1] -> out[0] src0 = TestUtils.VectorSource(numpy.float32, [1, 2, 3, 4]) src1 = TestUtils.VectorSource(numpy.float32, [5, 6, 7, 8]) dst0 = TestUtils.VectorSink(numpy.float32) dst1 = TestUtils.VectorSink(numpy.float32) tb = gras.TopBlock() tb.connect(src0, (ss, 0), dst0) tb.connect(src1, (ss, 1), dst1) tb.start() time.sleep(0.5) tb.stop() tb.wait() self.assertEqual((1, 2, 3, 4), dst1.data()) self.assertEqual((5, 6, 7, 8), dst0.data())
def setUp(self): self.tb = gras.TopBlock()
def test_make_top(self): t = gras.TopBlock('my_tb') print t