lib: make can_seek_beginning and can_seek_ns_from_origin methods return a status
[babeltrace.git] / tests / bindings / python / bt2 / test_message_iterator.py
index 2d4ab43850774131ffa9982355639079aa3f518b..01d4eca3c5b9d0d4d768dd6304554b6b2b01512d 100644 (file)
@@ -457,6 +457,60 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase):
         graph.run_once()
         self.assertFalse(can_seek_beginning)
 
+    def test_can_seek_beginning_user_error(self):
+        class MySink(bt2._UserSinkComponent):
+            def __init__(self, params, obj):
+                self._add_input_port('in')
+
+            def _user_graph_is_configured(self):
+                self._msg_iter = self._create_input_port_message_iterator(
+                    self._input_ports['in']
+                )
+
+            def _user_consume(self):
+                # This is expected to raise.
+                self._msg_iter.can_seek_beginning
+
+        def _user_can_seek_beginning(self):
+            raise ValueError('moustiquaire')
+
+        graph = _setup_seek_test(
+            MySink, user_can_seek_beginning=_user_can_seek_beginning
+        )
+
+        with self.assertRaises(bt2._Error) as ctx:
+            graph.run_once()
+
+        cause = ctx.exception[0]
+        self.assertIn('ValueError: moustiquaire', cause.message)
+
+    def test_can_seek_beginning_wrong_return_value(self):
+        class MySink(bt2._UserSinkComponent):
+            def __init__(self, params, obj):
+                self._add_input_port('in')
+
+            def _user_graph_is_configured(self):
+                self._msg_iter = self._create_input_port_message_iterator(
+                    self._input_ports['in']
+                )
+
+            def _user_consume(self):
+                # This is expected to raise.
+                self._msg_iter.can_seek_beginning
+
+        def _user_can_seek_beginning(self):
+            return 'Amqui'
+
+        graph = _setup_seek_test(
+            MySink, user_can_seek_beginning=_user_can_seek_beginning
+        )
+
+        with self.assertRaises(bt2._Error) as ctx:
+            graph.run_once()
+
+        cause = ctx.exception[0]
+        self.assertIn("TypeError: 'str' is not a 'bool' object", cause.message)
+
     def test_seek_beginning(self):
         class MySink(bt2._UserSinkComponent):
             def __init__(self, params, obj):
This page took 0.024556 seconds and 4 git commands to generate.