X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_graph.py;h=7a403b5cd3e68dd8b949cd88e72c78659c8cabd7;hp=852e3f01ce23e24c55f57fe15f64234fe9a6fa8d;hb=9b4f9b425f2efce9a6ccc25f7ae062ebc1116a7d;hpb=26fc5aedf48df3f1654fe4d0b6ada1a10cd804f2 diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 852e3f01..7a403b5c 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -35,9 +35,7 @@ class _MyIter(bt2._UserMessageIterator): self._ec = self._sc.create_event_class(name='salut') self._my_int_ft = self._tc.create_signed_integer_field_class(32) payload_ft = self._tc.create_structure_field_class() - payload_ft += collections.OrderedDict([ - ('my_int', self._my_int_ft), - ]) + payload_ft += [('my_int', self._my_int_ft)] self._ec.payload_field_type = payload_ft self._stream = self._t.create_stream(self._sc) self._packet = self._stream.create_packet() @@ -64,6 +62,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): + pass + comp = self._graph.add_component(MySink, 'salut') self.assertEqual(comp.name, 'salut') @@ -72,6 +73,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): + pass + comp = self._graph.add_component(MySink, 'salut') assert comp comp2 = self._graph.add_component(comp.cls, 'salut2') @@ -88,6 +92,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): + pass + params = {'hello': 23, 'path': '/path/to/stuff'} comp = self._graph.add_component(MySink, 'salut', params) self.assertEqual(params, comp_params) @@ -102,6 +109,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): + pass + with self.assertRaises(TypeError): self._graph.add_component(MySink, 'salut', logging_level='yo') @@ -110,6 +120,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): + pass + with self.assertRaises(ValueError): self._graph.add_component(MySink, 'salut', logging_level=12345) @@ -118,8 +131,12 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass - comp = self._graph.add_component(MySink, 'salut', - logging_level=bt2.LoggingLevel.DEBUG) + def _graph_is_configured(self): + pass + + comp = self._graph.add_component( + MySink, 'salut', logging_level=bt2.LoggingLevel.DEBUG + ) self.assertEqual(comp.logging_level, bt2.LoggingLevel.DEBUG) def test_connect_ports(self): @@ -127,8 +144,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -139,11 +155,15 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) self.assertTrue(src.output_ports['out'].is_connected) self.assertTrue(sink.input_ports['in'].is_connected) self.assertEqual(src.output_ports['out'].connection.addr, conn.addr) @@ -154,8 +174,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -166,27 +185,68 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') with self.assertRaises(TypeError): - conn = self._graph.connect_ports(sink.input_ports['in'], - src.output_ports['out']) + conn = self._graph.connect_ports( + sink.input_ports['in'], src.output_ports['out'] + ) + + def test_add_interrupter(self): + class MyIter(bt2._UserMessageIterator): + def __next__(self): + raise TypeError + + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + def __init__(self, params): + self._add_output_port('out') + + class MySink(bt2._UserSinkComponent): + def __init__(self, params): + self._add_input_port('in') + + def _consume(self): + next(self._msg_iter) + + def _graph_is_configured(self): + self._msg_iter = self._create_input_port_message_iterator( + self._input_ports['in'] + ) + + # add two interrupters, set one of them + interrupter1 = bt2.Interrupter() + interrupter2 = bt2.Interrupter() + self._graph.add_interrupter(interrupter1) + src = self._graph.add_component(MySource, 'src') + sink = self._graph.add_component(MySink, 'sink') + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) + self._graph.add_interrupter(interrupter2) + + with self.assertRaises(bt2._Error): + self._graph.run() + + interrupter2.set() + + with self.assertRaises(bt2.TryAgain): + self._graph.run() - def test_cancel(self): - self.assertFalse(self._graph.is_canceled) - self._graph.cancel() - self.assertTrue(self._graph.is_canceled) + interrupter2.reset() - # Test that Graph.run() raises bt2.Canceled if the graph gets canceled - # during execution. - def test_cancel_while_running(self): + with self.assertRaises(bt2._Error): + self._graph.run() + + # Test that Graph.run() raises bt2.Interrupted if the graph gets + # interrupted during execution. + def test_interrupt_while_running(self): class MyIter(_MyIter): def __next__(self): return self._create_stream_beginning_message(self._stream) - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -195,21 +255,23 @@ class GraphTestCase(unittest.TestCase): self._add_input_port('in') def _consume(self): - # Pretend that somebody asynchronously cancelled the graph. + # Pretend that somebody asynchronously interrupted the graph. nonlocal graph - graph.cancel() - + graph.interrupt() return next(self._msg_iter) def _graph_is_configured(self): - self._msg_iter = self._input_ports['in'].create_message_iterator() + self._msg_iter = self._create_input_port_message_iterator( + self._input_ports['in'] + ) - graph = bt2.Graph() - up = graph.add_component(MySource, 'down') - down = graph.add_component(MySink, 'up') - graph.connect_ports(up.output_ports['out'], down.input_ports['in']) - with self.assertRaises(bt2.Canceled): - graph.run() + graph = self._graph + up = self._graph.add_component(MySource, 'down') + down = self._graph.add_component(MySink, 'up') + self._graph.connect_ports(up.output_ports['out'], down.input_ports['in']) + + with self.assertRaises(bt2.TryAgain): + self._graph.run() def test_run(self): class MyIter(_MyIter): @@ -231,8 +293,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -259,12 +320,15 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 def _graph_is_configured(self): - self._msg_iter = self._input_port.create_message_iterator() + self._msg_iter = self._create_input_port_message_iterator( + self._input_port + ) src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) self._graph.run() def test_run_again(self): @@ -283,8 +347,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -308,12 +371,15 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 def _graph_is_configured(self): - self._msg_iter = self._input_port.create_message_iterator() + self._msg_iter = self._create_input_port_message_iterator( + self._input_port + ) src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) with self.assertRaises(bt2.TryAgain): self._graph.run() @@ -339,8 +405,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -365,14 +430,17 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 def _graph_is_configured(self): - self._msg_iter = self._input_port.create_message_iterator() + self._msg_iter = self._create_input_port_message_iterator( + self._input_port + ) src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) - with self.assertRaises(bt2.Error): + with self.assertRaises(bt2._Error): self._graph.run() def test_listeners(self): @@ -380,8 +448,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') self._add_output_port('zero') @@ -393,6 +460,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + def _port_connected(self, port, other_port): self._add_input_port('taste') @@ -400,20 +470,26 @@ class GraphTestCase(unittest.TestCase): nonlocal calls calls.append((port_added_listener, component, port)) - def ports_connected_listener(upstream_component, upstream_port, - downstream_component, downstream_port): + def ports_connected_listener( + upstream_component, upstream_port, downstream_component, downstream_port + ): nonlocal calls - calls.append((ports_connected_listener, - upstream_component, upstream_port, - downstream_component, downstream_port)) + calls.append( + ( + ports_connected_listener, + upstream_component, + upstream_port, + downstream_component, + downstream_port, + ) + ) calls = [] self._graph.add_port_added_listener(port_added_listener) self._graph.add_ports_connected_listener(ports_connected_listener) src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(len(calls), 5) @@ -444,8 +520,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') self._add_output_port('zero') @@ -457,6 +532,9 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + def _port_connected(self, port, other_port): self._add_input_port('taste') @@ -473,9 +551,12 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + graph = bt2.Graph() - with self.assertRaises(bt2.Error): + with self.assertRaises(bt2._Error): graph.add_component(MySink, 'comp') def test_raise_in_port_added_listener(self): @@ -486,13 +567,16 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop + def _graph_is_configured(self): + pass + def port_added_listener(component, port): raise ValueError('oh noes!') graph = bt2.Graph() graph.add_port_added_listener(port_added_listener) - with self.assertRaises(bt2.Error): + with self.assertRaises(bt2._Error): graph.add_component(MySink, 'comp') def test_raise_in_ports_connected_listener(self): @@ -500,8 +584,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -512,8 +595,12 @@ class GraphTestCase(unittest.TestCase): def _consume(self): raise bt2.Stop - def ports_connected_listener(upstream_component, upstream_port, - downstream_component, downstream_port): + def _graph_is_configured(self): + pass + + def ports_connected_listener( + upstream_component, upstream_port, downstream_component, downstream_port + ): raise ValueError('oh noes!') graph = bt2.Graph() @@ -521,5 +608,5 @@ class GraphTestCase(unittest.TestCase): up = graph.add_component(MySource, 'down') down = graph.add_component(MySink, 'up') - with self.assertRaises(bt2.Error): + with self.assertRaises(bt2._Error): graph.connect_ports(up.output_ports['out'], down.input_ports['in'])