bt2: Force usage of MapValue object on component init
[babeltrace.git] / tests / bindings / python / bt2 / test_graph.py
index d304169e1b7ab6843ac849b2aeec6de43a16e1c6..8c2a0621f2f0b6bcbed107dface114a2ab5a561b 100644 (file)
@@ -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
 
@@ -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,11 +459,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
 
@@ -473,11 +515,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
 
@@ -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):
This page took 0.026263 seconds and 4 git commands to generate.