From 6a91742b3a25285222551341c8a134b4b2b5aba9 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 Jul 2019 17:27:22 -0400 Subject: [PATCH] bt2: prepend `_user` to overridable protected methods It is possible that, in the future, we add new, optional overridable protected methods that the user can implement within a component class or message iterator class to have new features. There is the risk, however, that the user class already has a method named as such. This would be considered a backward compatibility break because the same user class with two different versions of Babeltrace 2 would not work the same way (and with the newest version, it probably would not work at all). To prevent this, this patch adds the `_user` namespace to all the overridable protected methods. It will be documented that you cannot, when you inherit one of the `bt2._User*` classes, have a method named `_user_*()`, as this prefix is reserved for the future within the `bt2` package. Signed-off-by: Philippe Proulx Change-Id: I0c5ac29a21a83d6f644d0bb696f71d687ecfebae Reviewed-on: https://review.lttng.org/c/babeltrace/+/1777 Tested-by: jenkins --- src/bindings/python/bt2/bt2/component.py | 18 +-- .../python/bt2/bt2/message_iterator.py | 14 +-- .../bt2/bt2/native_bt_component_class.i | 28 ++--- tests/bindings/python/bt2/test_component.py | 47 ++------ .../python/bt2/test_component_class.py | 111 +++++------------- tests/bindings/python/bt2/test_connection.py | 15 +-- tests/bindings/python/bt2/test_error.py | 15 +-- tests/bindings/python/bt2/test_graph.py | 89 ++++---------- .../python/bt2/test_message_iterator.py | 24 ++-- tests/bindings/python/bt2/test_port.py | 75 +++--------- .../python/bt2/test_query_executor.py | 70 ++++------- tests/bindings/python/bt2/utils.py | 5 +- .../auto-source-discovery/bt_plugin_test.py | 6 +- .../bt_plugin_trimmer_test.py | 2 +- .../bt_plugin_test_python_plugin_provider.py | 5 +- 15 files changed, 154 insertions(+), 370 deletions(-) diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index d26adc8f..05ebe761 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -484,9 +484,9 @@ class _UserComponentType(type): cls, comp_cls_name, comp_cls_descr, comp_cls_help ) elif _UserSinkComponent in bases: - if not hasattr(cls, '_consume'): + if not hasattr(cls, '_user_consume'): raise bt2._IncompleteUserClass( - "cannot create component class '{}': missing a _consume() method".format( + "cannot create component class '{}': missing a _user_consume() method".format( class_name ) ) @@ -586,7 +586,7 @@ class _UserComponentType(type): ) # this can raise, but the native side checks the exception - results = cls._query(query_exec, obj, params, log_level) + results = cls._user_query(query_exec, obj, params, log_level) # this can raise, but the native side checks the exception results = bt2.create_value(results) @@ -602,7 +602,7 @@ class _UserComponentType(type): return int(results_ptr) - def _query(cls, query_executor, obj, params, log_level): + def _user_query(cls, query_executor, obj, params, log_level): raise NotImplementedError def _bt_component_class_ptr(self): @@ -656,10 +656,10 @@ class _UserComponent(metaclass=_UserComponentType): def __init__(self, params=None): pass - def _finalize(self): + def _user_finalize(self): pass - def _port_connected(self, port, other_port): + def _user_port_connected(self, port, other_port): pass def _bt_port_connected_from_native( @@ -675,7 +675,7 @@ class _UserComponent(metaclass=_UserComponentType): other_port = bt2_port._create_from_ptr_and_get_ref( other_port_ptr, other_port_type ) - self._port_connected(port, other_port) + self._user_port_connected(port, other_port) def _create_trace_class(self, assigns_automatic_stream_class_id=True): ptr = self._bt_as_self_component_ptr(self._bt_ptr) @@ -829,9 +829,9 @@ class _UserSinkComponent(_UserComponent, _SinkComponent): ) def _bt_graph_is_configured_from_native(self): - self._graph_is_configured() + self._user_graph_is_configured() - def _graph_is_configured(self): + def _user_graph_is_configured(self): pass @property diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index 8936c0db..c6c23dfd 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -146,7 +146,7 @@ class _UserMessageIterator(_MessageIterator): def _is_interrupted(self): return bool(native_bt.self_message_iterator_is_interrupted(self._bt_ptr)) - def _finalize(self): + def _user_finalize(self): pass def __next__(self): @@ -173,19 +173,19 @@ class _UserMessageIterator(_MessageIterator): def _bt_can_seek_beginning_from_native(self): # Here, we mimic the behavior of the C API: # - # - If the iterator has a _can_seek_beginning attribute, read it and use - # that result. + # - If the iterator has a _user_can_seek_beginning attribute, + # read it and use that result. # - Otherwise, the presence or absence of a `_seek_beginning` # method indicates whether the iterator can seek beginning. - if hasattr(self, '_can_seek_beginning'): - can_seek_beginning = self._can_seek_beginning + if hasattr(self, '_user_can_seek_beginning'): + can_seek_beginning = self._user_can_seek_beginning utils._check_bool(can_seek_beginning) return can_seek_beginning else: - return hasattr(self, '_seek_beginning') + return hasattr(self, '_user_seek_beginning') def _bt_seek_beginning_from_native(self): - self._seek_beginning() + self._user_seek_beginning() def _create_input_port_message_iterator(self, input_port): utils._check_type(input_port, bt2_port._UserComponentInputPort) diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i b/src/bindings/python/bt2/bt2/native_bt_component_class.i index bba59883..e71e6bf8 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i @@ -573,19 +573,19 @@ void component_class_finalize(bt_self_component *self_component) PyObject *py_comp = bt_self_component_get_data(self_component); BT_ASSERT(py_comp); - /* Call user's _finalize() method */ + /* Call user's _user_finalize() method */ PyObject *py_method_result = PyObject_CallMethod(py_comp, - "_finalize", NULL); + "_user_finalize", NULL); if (PyErr_Occurred()) { - BT_LOGW("User component's _finalize() method raised an exception: ignoring:"); + BT_LOGW("User component's _user_finalize() method raised an exception: ignoring:"); logw_exception(); } /* - * Ignore any exception raised by the _finalize() method because - * it won't change anything at this point: the component is - * being destroyed anyway. + * Ignore any exception raised by the _user_finalize() method + * because it won't change anything at this point: the component + * is being destroyed anyway. */ PyErr_Clear(); Py_XDECREF(py_method_result); @@ -1084,19 +1084,19 @@ void component_class_message_iterator_finalize( BT_ASSERT(py_message_iter); - /* Call user's _finalize() method */ + /* Call user's _user_finalize() method */ py_method_result = PyObject_CallMethod(py_message_iter, - "_finalize", NULL); + "_user_finalize", NULL); if (PyErr_Occurred()) { - BT_LOGW("User's _finalize() method raised an exception: ignoring:"); + BT_LOGW("User's _user_finalize() method raised an exception: ignoring:"); logw_exception(); } /* - * Ignore any exception raised by the _finalize() method because - * it won't change anything at this point: the component is - * being destroyed anyway. + * Ignore any exception raised by the _user_finalize() method + * because it won't change anything at this point: the component + * is being destroyed anyway. */ PyErr_Clear(); Py_XDECREF(py_method_result); @@ -1153,11 +1153,11 @@ component_class_sink_consume(bt_self_component_sink *self_component_sink) BT_ASSERT(py_comp); py_method_result = PyObject_CallMethod(py_comp, - "_consume", NULL); + "_user_consume", NULL); status = py_exc_to_status_component(self_component); if (!py_method_result && status == __BT_FUNC_STATUS_OK) { /* Pretty sure this should never happen, but just in case */ - BT_LOGE("User's _consume() method failed without raising an exception: " + BT_LOGE("User's _user_consume() method failed without raising an exception: " "status=%d", status); status = __BT_FUNC_STATUS_ERROR; } diff --git a/tests/bindings/python/bt2/test_component.py b/tests/bindings/python/bt2/test_component.py index 69e5617b..b61749ec 100644 --- a/tests/bindings/python/bt2/test_component.py +++ b/tests/bindings/python/bt2/test_component.py @@ -37,10 +37,7 @@ class UserComponentTestCase(unittest.TestCase): def __init__(comp_self, params): self.assertEqual(comp_self.name, 'yaes') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink, 'yaes') @@ -50,10 +47,7 @@ class UserComponentTestCase(unittest.TestCase): def __init__(comp_self, params): self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) @@ -63,10 +57,7 @@ class UserComponentTestCase(unittest.TestCase): def __init__(comp_self, params): self.assertEqual(comp_self.cls, MySink) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -77,10 +68,7 @@ class UserComponentTestCase(unittest.TestCase): self.assertIsInstance(comp_self.addr, int) self.assertNotEqual(comp_self.addr, 0) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -89,13 +77,10 @@ class UserComponentTestCase(unittest.TestCase): finalized = False class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass - def _finalize(comp_self): + def _user_finalize(comp_self): nonlocal finalized finalized = True @@ -119,10 +104,7 @@ class GenericComponentTestCase(unittest.TestCase): def test_name(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink, 'yaes') @@ -130,10 +112,7 @@ class GenericComponentTestCase(unittest.TestCase): def test_logging_level(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING) @@ -141,10 +120,7 @@ class GenericComponentTestCase(unittest.TestCase): def test_class(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -152,10 +128,7 @@ class GenericComponentTestCase(unittest.TestCase): def test_addr(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) diff --git a/tests/bindings/python/bt2/test_component_class.py b/tests/bindings/python/bt2/test_component_class.py index 909b2d64..fd36d240 100644 --- a/tests/bindings/python/bt2/test_component_class.py +++ b/tests/bindings/python/bt2/test_component_class.py @@ -48,10 +48,7 @@ class UserComponentClassTestCase(unittest.TestCase): def test_no_init_sink(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._test_no_init(MySink) @@ -108,28 +105,19 @@ class UserComponentClassTestCase(unittest.TestCase): def test_minimal_sink(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass def test_default_name(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertEqual(MySink.name, 'MySink') def test_custom_name(self): class MySink(bt2._UserSinkComponent, name='salut'): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertEqual(MySink.name, 'salut') @@ -138,10 +126,7 @@ class UserComponentClassTestCase(unittest.TestCase): with self.assertRaises(TypeError): class MySink(bt2._UserSinkComponent, name=23): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass def test_description(self): @@ -156,10 +141,7 @@ class UserComponentClassTestCase(unittest.TestCase): cupim flank tenderloin. """ - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertEqual(MySink.description, 'The description.') @@ -169,10 +151,7 @@ class UserComponentClassTestCase(unittest.TestCase): """ """ - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertIsNone(MySink.description) @@ -187,20 +166,14 @@ class UserComponentClassTestCase(unittest.TestCase): here. """ - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertEqual(MySink.help, 'The help\ntext is\nhere.') def test_addr(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertIsInstance(MySink.addr, int) @@ -208,10 +181,7 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_not_implemented(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass with self.assertRaises(bt2._Error): @@ -219,14 +189,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_raises(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): raise ValueError with self.assertRaises(bt2._Error): @@ -234,14 +201,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_wrong_return_type(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): return ... with self.assertRaises(bt2._Error): @@ -249,14 +213,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_params_none(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params return None @@ -270,14 +231,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_logging_level(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_log_level query_log_level = log_level @@ -288,14 +246,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_returns_none(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @staticmethod - def _query(query_exec, obj, params, log_level): + def _user_query(query_exec, obj, params, log_level): return res = bt2.QueryExecutor().query(MySink, 'obj', None) @@ -303,14 +258,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_simple(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params return 17.5 @@ -324,14 +276,11 @@ class UserComponentClassTestCase(unittest.TestCase): def test_query_complex(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params return {'null': None, 'bt2': 'BT2'} @@ -350,10 +299,7 @@ class UserComponentClassTestCase(unittest.TestCase): def test_eq(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self.assertEqual(MySink, MySink) @@ -368,14 +314,11 @@ class ComponentClassTestCase(unittest.TestCase): The help. ''' - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): return [obj, params, 23] self._py_comp_cls = MySink diff --git a/tests/bindings/python/bt2/test_connection.py b/tests/bindings/python/bt2/test_connection.py index fc5c546e..898c6871 100644 --- a/tests/bindings/python/bt2/test_connection.py +++ b/tests/bindings/python/bt2/test_connection.py @@ -34,12 +34,9 @@ class ConnectionTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') @@ -58,12 +55,9 @@ class ConnectionTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') @@ -83,12 +77,9 @@ class ConnectionTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') diff --git a/tests/bindings/python/bt2/test_error.py b/tests/bindings/python/bt2/test_error.py index 9ae8b36c..ca750aea 100644 --- a/tests/bindings/python/bt2/test_error.py +++ b/tests/bindings/python/bt2/test_error.py @@ -44,10 +44,10 @@ class WorkingSink(bt2._UserSinkComponent): def __init__(self, params): 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) @@ -55,10 +55,10 @@ class SinkWithExceptionChaining(bt2._UserSinkComponent): def __init__(self, params): 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(executor, obj, params, log_level): raise ValueError('Query is failing') diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 453a62ed..bda08de2 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -59,10 +59,7 @@ class GraphTestCase(unittest.TestCase): def test_add_component_user_cls(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._graph.add_component(MySink, 'salut') @@ -70,10 +67,7 @@ class GraphTestCase(unittest.TestCase): def test_add_component_gen_cls(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._graph.add_component(MySink, 'salut') @@ -89,10 +83,7 @@ class GraphTestCase(unittest.TestCase): nonlocal comp_params comp_params = params - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass params = {'hello': 23, 'path': '/path/to/stuff'} @@ -106,10 +97,7 @@ class GraphTestCase(unittest.TestCase): def test_add_component_invalid_logging_level_type(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass with self.assertRaises(TypeError): @@ -117,10 +105,7 @@ class GraphTestCase(unittest.TestCase): def test_add_component_invalid_logging_level_value(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass with self.assertRaises(ValueError): @@ -128,10 +113,7 @@ class GraphTestCase(unittest.TestCase): def test_add_component_logging_level(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._graph.add_component( @@ -152,12 +134,9 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') @@ -182,12 +161,9 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') @@ -209,10 +185,10 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): 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'] ) @@ -254,13 +230,13 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): # Pretend that somebody asynchronously interrupted the graph. nonlocal graph graph.interrupt() return 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'] ) @@ -302,7 +278,7 @@ class GraphTestCase(unittest.TestCase): self._input_port = self._add_input_port('in') self._at = 0 - def _consume(comp_self): + def _user_consume(comp_self): msg = next(comp_self._msg_iter) if comp_self._at == 0: @@ -319,7 +295,7 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 - def _graph_is_configured(self): + def _user_graph_is_configured(self): self._msg_iter = self._create_input_port_message_iterator( self._input_port ) @@ -356,7 +332,7 @@ class GraphTestCase(unittest.TestCase): self._input_port = self._add_input_port('in') self._at = 0 - def _consume(comp_self): + def _user_consume(comp_self): msg = next(comp_self._msg_iter) if comp_self._at == 0: self.assertIsInstance(msg, bt2._StreamBeginningMessage) @@ -370,7 +346,7 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 - def _graph_is_configured(self): + def _user_graph_is_configured(self): self._msg_iter = self._create_input_port_message_iterator( self._input_port ) @@ -414,7 +390,7 @@ class GraphTestCase(unittest.TestCase): self._input_port = self._add_input_port('in') self._at = 0 - def _consume(comp_self): + def _user_consume(comp_self): msg = next(comp_self._msg_iter) if comp_self._at == 0: self.assertIsInstance(msg, bt2._StreamBeginningMessage) @@ -429,7 +405,7 @@ class GraphTestCase(unittest.TestCase): comp_self._at += 1 - def _graph_is_configured(self): + def _user_graph_is_configured(self): self._msg_iter = self._create_input_port_message_iterator( self._input_port ) @@ -457,13 +433,10 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - - def _port_connected(self, port, other_port): + def _user_port_connected(self, port, other_port): self._add_input_port('taste') def port_added_listener(component, port): @@ -529,13 +502,10 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - - def _port_connected(self, port, other_port): + def _user_port_connected(self, port, other_port): self._add_input_port('taste') with self.assertRaises(TypeError): @@ -548,12 +518,9 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): raise ValueError('oops!') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() with self.assertRaises(bt2._Error): @@ -564,12 +531,9 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - def port_added_listener(component, port): raise ValueError('oh noes!') @@ -592,12 +556,9 @@ class GraphTestCase(unittest.TestCase): def __init__(self, params): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - def ports_connected_listener( upstream_component, upstream_port, downstream_component, downstream_port ): diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index c8d2cf16..08be7d00 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -30,10 +30,10 @@ class UserMessageIteratorTestCase(unittest.TestCase): def __init__(self, params): 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'] ) @@ -118,7 +118,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): def test_finalize(self): class MyIter(bt2._UserMessageIterator): - def _finalize(self): + def _user_finalize(self): nonlocal finalized finalized = True @@ -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): @@ -264,11 +264,11 @@ 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): @@ -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,10 +305,10 @@ 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): @@ -343,10 +343,10 @@ class UserMessageIteratorTestCase(unittest.TestCase): 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() diff --git a/tests/bindings/python/bt2/test_port.py b/tests/bindings/python/bt2/test_port.py index 35d8797e..8be3f38c 100644 --- a/tests/bindings/python/bt2/test_port.py +++ b/tests/bindings/python/bt2/test_port.py @@ -75,10 +75,7 @@ class PortTestCase(unittest.TestCase): port = comp_self._add_input_port('in') self.assertEqual(port.name, 'in') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -142,10 +139,7 @@ class PortTestCase(unittest.TestCase): self.assertEqual(port2.addr, comp_self._input_ports['print'].addr) self.assertEqual(port1.addr, comp_self._input_ports['clear'].addr) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -208,10 +202,7 @@ class PortTestCase(unittest.TestCase): with self.assertRaises(KeyError): comp_self._input_ports['hello'] - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -266,10 +257,7 @@ class PortTestCase(unittest.TestCase): comp_self._add_input_port('insert') self.assertEqual(len(comp_self._input_ports), 3) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -364,10 +352,7 @@ class PortTestCase(unittest.TestCase): self.assertEqual(ports[2][0], 'insert') self.assertEqual(ports[2][1].addr, port3.addr) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -456,10 +441,7 @@ class PortTestCase(unittest.TestCase): port2 = comp_self._add_input_port('print') port3 = comp_self._add_input_port('insert') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -528,10 +510,7 @@ class PortTestCase(unittest.TestCase): with self.assertRaises(KeyError): comp_self._input_ports['hello'] - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -588,10 +567,7 @@ class PortTestCase(unittest.TestCase): comp_self._add_input_port('print') comp_self._add_input_port('insert') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -705,10 +681,7 @@ class PortTestCase(unittest.TestCase): port2 = comp_self._add_input_port('print') port3 = comp_self._add_input_port('insert') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -732,10 +705,7 @@ class PortTestCase(unittest.TestCase): def __init__(comp_self, params): comp_self._add_input_port('clear') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -746,10 +716,7 @@ class PortTestCase(unittest.TestCase): def __init__(comp_self, params): comp_self._add_input_port('clear') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -760,10 +727,7 @@ class PortTestCase(unittest.TestCase): def __init__(comp_self, params): comp_self._add_input_port('clear') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -775,10 +739,7 @@ class PortTestCase(unittest.TestCase): port = comp_self._add_input_port('clear') self.assertEqual(port.name, 'clear') - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -789,10 +750,7 @@ class PortTestCase(unittest.TestCase): port = comp_self._add_input_port('clear') self.assertIsNone(port.connection) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -803,10 +761,7 @@ class PortTestCase(unittest.TestCase): port = comp_self._add_input_port('clear') self.assertFalse(port.is_connected) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) diff --git a/tests/bindings/python/bt2/test_query_executor.py b/tests/bindings/python/bt2/test_query_executor.py index 52af4664..e4f1fa5b 100644 --- a/tests/bindings/python/bt2/test_query_executor.py +++ b/tests/bindings/python/bt2/test_query_executor.py @@ -25,14 +25,11 @@ import bt2 class QueryExecutorTestCase(unittest.TestCase): def test_query(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params return {'null': None, 'bt2': 'BT2'} @@ -51,14 +48,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_params_none(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params @@ -69,14 +63,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_logging_level(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal query_log_level query_log_level = log_level @@ -87,14 +78,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_gen_error(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): raise ValueError with self.assertRaises(bt2._Error) as ctx: @@ -110,14 +98,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_invalid_object(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): raise bt2.InvalidObject with self.assertRaises(bt2.InvalidObject): @@ -125,14 +110,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_logging_level_invalid_type(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): pass with self.assertRaises(TypeError): @@ -140,14 +122,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_logging_level_invalid_value(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): pass with self.assertRaises(ValueError): @@ -155,14 +134,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_try_again(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): raise bt2.TryAgain with self.assertRaises(bt2.TryAgain): @@ -170,14 +146,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_add_interrupter(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): nonlocal interrupter2 test_self.assertFalse(query_exec.is_interrupted) interrupter2.set() @@ -195,14 +168,11 @@ class QueryExecutorTestCase(unittest.TestCase): def test_query_interrupt(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass @classmethod - def _query(cls, query_exec, obj, params, log_level): + def _user_query(cls, query_exec, obj, params, log_level): test_self.assertFalse(query_exec.is_interrupted) query_exec.interrupt() test_self.assertTrue(query_exec.is_interrupted) diff --git a/tests/bindings/python/bt2/utils.py b/tests/bindings/python/bt2/utils.py index fb4003a3..46be6fe2 100644 --- a/tests/bindings/python/bt2/utils.py +++ b/tests/bindings/python/bt2/utils.py @@ -30,10 +30,7 @@ def run_in_component_init(func): nonlocal res_bound res_bound = func(self) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass g = bt2.Graph() diff --git a/tests/data/cli/auto-source-discovery/bt_plugin_test.py b/tests/data/cli/auto-source-discovery/bt_plugin_test.py index 8d65b3d0..002e9c33 100644 --- a/tests/data/cli/auto-source-discovery/bt_plugin_test.py +++ b/tests/data/cli/auto-source-discovery/bt_plugin_test.py @@ -26,7 +26,7 @@ class TestSourceExt(Base, bt2._UserSourceComponent, message_iterator_class=TestI self._print_params(params) @staticmethod - def _query(query_exec, obj, params, log_level): + def _user_query(query_exec, obj, params, log_level): if obj == 'support-info': if params['type'] == 'file': name = os.path.basename(str(params['input'])) @@ -64,7 +64,7 @@ class TestSourceSomeDir( self._print_params(params) @staticmethod - def _query(query_exec, obj, params, log_level): + def _user_query(query_exec, obj, params, log_level): if obj == 'support-info': if params['type'] == 'directory': name = os.path.basename(str(params['input'])) @@ -83,7 +83,7 @@ class TestSourceABCDE(Base, bt2._UserSourceComponent, message_iterator_class=Tes self._print_params(params) @staticmethod - def _query(query_exec, obj, params, log_level): + def _user_query(query_exec, obj, params, log_level): if obj == 'support-info': return ( 1.0 diff --git a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py index 0fdb78f9..69abd1aa 100644 --- a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py +++ b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py @@ -33,7 +33,7 @@ class TheIteratorOfAllEvil(bt2._UserMessageIterator): ] self._at = 0 - def _seek_beginning(self): + def _user_seek_beginning(self): self._at = 0 def __next__(self): diff --git a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py index 77bf3613..cdac0670 100644 --- a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py +++ b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py @@ -35,10 +35,7 @@ class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): @bt2.plugin_component_class class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass -- 2.34.1