X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_error.py;h=f11cb2c2e92cf912d7ca5cd06a76136a06521514;hb=7d30475f16814c503a3f3188de7bc85dd029d887;hp=c1d637778ebfc97aeb7ef81caded89f7dbd69201;hpb=2d83d56c9e5b8f909b2fb7ca79a612159a6f7723;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_error.py b/tests/bindings/python/bt2/test_error.py index c1d63777..f11cb2c2 100644 --- a/tests/bindings/python/bt2/test_error.py +++ b/tests/bindings/python/bt2/test_error.py @@ -29,36 +29,36 @@ class FailingIter(bt2._UserMessageIterator): class SourceWithFailingIter( bt2._UserSourceComponent, message_iterator_class=FailingIter ): - def __init__(self, params): + def __init__(self, config, params, obj): self._add_output_port('out') class SourceWithFailingInit( bt2._UserSourceComponent, message_iterator_class=FailingIter ): - def __init__(self, params): + def __init__(self, config, params, obj): raise ValueError('Source is failing') class WorkingSink(bt2._UserSinkComponent): - def __init__(self, params): + def __init__(self, config, params, obj): self._in = self._add_input_port('in') - def _graph_is_configured(self): + def _user_graph_is_configured(self): self._iter = self._create_input_port_message_iterator(self._in) - def _consume(self): + def _user_consume(self): next(self._iter) class SinkWithExceptionChaining(bt2._UserSinkComponent): - def __init__(self, params): + def __init__(self, config, params, obj): self._in = self._add_input_port('in') - def _graph_is_configured(self): + def _user_graph_is_configured(self): self._iter = self._create_input_port_message_iterator(self._in) - def _consume(self): + def _user_consume(self): try: next(self._iter) except bt2._Error as e: @@ -66,14 +66,11 @@ class SinkWithExceptionChaining(bt2._UserSinkComponent): class SinkWithFailingQuery(bt2._UserSinkComponent): - def _graph_is_configured(self): - pass - - def _consume(self): + def _user_consume(self): pass @staticmethod - def _query(executor, obj, params, log_level): + def _user_query(priv_executor, obj, params, method_obj): raise ValueError('Query is failing') @@ -91,7 +88,7 @@ class ErrorTestCase(unittest.TestCase): def test_current_thread_error_none(self): # When a bt2._Error is raised, it steals the current thread's error. # Verify that it is now NULL. - exc = self._run_failing_graph(SourceWithFailingInit, WorkingSink) + self._run_failing_graph(SourceWithFailingInit, WorkingSink) self.assertIsNone(native_bt.current_thread_take_error()) def test_len(self): @@ -107,7 +104,7 @@ class ErrorTestCase(unittest.TestCase): for c in exc: # Each cause is an instance of _ErrorCause (including subclasses). - self.assertIsInstance(c, bt2.error._ErrorCause) + self.assertIsInstance(c, bt2._ErrorCause) def test_getitem(self): exc = self._run_failing_graph(SourceWithFailingIter, WorkingSink) @@ -115,7 +112,7 @@ class ErrorTestCase(unittest.TestCase): for i in range(len(exc)): c = exc[i] # Each cause is an instance of _ErrorCause (including subclasses). - self.assertIsInstance(c, bt2.error._ErrorCause) + self.assertIsInstance(c, bt2._ErrorCause) def test_getitem_indexerror(self): exc = self._run_failing_graph(SourceWithFailingIter, WorkingSink) @@ -138,24 +135,23 @@ class ErrorTestCase(unittest.TestCase): self.assertEqual(len(exc), 5) - self.assertIsInstance(exc[0], bt2.error._MessageIteratorErrorCause) + self.assertIsInstance(exc[0], bt2._MessageIteratorErrorCause) self.assertEqual(exc[0].component_class_name, 'SourceWithFailingIter') self.assertIn('ValueError: User message iterator is failing', exc[0].message) - self.assertIsInstance(exc[1], bt2.error._ErrorCause) + self.assertIsInstance(exc[1], bt2._ErrorCause) - self.assertIsInstance(exc[2], bt2.error._ComponentErrorCause) + self.assertIsInstance(exc[2], bt2._ComponentErrorCause) self.assertEqual(exc[2].component_class_name, 'SinkWithExceptionChaining') self.assertIn( - 'bt2.error._Error: unexpected error: cannot advance the message iterator', - exc[2].message, + 'unexpected error: cannot advance the message iterator', exc[2].message ) - self.assertIsInstance(exc[3], bt2.error._ComponentErrorCause) + self.assertIsInstance(exc[3], bt2._ComponentErrorCause) self.assertEqual(exc[3].component_class_name, 'SinkWithExceptionChaining') self.assertIn('ValueError: oops', exc[3].message) - self.assertIsInstance(exc[4], bt2.error._ErrorCause) + self.assertIsInstance(exc[4], bt2._ErrorCause) def _common_cause_tests(self, cause): self.assertIsInstance(cause.module_name, str) @@ -165,13 +161,13 @@ class ErrorTestCase(unittest.TestCase): def test_unknown_error_cause(self): exc = self._run_failing_graph(SourceWithFailingIter, SinkWithExceptionChaining) cause = exc[-1] - self.assertIs(type(cause), bt2.error._ErrorCause) + self.assertIs(type(cause), bt2._ErrorCause) self._common_cause_tests(cause) def test_component_error_cause(self): exc = self._run_failing_graph(SourceWithFailingInit, SinkWithExceptionChaining) cause = exc[0] - self.assertIs(type(cause), bt2.error._ComponentErrorCause) + self.assertIs(type(cause), bt2._ComponentErrorCause) self._common_cause_tests(cause) self.assertIn('Source is failing', cause.message) @@ -181,13 +177,13 @@ class ErrorTestCase(unittest.TestCase): self.assertIsNone(cause.plugin_name) def test_component_class_error_cause(self): - q = bt2.QueryExecutor() + q = bt2.QueryExecutor(SinkWithFailingQuery, 'hello') with self.assertRaises(bt2._Error) as ctx: - q.query(SinkWithFailingQuery, 'hello') + q.query() cause = ctx.exception[0] - self.assertIs(type(cause), bt2.error._ComponentClassErrorCause) + self.assertIs(type(cause), bt2._ComponentClassErrorCause) self._common_cause_tests(cause) self.assertIn('Query is failing', cause.message) @@ -199,7 +195,7 @@ class ErrorTestCase(unittest.TestCase): def test_message_iterator_error_cause(self): exc = self._run_failing_graph(SourceWithFailingIter, SinkWithExceptionChaining) cause = exc[0] - self.assertIs(type(cause), bt2.error._MessageIteratorErrorCause) + self.assertIs(type(cause), bt2._MessageIteratorErrorCause) self._common_cause_tests(cause) self.assertIn('User message iterator is failing', cause.message) @@ -208,3 +204,16 @@ class ErrorTestCase(unittest.TestCase): self.assertEqual(cause.component_class_type, bt2.ComponentClassType.SOURCE) self.assertEqual(cause.component_class_name, 'SourceWithFailingIter') self.assertIsNone(cause.plugin_name) + + def test_str(self): + # Test __str__. We don't need to test the precise format used, but + # just that it doesn't miserably crash and that it contains some + # expected bits. + exc = self._run_failing_graph(SourceWithFailingIter, SinkWithExceptionChaining) + s = str(exc) + self.assertIn("[src (out): 'source.SourceWithFailingIter']", s) + self.assertIn('ValueError: oops', s) + + +if __name__ == '__main__': + unittest.main()