bt2: pass custom Python object to Python component's __init__()
[babeltrace.git] / tests / bindings / python / bt2 / test_message_iterator.py
index f780cf2c75a9a3052c00c92903253d717fabff37..43af1e1f4d8457807f70f5bb10c7615499c3a6f5 100644 (file)
@@ -27,13 +27,13 @@ class UserMessageIteratorTestCase(unittest.TestCase):
     @staticmethod
     def _create_graph(src_comp_cls, flt_comp_cls=None):
         class MySink(bt2._UserSinkComponent):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_input_port('in')
 
-            def _consume(self):
+            def _user_consume(self):
                 next(self._msg_iter)
 
-            def _graph_is_configured(self):
+            def _user_graph_is_configured(self):
                 self._msg_iter = self._create_input_port_message_iterator(
                     self._input_ports['in']
                 )
@@ -70,7 +70,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 the_output_port_from_iter = self_port_output
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 nonlocal the_output_port_from_source
                 the_output_port_from_source = self._add_output_port('out', 'user data')
 
@@ -90,7 +90,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 src_iter_initialized = True
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
 
         class MyFilterIter(bt2._UserMessageIterator):
@@ -105,7 +105,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 return next(self._up_iter)
 
         class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyFilterIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_input_port('in')
                 self._add_output_port('out')
 
@@ -118,12 +118,12 @@ class UserMessageIteratorTestCase(unittest.TestCase):
 
     def test_finalize(self):
         class MyIter(bt2._UserMessageIterator):
-            def _finalize(self):
+            def _user_finalize(self):
                 nonlocal finalized
                 finalized = True
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
 
         finalized = False
@@ -139,7 +139,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 salut = self._component._salut
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
                 self._salut = 23
 
@@ -155,7 +155,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 addr = self.addr
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
 
         addr = None
@@ -188,7 +188,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 return self._msgs.pop(0)
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 tc = self._create_trace_class()
                 sc = tc.create_stream_class(supports_packets=True)
                 ec = sc.create_event_class()
@@ -200,15 +200,15 @@ class UserMessageIteratorTestCase(unittest.TestCase):
 
         # Skip beginning messages.
         msg = next(it)
-        self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
+        self.assertIsInstance(msg, bt2._StreamBeginningMessage)
         msg = next(it)
-        self.assertIsInstance(msg, bt2.message._PacketBeginningMessage)
+        self.assertIsInstance(msg, bt2._PacketBeginningMessage)
 
         msg_ev1 = next(it)
         msg_ev2 = next(it)
 
-        self.assertIsInstance(msg_ev1, bt2.message._EventMessage)
-        self.assertIsInstance(msg_ev2, bt2.message._EventMessage)
+        self.assertIsInstance(msg_ev1, bt2._EventMessage)
+        self.assertIsInstance(msg_ev2, bt2._EventMessage)
         self.assertEqual(msg_ev1.addr, msg_ev2.addr)
 
     @staticmethod
@@ -235,7 +235,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 ]
                 self._at = 0
 
-            def _seek_beginning(self):
+            def _user_seek_beginning(self):
                 self._at = 0
 
             def __next__(self):
@@ -247,7 +247,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                     raise StopIteration
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 tc = self._create_trace_class()
                 sc = tc.create_stream_class(supports_packets=True)
                 ec = sc.create_event_class()
@@ -264,15 +264,15 @@ class UserMessageIteratorTestCase(unittest.TestCase):
             def __next__(self):
                 return next(self._upstream_iter)
 
-            def _seek_beginning(self):
+            def _user_seek_beginning(self):
                 self._upstream_iter.seek_beginning()
 
             @property
-            def _can_seek_beginning(self):
+            def _user_can_seek_beginning(self):
                 return self._upstream_iter.can_seek_beginning
 
         class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyFilterIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 input_port = self._add_input_port('in')
                 self._add_output_port('out', input_port)
 
@@ -287,11 +287,11 @@ class UserMessageIteratorTestCase(unittest.TestCase):
     def test_can_seek_beginning(self):
         it, MySourceIter = self._setup_seek_beginning_test()
 
-        def _can_seek_beginning(self):
+        def _user_can_seek_beginning(self):
             nonlocal can_seek_beginning
             return can_seek_beginning
 
-        MySourceIter._can_seek_beginning = property(_can_seek_beginning)
+        MySourceIter._user_can_seek_beginning = property(_user_can_seek_beginning)
 
         can_seek_beginning = True
         self.assertTrue(it.can_seek_beginning)
@@ -305,24 +305,24 @@ class UserMessageIteratorTestCase(unittest.TestCase):
         # Remove the _can_seek_beginning method, we now rely on the presence of
         # a _seek_beginning method to know whether the iterator can seek to
         # beginning or not.
-        del MySourceIter._can_seek_beginning
+        del MySourceIter._user_can_seek_beginning
         self.assertTrue(it.can_seek_beginning)
 
-        del MySourceIter._seek_beginning
+        del MySourceIter._user_seek_beginning
         self.assertFalse(it.can_seek_beginning)
 
     def test_seek_beginning(self):
         it, MySourceIter = self._setup_seek_beginning_test()
 
         msg = next(it)
-        self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
+        self.assertIsInstance(msg, bt2._StreamBeginningMessage)
         msg = next(it)
-        self.assertIsInstance(msg, bt2.message._PacketBeginningMessage)
+        self.assertIsInstance(msg, bt2._PacketBeginningMessage)
 
         it.seek_beginning()
 
         msg = next(it)
-        self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
+        self.assertIsInstance(msg, bt2._StreamBeginningMessage)
 
         # Verify that we can seek beginning after having reached the end.
         #
@@ -338,15 +338,15 @@ class UserMessageIteratorTestCase(unittest.TestCase):
         #
         # it.seek_beginning()
         # msg = next(it)
-        # self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
+        # self.assertIsInstance(msg, bt2._StreamBeginningMessage)
 
     def test_seek_beginning_user_error(self):
         it, MySourceIter = self._setup_seek_beginning_test()
 
-        def _seek_beginning_error(self):
+        def _user_seek_beginning_error(self):
             raise ValueError('ouch')
 
-        MySourceIter._seek_beginning = _seek_beginning_error
+        MySourceIter._user_seek_beginning = _user_seek_beginning_error
 
         with self.assertRaises(bt2._Error):
             it.seek_beginning()
@@ -360,7 +360,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 raise bt2.TryAgain
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
 
         graph = bt2.Graph()
@@ -403,7 +403,7 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase):
                 return msg
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
-            def __init__(self, params):
+            def __init__(self, params, obj):
                 self._add_output_port('out')
 
                 trace_class = self._create_trace_class()
@@ -433,15 +433,15 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase):
 
         for at, msg in enumerate(msg_iter):
             if at == 0:
-                self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
+                self.assertIsInstance(msg, bt2._StreamBeginningMessage)
             elif at == 1:
-                self.assertIsInstance(msg, bt2.message._PacketBeginningMessage)
+                self.assertIsInstance(msg, bt2._PacketBeginningMessage)
             elif at == 5:
-                self.assertIsInstance(msg, bt2.message._PacketEndMessage)
+                self.assertIsInstance(msg, bt2._PacketEndMessage)
             elif at == 6:
-                self.assertIsInstance(msg, bt2.message._StreamEndMessage)
+                self.assertIsInstance(msg, bt2._StreamEndMessage)
             else:
-                self.assertIsInstance(msg, bt2.message._EventMessage)
+                self.assertIsInstance(msg, bt2._EventMessage)
                 self.assertEqual(msg.event.cls.name, 'salut')
                 field = msg.event.payload_field['my_int']
                 self.assertEqual(field, at * 3)
This page took 0.028215 seconds and 4 git commands to generate.