X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_graph.py;h=8c2a0621f2f0b6bcbed107dface114a2ab5a561b;hb=3e03e5e334d6a995f4fc63f52b6d6745688f640f;hp=1d3f9da27be726606de2f635ebc2056faa0ba8a2;hpb=36153ada10de62a443f2de95aba56ff48ba0f6dc;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 1d3f9da2..8c2a0621 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -21,7 +21,7 @@ import bt2 class _MyIter(bt2._UserMessageIterator): - def __init__(self, self_output_port): + def __init__(self, config, self_output_port): self._build_meta() self._at = 0 @@ -87,7 +87,7 @@ class GraphTestCase(unittest.TestCase): comp_params = None class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): nonlocal comp_params comp_params = params @@ -103,7 +103,7 @@ class GraphTestCase(unittest.TestCase): comp_obj = None class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): nonlocal comp_obj comp_obj = obj @@ -119,7 +119,7 @@ class GraphTestCase(unittest.TestCase): comp_obj = None class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): nonlocal comp_obj comp_obj = obj @@ -159,6 +159,48 @@ class GraphTestCase(unittest.TestCase): with self.assertRaises(ValueError): self._graph.add_component(MySink, 'salut', logging_level=12345) + def test_add_component_invalid_params_type(self): + class MySink(bt2._UserSinkComponent): + def _user_consume(self): + pass + + with self.assertRaises(TypeError): + self._graph.add_component(MySink, 'salut', params=12) + + def test_add_component_params_dict(self): + params_obj = None + + class MySink(bt2._UserSinkComponent): + def __init__(self, config, params, obj): + nonlocal params_obj + params_obj = params + + def _user_consume(self): + pass + + params = {'plage': 12312} + self._graph.add_component(MySink, 'salut', params=params) + + # Check equality and not identity because `add_component()` method + # converts the Python `dict` to a `bt2.MapValue`. + self.assertEqual(params, params_obj) + + def test_add_component_params_mapvalue(self): + params_obj = None + + class MySink(bt2._UserSinkComponent): + def __init__(self, config, params, obj): + nonlocal params_obj + params_obj = params + + def _user_consume(self): + pass + + params = bt2.MapValue({'beachclub': '121'}) + self._graph.add_component(MySink, 'salut', params=params) + + self.assertEqual(params, params_obj) + def test_add_component_logging_level(self): class MySink(bt2._UserSinkComponent): def _user_consume(self): @@ -175,11 +217,11 @@ class GraphTestCase(unittest.TestCase): raise bt2.Stop class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -202,11 +244,11 @@ class GraphTestCase(unittest.TestCase): raise bt2.Stop class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -224,11 +266,11 @@ class GraphTestCase(unittest.TestCase): raise TypeError class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -269,11 +311,11 @@ class GraphTestCase(unittest.TestCase): return self._create_stream_beginning_message(self._stream) class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -316,11 +358,11 @@ class GraphTestCase(unittest.TestCase): return msg class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._input_port = self._add_input_port('in') self._at = 0 @@ -328,16 +370,16 @@ class GraphTestCase(unittest.TestCase): msg = next(comp_self._msg_iter) if comp_self._at == 0: - self.assertIsInstance(msg, bt2._StreamBeginningMessage) + self.assertIs(type(msg), bt2._StreamBeginningMessageConst) elif comp_self._at == 1: - self.assertIsInstance(msg, bt2._PacketBeginningMessage) + self.assertIs(type(msg), bt2._PacketBeginningMessageConst) elif comp_self._at >= 2 and comp_self._at <= 6: - self.assertIsInstance(msg, bt2._EventMessage) + self.assertIs(type(msg), bt2._EventMessageConst) self.assertEqual(msg.event.cls.name, 'salut') elif comp_self._at == 7: - self.assertIsInstance(msg, bt2._PacketEndMessage) + self.assertIs(type(msg), bt2._PacketEndMessageConst) elif comp_self._at == 8: - self.assertIsInstance(msg, bt2._StreamEndMessage) + self.assertIs(type(msg), bt2._StreamEndMessageConst) comp_self._at += 1 @@ -356,11 +398,11 @@ class GraphTestCase(unittest.TestCase): pass class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._input_port = self._add_input_port('in') def _user_consume(comp_self): @@ -383,11 +425,11 @@ class GraphTestCase(unittest.TestCase): pass class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._input_port = self._add_input_port('in') def _user_consume(comp_self): @@ -417,22 +459,22 @@ class GraphTestCase(unittest.TestCase): return msg class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._input_port = self._add_input_port('in') self._at = 0 def _user_consume(comp_self): msg = next(comp_self._msg_iter) if comp_self._at == 0: - self.assertIsInstance(msg, bt2._StreamBeginningMessage) + self.assertIs(type(msg), bt2._StreamBeginningMessageConst) elif comp_self._at == 1: - self.assertIsInstance(msg, bt2._PacketBeginningMessage) + self.assertIs(type(msg), bt2._PacketBeginningMessageConst) elif comp_self._at == 2: - self.assertIsInstance(msg, bt2._EventMessage) + self.assertIs(type(msg), bt2._EventMessageConst) raise bt2.TryAgain else: pass @@ -473,22 +515,22 @@ class GraphTestCase(unittest.TestCase): return msg class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._input_port = self._add_input_port('in') self._at = 0 def _user_consume(comp_self): msg = next(comp_self._msg_iter) if comp_self._at == 0: - self.assertIsInstance(msg, bt2._StreamBeginningMessage) + self.assertIs(type(msg), bt2._StreamBeginningMessageConst) elif comp_self._at == 1: - self.assertIsInstance(msg, bt2._PacketBeginningMessage) + self.assertIs(type(msg), bt2._PacketBeginningMessageConst) elif comp_self._at == 2: - self.assertIsInstance(msg, bt2._EventMessage) + self.assertIs(type(msg), bt2._EventMessageConst) elif comp_self._at == 3: nonlocal raised_in_sink raised_in_sink = True @@ -514,12 +556,12 @@ class GraphTestCase(unittest.TestCase): raise bt2.Stop class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') self._add_output_port('zero') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -583,12 +625,12 @@ class GraphTestCase(unittest.TestCase): raise bt2.Stop class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') self._add_output_port('zero') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -604,7 +646,7 @@ class GraphTestCase(unittest.TestCase): def test_raise_in_component_init(self): class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): raise ValueError('oops!') def _user_consume(self): @@ -617,7 +659,7 @@ class GraphTestCase(unittest.TestCase): def test_raise_in_port_added_listener(self): class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -638,11 +680,11 @@ class GraphTestCase(unittest.TestCase): raise bt2.Stop class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_input_port('in') def _user_consume(self): @@ -660,3 +702,7 @@ class GraphTestCase(unittest.TestCase): with self.assertRaises(bt2._Error): graph.connect_ports(up.output_ports['out'], down.input_ports['in']) + + +if __name__ == '__main__': + unittest.main()